terraform_binary attribute enables you to specify a custom Terraform executable instead of relying on the system default. By pointing Terragrunt to a specific binary—either by name or full path—you can maintain consistent Terraform versions across multiple environments, projects, and CI/CD pipelines.
Before you begin, verify that the path to your custom Terraform binary is correct and that the file has execute permissions.
You can check permissions with
You can check permissions with
ls -l /path/to/terraform.Why Override the Terraform Binary?
| Benefit | Description | Example Use Case |
|---|---|---|
| Version Control | Lock Terragrunt to a precise Terraform release without altering your system default. | Enforce Terraform v1.8.4 for production modules. |
| Custom Builds | Test unreleased, beta, or locally compiled Terraform versions. | Run Terraform v1.9.0-beta during feature development. |
| Environment Isolation | Standardize the Terraform executable across developers, CI servers, and remote runners. | Eliminate “works on my machine” version drift issues. |
Default Behavior (No terraform_binary)
When you omit terraform_binary, Terragrunt uses the Terraform executable found in your system PATH. Here’s a sample Terragrunt configuration without the override:
terragrunt version to confirm which Terraform version is used:
Overriding with terraform_binary
Imagine you’ve placed a beta build of Terraform (v1.9.0-beta) into your parent Terragrunt directory:
terraform_binary attribute:
PATH.
If the specified binary is not found or not executable, Terragrunt will fail to initialize. Always include the correct path and ensure execution rights.
Best Practices
- Pin Terraform versions per project to minimize drift.
- Store custom or beta executables in a consistent directory structure.
- Use
${get_parent_terragrunt_dir()}or absolute paths to avoid ambiguity. - Incorporate version checks in your CI/CD pipelines to catch mismatches early.