Skip to main content
The Terraform block in Terragrunt defines how Terragrunt locates and invokes your Terraform configuration. It centralizes settings such as module source, version locking, extra CLI arguments, and lifecycle hooks. By configuring this block once, you ensure consistent Terraform behavior across all environments and modules.

Key Terraform Block Attributes

Always lock your modules to a specific version or ref to avoid unintended upgrades.
For Registry modules, append ?version=, and for Git sources, use ?ref=.

1. Defining the Source

The source attribute tells Terragrunt where to fetch Terraform code. You can reference:
  • Terraform Registry Modules
  • Git Repositories (HTTPS or SSH)
  • Local Directories

1.1 Terraform Registry

Include subdirectories by adding extra slashes:

1.2 GitHub (HTTPS)

1.3 GitHub (SSH)

1.4 Local Modules

Ideal for local development and testing:

2. Passing Extra Arguments

Use extra_arguments to pass flags, variable files, or arbitrary flags to Terraform:

3. Hooks and Custom Commands

Hooks allow you to run scripts before or after Terraform commands:
Use hooks carefully in production: unexpected script failures can block Terraform runs.
Always test hooks in a development environment first.

References

Watch Video