🐾Best practices for storing application code and Terraform code🐾
❓How should you store your application code for Lambda functions or applications running on ECS? Should you use the same or separate repository from your Terraform configuration?
✅ There are no official best practices for that, but I can share my experience and thoughts with you. In general, I prefer to store both application and Terraform code in one repository because:
1️⃣ I consider Terraform configuration and application code as one deployable unit, which should be stored together. Also, it is much easier to deploy application into the cloud with CI/CD tools, when it is one repository.
2️⃣ It is more convenient to have changes in configuration and application related to the same reason in one commit. I saw pretty similar opinion from HashiCorp guy in Discuss forum: “If two things will often change together then it’s helpful for them to be represented together in a single repository.”
3️⃣ I think all IaC tools have the same goal and therefore can share best practices. AWS CDK has its own best practices and judging based on what I have seen in example repositories, usually, application code is stored in the same repository as configuration code.
So, as most of the time I use Terraform + Terragrunt configuration for resources and deployments, usually my repository has the following structure:
Workloads/ |-- vpc/ | |-- main.tf | |-- README.md |-- some_workload/ | |-- main.tf | |-- assets/ | | |-- application_code.py | |-- README.md Deployments/ |-- prod/ | |-- us-east-1/ | | |-- vpc/ | | | |-- terragrunt.hcl | | |-- some_workload/ | | | |-- terragrunt.hcl | |-- eu-central-1/ | | |-- vpc/ |-- dev/ | |-- vpc/ | | |-- terragrunt.hcl
🤓Let me know which approach you use for your IaC repositories in the comments.
If you like this post, you can share APAWS newsletter with friends: