13. Managing Multiple Environments
Approaches
1. Workspaces
Multiple named sections within a single backend
$ terraform workspace new dev
$ terraform workspace list
$ terraform workspace select staging
Pros
easy to get started
convinient terraform.workspace expression
minimizes code duplication
Cons
prone to human error
state stored with same backend
codebase doesn't unambigously show deployment configurations
2. File Structure
Directory layout provides seperation, modules provide reuse
_modules
module_1
main.tf
module_2
main.tf
dev
main.tf
terraform.tfvars
prod
main.tf
terraform.tfvars
Pros
isolation of backends
improved security
decreased potential for human error
codebase fully represents deployed state
referencing resources acrodd configurations is possible using
terraform_remote_state
Cons
multiple terraform apply required to provision environments
more code duplication, but can be minimized with modules
Last updated