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.
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.
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.
How to use
- Install Terramate:
brew install terramate
- Initialize in an existing Terraform repo:
terramate create --name my-stack
- 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
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
Related on TokRepo
- DevOps tools -- Infrastructure automation and management
- Automation tools -- Workflow automation for operations teams
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
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.
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.
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.
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.
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)
- Terramate GitHub— Terramate adds orchestration to Terraform and OpenTofu
- Terramate Documentation— Stack management, code generation, and change detection
- Terramate Change Detection— Git-based change detection for Terraform stacks
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.