In this repo, i give example how to dealing with multiple environment when using terraform as your IaC.
What this repo is made of
- Terraform workspace
- Terraform interpolation (
lookup
) - Makefile
➜ terraform-multienv $ tree
.
├── map
│ ├── main.tf
│ ├── terraform.tfstate.d => workspace state file location
│ │ ├── dev
│ │ ├── prod
│ │ └── staging
│ └── variables.tf
├── README.md
└── wrapper
├── dev.tfvars
├── main.tf
├── Makefile
├── prod.tfvars
├── staging.tfvars
├── terraform.tfstate.d => workspace state file location
│ ├── dev
│ ├── prod
│ └── staging
└── variables.tf
10 directories, 9 files
There are 2 examples scenario when dealing with terraform for multiple environment
- in this directory i use resources mapping based on the environment in
variables.tf
- using
lookup
function to get correct value based on environment and store it inlocal
-
in this folder I separate values based on variable file
dev.tfvars
staging.tfvars
prod.tfvars
-
create
Makefile
as a wrapper for executing terraform command
Please try and find it by yourself :D