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
configterragrunt.hcl
— Root-level configuration used by all environmentsscripts/
— Utility scripts for setting up symlinks and running terragrunt
terraform-terragrunt-aws-project/
├── terragrunt.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
- add symlink for modules and common files
./scripts/symlink-modules.sh
./scripts/symlink-common.sh
- add .env file to the root of the project
TERRAFORM_ORG_NAME=
TERRAFORM_WORKSPACE_TAGS=
-
update config.json file
-
run terragrunt with the following command
./scripts/run.sh
To ensure that the GitHub Action workflow runs correctly, you need to set up the following GitHub secret:
TF_API_TOKEN
: This is a Terraform Cloud API token used for authentication.
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.8.0",
"terragrunt_version": "0.57.0",
"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"
}
}
}
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: hiremostafa@gmail.com