Terraform Best Practices for Cloud users.
Table of Contents
- Run terraform command with var-file
- Manage remote backend for tfstate files
- Manage multiple Terraform modules and environments easily with Terragrunt
- Visualize Tf resource configuration or execution plan using the Tf Graph
the READM for terraform version 0.11 and less has been renamed to README.0.11.md
$ cat config/dev.tfvars
name = "dev-stack"
tag_team_name = "hello-world"
$ terraform plan -var-file=config/dev.tfvars
With var-file
, you can easily manage environment (dev/stag/uat/prod) variables.
With var-file
, you avoid running terraform with long list of key-value pairs ( -var foo=bar
)
Terraform doesn't support Interpolated variables in terraform backend config, normally you write a seperate script to define a backend storage name for different environments, but I recommend to hard code it.
Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules. https://www.gruntwork.io
- Terragrunt - AWS QuickStart
- Terragrunt - Azure QuickStart - Coming Soon
the Graph is great tool to visualize resource dependencies especially useful for complex Tf configurations - get started here