ARTICLE AD BOX
I have been working on a project to automate the AWS infrastructure with Terraform. Initially, I created two folders (bootstrap and live).
Below is the Bootstrap folder structure.
enter image description here
We know we need to create a backend configuration file to store Terraform state in an S3 bucket. But the backend config does not support variable interpolation, so we have to hard-code values in the backend. In addition to this, there is also a chicken-and-egg problem (the S3 backend and DynamoDB have to be created before using them).
To resolve these issues, Terragrunt is a good option.
But we can also create a Python script to automatically generate the backend configuration file and run the migrate command to store the Terraform state in the S3 backend.
The approach is
- terraform init (manual): to initialize all the modules, including S3 and DynamoDB.
- terraform validate (manual): to validate the syntax of all modules
- terraform plan -var-file dev.tfvars (manual)
- And then run the Python script to apply the modules and extract outputs from the outputs.tf file + generate a backend file + migrate state to S3.
Is it also not a good approach to resolve these issues instead of using Terragrunt (especially in the bootstrap folder) to initialize the modules, such as iam_policy, iam_role, dynamoDb, S3, and kms?
