← All writing

Terragrunt vs. Pure Terraform: Multi-Account Architecture at Scale

· Sourabh G Kulkarni

Why pure Terraform leads to configuration duplication in multi-account clouds, and how Terragrunt solves backend and variable inheritance.

Terragrunt vs. Pure Terraform: Multi-Account Architecture at Scale

As cloud infrastructure matures from a single AWS account to multi-account organizations (Development, Staging, Production, and Shared Services), native Terraform hits an ergonomic wall: configuration duplication.

Every single environment requires its own backend "s3" {} block, its own provider configuration, and repetitive variable declarations. If you manage 3 environments across 4 AWS accounts, updating a backend bucket name or adding a common tag requires editing 12 separate files.

Terragrunt acts as a thin wrapper on top of Terraform designed to keep your infrastructure code 100% DRY (Don't Repeat Yourself).

flowchart TD
    subgraph RootConfig["Root Terragrunt Layer (DRY Single Source of Truth)"]
        RootHcl["terragrunt.hcl (Central Backend & Provider Blocks)"]
    end

    subgraph Envs["Multi-Account Directory Tree"]
        Dev["dev/us-east-1/vpc/terragrunt.hcl"]
        Stage["staging/us-east-1/vpc/terragrunt.hcl"]
        Prod["prod/us-east-1/vpc/terragrunt.hcl"]
    end

    subgraph IaCModule["Reusable Pure Terraform Module"]
        Mod["git::github.com/company/terraform-aws-vpc?ref=v1.2.0"]
    end

    RootHcl -->|generate backend & providers| Dev
    RootHcl -->|generate backend & providers| Stage
    RootHcl -->|generate backend & providers| Prod

    Dev -->|inputs: cidr = 10.1.0.0/16| Mod
    Stage -->|inputs: cidr = 10.2.0.0/16| Mod
    Prod -->|inputs: cidr = 10.0.0.0/16| Mod

1. The Core Power: Remote State Generation

With Terragrunt, you define your S3 backend and DynamoDB lock table once in a root terragrunt.hcl:

# root terragrunt.hcl
remote_state {
  backend = "s3"
  generate = {
    path      = "backend.tf"
    if_exists = "overwrite_terragrunt"
  }
  config = {
    bucket         = "company-tf-state-${get_aws_account_id()}"
    key            = "${path_relative_to_include()}/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    dynamodb_table = "terraform-locks"
  }
}

Every child directory simply inherits this configuration:

# prod/us-east-1/eks/terragrunt.hcl
include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "git::https://github.com/company/terraform-aws-eks.git?ref=v3.2.0"
}

inputs = {
  cluster_name = "production-cluster"
  node_count   = 6
}

Terragrunt automatically interpolates the S3 key as prod/us-east-1/eks/terraform.tfstate. Zero duplicate backend blocks.


2. Managing Inter-Module Dependencies

In pure Terraform, passing outputs from a VPC to an EKS cluster across separate state files requires brittle data "terraform_remote_state" lookups.

Terragrunt introduces first-class dependency blocks:

# prod/us-east-1/eks/terragrunt.hcl
dependency "vpc" {
  config_path = "../vpc"
}

inputs = {
  vpc_id          = dependency.vpc.outputs.vpc_id
  private_subnets = dependency.vpc.outputs.private_subnet_ids
}

When you run terragrunt run-all plan or terragrunt run-all apply, Terragrunt calculates the full dependency graph and automatically executes the VPC first, followed by the EKS cluster.


3. Pure Terraform vs. Terragrunt: When to Use Which?

MetricPure TerraformTerragrunt
Learning CurveStandard HCLRequires understanding wrapper lifecycle
Backend ConfigDuplicated across every state folderDefined once at root (remote_state)
Cross-Module Outputsdata "terraform_remote_state"Explicit dependency blocks
Multi-Stack DeployManual sequential runsrun-all apply with DAG ordering
Tooling EcosystemUniversal supportRequires Terragrunt binary in CI/CD

The Recommendation

For single-account or simple architectures, stick with pure Terraform using structured modules. As soon as you scale to multiple AWS accounts or environments that require isolated state files, Terragrunt saves hundreds of hours of configuration maintenance.