ConfigsApr 16, 2026·3 min read

Terramate — IaC Orchestration for Terraform & OpenTofu

An open-source orchestration tool that adds code generation, stack management, change detection, and drift detection to Terraform and OpenTofu projects. Terramate scales IaC from single directories to hundreds of stacks.

TL;DR
Terramate orchestrates Terraform stacks with code generation, change detection, and drift detection at scale.
§01

What it is

Terramate is an open-source orchestration tool that extends Terraform and OpenTofu with stack management, code generation, change detection, and drift detection. It helps teams scale from a single Terraform directory to hundreds of stacks by managing dependencies, ordering execution, and detecting which stacks actually changed.

Terramate targets platform and infrastructure engineers managing large Terraform codebases. If your Terraform project has grown into many modules and environments with complex interdependencies, Terramate brings structure without replacing your existing HCL.

§02

How it saves time or tokens

This workflow provides installation and initialization commands. Instead of running terraform apply across every directory manually, Terramate detects which stacks changed and runs only those. Code generation eliminates copy-paste between stacks, and drift detection alerts you to manual changes.

§03

How to use

  1. Install Terramate:
brew install terramate
  1. Initialize in an existing Terraform repo:
terramate create --name my-stack
  1. Run Terraform through Terramate:
# Detect changed stacks and run plan only on those
terramate run --changed -- terraform plan

# Apply across all stacks in dependency order
terramate run -- terraform apply -auto-approve

# Check for drift
terramate run -- terraform plan -detailed-exitcode
§04

Example

# terramate.tm.hcl - Stack configuration
stack {
  name        = "production-vpc"
  description = "Production VPC and networking"
  tags        = ["network", "production"]
}

# Generate shared backend config across stacks
generate_hcl "_backend.tf" {
  content {
    terraform {
      backend "s3" {
        bucket = "my-terraform-state"
        key    = "stacks/${terramate.stack.path.relative}/terraform.tfstate"
        region = "us-east-1"
      }
    }
  }
}
# Run only on stacks tagged 'production'
terramate run --tags production -- terraform plan
§05

Related on TokRepo

§06

Common pitfalls

  • Terramate does not replace Terraform. It wraps and orchestrates it. Your existing .tf files remain unchanged; Terramate adds .tm.hcl files for stack configuration.
  • Change detection works with Git. Uncommitted changes are not detected by default. Commit your changes or use --changed with appropriate flags.
  • Code generation templates use Terramate's own HCL syntax, not standard Terraform. Review the Terramate docs for template variables and functions.

Frequently Asked Questions

Does Terramate replace Terraform?+

No. Terramate wraps Terraform and OpenTofu. Your existing HCL files remain untouched. Terramate adds orchestration, code generation, and change detection on top of your existing Terraform workflow.

How does change detection work?+

Terramate uses Git to detect which files changed since the last commit or merge. It maps changed files to stacks and only runs Terraform on affected stacks. This dramatically reduces plan and apply times in large repos.

What is code generation in Terramate?+

Code generation lets you define HCL templates that produce Terraform files. Instead of copy-pasting backend configs or provider blocks across stacks, you write one template and Terramate generates the files in each stack.

Does Terramate support OpenTofu?+

Yes. Terramate works with both Terraform and OpenTofu. Replace terraform with tofu in your terramate run commands. Stack management, change detection, and code generation work identically.

How does drift detection work?+

Run terramate run -- terraform plan -detailed-exitcode across all stacks. Terramate collects the exit codes and reports which stacks have drifted from their desired state. This catches manual changes made outside Terraform.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets