Terragrunt for Beginners

Terragrunt Attributes

Terragrunt Attribute Overview

In this guide, we’ll dive into key Terragrunt configuration attributes that unlock advanced control over your Infrastructure as Code workflows. You’ll learn how to parameterize Terraform modules, optimize caching, enforce security safeguards, and handle transient errors—empowering you to build resilient, maintainable deployments.

The image is a diagram titled "Terragrunt Attributes," listing attributes such as Inputs, Download dir, Prevent destroy, Skip, IAM role and related, Terraform binary, Version constraint, and Retryable errors.

Attribute Summary

AttributePurpose
inputsPass variables into Terraform modules for dynamic parameterization.
download_dirDefine a local cache directory for remote Terraform modules and providers.
prevent_destroyProtect critical resources from accidental deletion during apply or destroy.
skipExclude specific Terragrunt blocks or commands from execution.
iam_roleConfigure AWS IAM roles and permissions for Terraform operations.
terraform_binarySpecify a custom Terraform executable or version.
version_constraintEnforce version rules for both Terraform and Terragrunt binaries.
retryable_errorsList error patterns that Terragrunt retries automatically on failure.

Detailed Attribute Guide

inputs

Define a map of input variables to inject into your Terraform modules.

# terragrunt.hcl
inputs = {
  environment = "production"
  region      = "us-east-1"
}

Note

Use precise variable names in inputs to match your Terraform module's variables.tf definitions.

download_dir

Specify where Terragrunt downloads remote modules, providers, and configuration files. This optimizes build speed by caching dependencies locally.

download_dir = "${get_terragrunt_dir()}/.terragrunt-cache"

prevent_destroy

Safeguard resources from accidental destruction. When set to true, Terragrunt will refuse to run terraform destroy on the protected blocks.

prevent_destroy = true

Warning

Enabling prevent_destroy can block intentional resource teardown. Use with caution.

skip

Skip execution of selected Terragrunt commands or blocks to streamline CI/CD pipelines.

skip = ["plan", "apply_all"]

iam_role

Assign an AWS IAM role for Terraform operations, ensuring secure and auditable access.

iam_role {
  arn = "arn:aws:iam::123456789012:role/TerraformExecution"
}

terraform_binary

Point Terragrunt to a specific Terraform binary, enabling consistent Terraform versions across your environments.

terraform_binary = "/usr/local/bin/terraform"

version_constraint

Lock both Terraform and Terragrunt to specific versions for consistent builds.

version_constraint = ">= 1.0.0, < 2.0.0"

retryable_errors

Configure Terragrunt to automatically retry on transient errors.

retryable_errors = [
  "Error acquiring the state lock",
  "Provider finished with"
]

Watch Video

Watch video content

Previous
Demo of Lab 3