Skip to main content
Let’s provision our first reusable group of resources: a Virtual Private Cloud (VPC) using Terraform modules and Terragrunt. Goal: deploy a reusable VPC across multiple environments (for example, dev and prod) by leveraging the community-maintained Terraform module terraform-aws-modules/vpc/aws. Community modules accelerate delivery by providing well-tested patterns, reducing duplicate code, and improving maintainability. How this works in brief:
  • Each environment (for example, live/dev/vpc and live/prod/vpc) contains a terragrunt.hcl that points at the VPC module and supplies environment-specific inputs.
  • Terragrunt downloads the module, renders variables, and runs Terraform commands (init/plan/apply) for that environment.
A slide titled "Setting up the first group of resources (VPC)" showing two circular icons: a community/people icon for a community-contributed Terraform module and an AWS logo for terraform-aws-modules/vpc/aws. A rounded "Community Module" button is shown below.
Typical workflow and steps
  • Create a terragrunt.hcl file for each environment (for example, dev and prod). Each terragrunt.hcl references the community VPC module and supplies inputs specific to that environment.
  • From the environment directory, run the Terragrunt CLI to initialize, plan, and apply the configuration.
Example Terragrunt configuration Below is a minimal terragrunt.hcl that references the terraform-aws-modules/vpc/aws module and provides common inputs. Place one version of this file in each environment directory and customize the inputs as needed.
Best practice: pin the module version (for example via ?ref=v3.14.0) to ensure reproducible builds and reduce unexpected changes from upstream. Common inputs reference Recommended Terragrunt CLI sequence
  1. Change into the environment directory that contains your terragrunt.hcl:
  1. Initialize the working directory (downloads modules and providers):
  1. Generate and inspect a plan for the proposed changes:
  1. Apply the planned changes to create the VPC:
Customizing for each environment
  • Keep environment-specific values such as CIDR blocks, AZ lists, subnet sizes, tags, and naming conventions inside each environment’s terragrunt.hcl.
  • Use the same module source across environments to ensure consistent architecture while varying inputs to meet environment constraints.
Always review the terragrunt plan output before applying—this helps avoid accidental changes. Keep environment-specific values (for example, CIDR blocks and tags) in each environment’s terragrunt.hcl so deployments remain consistent and reproducible.
Links and references

Watch Video