Skip to main content
In this walkthrough, you’ll use Terragrunt to provision a multi-account, multi-region AWS infrastructure. You’ll configure remote state, set up environments (dev, stage, prod), and deploy core modules (VPC, Key Pair, Security Group, EC2).
Keep your AWS credentials handy. Run the following at any time to fetch them:

Prerequisites

Before you begin, confirm you have the following tools installed:

Project Setup

  1. Clone or navigate to your Terragrunt root.
  2. Create a working demo directory:

Step 1: Account Configuration

Create terragrunt-stack/demo/account.hcl to define account-level locals:
In your root terragrunt.hcl, add remote state and provider generation:

Step 2: Region Configuration

  1. Create terragrunt-stack/demo/us-east-1/region.hcl:
  2. Update root terragrunt.hcl:

Step 3: Environment Configuration (Dev)

  1. Create terragrunt-stack/demo/us-east-1/dev/env.hcl:
  2. Add to root terragrunt.hcl:

Step 4: VPC Module

File: terragrunt-stack/demo/us-east-1/dev/vpc/terragrunt.hcl
Initialize and apply:
Verify in the AWS VPC Dashboard.

Step 5: Key Pair & Security Group Modules

Key Pair

terragrunt-stack/demo/us-east-1/dev/key-pair/terragrunt.hcl:

Security Group

terragrunt-stack/demo/us-east-1/dev/security-group/terragrunt.hcl:

Step 6: EC2 Module

Ensure modules/ec2/main.tf contains:
Create terragrunt-stack/demo/us-east-1/dev/ec2/terragrunt.hcl:

Step 7: Apply the Dev Environment

Run all modules in order from terragrunt-stack/demo/us-east-1:
Terragrunt processes dependencies in this sequence:
  1. Key Pair
  2. VPC
  3. Security Group
  4. EC2

Step 8: Stage Environment

Duplicate the dev folder to stage and apply:
Check that the stage directory mirrors dev in your editor.

Step 9: Production in us-west-2

  1. Copy us-east-1us-west-2, remove dev, rename stageprod.
  2. In prod/ec2/terragrunt.hcl, update:
  3. Apply prod:

Step 10: Review Remote State Files

List state files in your S3 bucket:
Example output:
Each module maintains its own state, promoting isolation and reducing the blast radius.
Congratulations! You’ve successfully built a modular, scalable AWS infrastructure with Terragrunt.

References & Further Reading

Watch Video

Practice Lab