Created as an exercise to:
- Evaluate usability of
${path.root}/module
and${path.root}/__environment__
directory structure - Implement mechansim that allows separate state files for each environment
- Leverage Azure as a remote-backend for Terraform
- Minimize initialization needed to setup remote backed for each environment
├── README.md
├── environments
│ └── development
│ ├── main.tf
│ ├── terraform.tfstate
│ ├── terraform.tfstate.backup
│ └── variables.tf
└── modules
├── base
│ ├── certificate
│ │ ├── main.tf
│ │ ├── output.tf
│ │ └── variables.tf
│ ├── compute
│ │ └── linux_vm
│ │ ├── main.tf
│ │ ├── output.tf
│ │ └── variables.tf
│ ├── network
│ │ └── virtual_network
│ │ ├── main.tf
│ │ ├── output.tf
│ │ └── variables.tf
│ ├── resource_group
│ │ ├── main.tf
│ │ ├── output.tf
│ │ └── variables.tf
│ └── storage
│ └── key_vault
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
└── services
├── application_gateway
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
└── remote_state
├── main.tf
├── makefile
├── templates
│ └── terraform.tf.tpl
└── variables.tf
The commands below will setup the prerequisites for the azurerm
remote-backend. They will also generate the
terraform.tf
file from template that is used to initialize the remote-backend.
terraform init
terraform plan
terraform apply
You should notice terraform.tf
in your current working directory. The next set of commands will read the statements in
terraform.tf
and configure the remote-backend.
teraform init --reconfigure
terraform plan
terraform apply
Delete the leftover terraform.tfstate
and terraform.tfstate.backup
files by running:
rm terraform.tfstate*
- Fix error on
terraform destroy
since state file part of resources being destroyed - Reduce duplication in
main.tf
file between development and production - Reduce duplication in
variables.tf
file between development and production - Add appropriate license