A Terraform and Terragrunt project for managing AWS infrastructure across multiple environments (dev, stage, prod).
modules/
— Reusable Terraform modules (vpc
,subnet
, etc.)live/
- Terraform related code per environmentcommon/
— Shared code across all environmentsdev/
,stage/
,prod/
— Environment-specific codemodules/
— Symlinks to root-level modulescommon-*.tf
— Symlinks to sharedcommon
configs
environment/
— Contains per-environmentterragrunt.hcl
configroot.hcl
— Root-level configuration used by all environmentsscripts/
— Utility scripts for setting up symlinks and running terragrunt
terraform-terragrunt-aws-project/
├── root.hcl # Root Terragrunt config (shared by all envs)
│
├── modules/ # Reusable Terraform modules
│ ├── subnet/
│ │ ├── main.tf
│ │ ├── output.tf
│ │ └── variables.tf
│ └── vpc/
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
│
├── live/ # Terraform project code per environment
│ ├── common/ # Shared Terraform configurations
│ │ └── common-*.tf # e.g., common-tags.tf, common-provider.tf
│ ├── dev/
│ │ ├── modules/ # 🔗 Symlinks to ../../modules/*
│ │ ├── common-*.tf # 🔗 Symlinks to ../common/*
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── output.tf
│ ├── stage/
│ │ ├── modules/ # 🔗 Symlinks to ../../modules/*
│ │ ├── common-*.tf # 🔗 Symlinks to ../common/*
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── output.tf
│ └── prod/
│ ├── modules/ # 🔗 Symlinks to ../../modules/*
│ ├── common-*.tf # 🔗 Symlinks to ../common/*
│ ├── main.tf
│ ├── variables.tf
│ └── output.tf
│
├── environment/ # Terragrunt HCL configs per environment
│ ├── dev/
│ │ └── terragrunt.hcl
│ ├── stage/
│ │ └── terragrunt.hcl
│ └── prod/
│ └── terragrunt.hcl
│
└── scripts/ # Setup automation scripts
├── run.sh # ✅ Run scripts
├── symlink-common.sh # 🔁 Symlinks common tf files into all envs
└── symlink-modules.sh # 🔁 Symlinks shared modules into all envs
Before installation terraform and terragrunt, check the Terragrunt and Terraform version Compatibility
./scripts/symlink-modules.sh
./scripts/symlink-common.sh
TERRAFORM_ORG_NAME=
TERRAFORM_WORKSPACE_TAGS=
{
"terraform_version": "1.8.0",
"terragrunt_version": "0.57.0",
"environments": {
"main": {
"TF_WORKSPACE": "infra-azure-prod",
"TG_WORKDIR": "environment/prod"
},
"stage": {
"TF_WORKSPACE": "infra-azure-stage",
"TG_WORKDIR": "environment/stage"
},
"dev": {
"TF_WORKSPACE": "infra-azure-dev",
"TG_WORKDIR": "environment/dev"
},
"default": {
"TF_WORKSPACE": "default",
"TG_WORKDIR": "environment/default"
}
}
}
AWS_ACCESS_KEY_ID
- AWS Access Key IDAWS_SECRET_ACCESS_KEY
- AWS Secret Access Key
./scripts/run.sh
To ensure that the GitHub Action workflow runs correctly, you need to set up the following GitHub secret and variables:
TF_API_TOKEN
: This is a Terraform Cloud API token used for authentication.
TERRAFORM_ORG_NAME
: This is the name of the Terraform Cloud organization.TERRAFORM_WORKSPACE_TAGS
: This is the tags of the Terraform Cloud workspace.
The config.json
file contains essential configurations for Terraform and Terragrunt. You should update this file to match your environment and branch-specific settings.
Here is the format for config.json
:
{
"terraform_version": "1.12.2",
"terragrunt_version": "0.83.2",
"environments": {
"main": {
"TF_WORKSPACE": "infra-aws-prod",
"TG_WORKDIR": "environment/prod"
},
"stage": {
"TF_WORKSPACE": "infra-aws-stage",
"TG_WORKDIR": "environment/stage"
},
"dev": {
"TF_WORKSPACE": "infra-aws-dev",
"TG_WORKDIR": "environment/dev"
},
"default": {
"TF_WORKSPACE": "default",
"TG_WORKDIR": "environment/default"
}
}
}
Note
This project intentionally uses a minimal set of Terragrunt features, primarily focusing on environment variable management and configuration inheritance. This approach keeps the infrastructure code simple and maintainable while still leveraging Terragrunt's key benefits for managing multi-environment deployments.
I'm available for hire to help with your Terraform, Terragrunt, and AWS infrastructure projects.
Services offered:
- Infrastructure as Code (IaC) development
- AWS cloud architecture and deployment
- Terraform/Terragrunt consulting and best practices
- CI/CD pipeline setup and optimization
- Infrastructure troubleshooting and optimization
📧 Contact: [email protected]