Terragrunt for Beginners

Terragrunt Attributes

inputs Attribute

Terragrunt’s inputs attribute is essential for passing configuration values into Terraform modules. By specifying key-value pairs, you can easily feed outputs from dependencies or define custom variables for your current module, keeping your infrastructure code modular and maintainable.

How inputs Works

The image shows a diagram of key-value pairs, labeled "Inputs Attribute" and "Attributes," with a gradient color bar at the bottom.

In Terragrunt, the inputs block maps each variable name to the desired value:

  • You can reference outputs from other modules using Terragrunt’s dependency blocks.
  • Values defined here correspond directly to the Terraform variables declared in variables.tf.

Key Benefits

The image features a puzzle piece icon with the text "Enables modularization" below it, and a "Benefits" button at the bottom.

  • Modularization: Share data between modules without duplicating configuration.
  • Reusability: Centralize common settings (e.g., VPC CIDR ranges) across environments.
  • Maintainability: Change inputs in a single Terragrunt file rather than multiple Terraform modules.

Important Considerations

Note

Terragrunt’s inputs block does not enforce Terraform variable type constraints. Always verify that the values you provide match the expected type (e.g., string, number, list, map).

Example: AWS VPC Module

Below is a Terragrunt configuration that passes the VPC name and cidr into the Terraform AWS VPC module:

terraform {
  source = "tfr://terraform-aws-modules/vpc/aws//?version=5.8.1"
}

include "root" {
  path   = find_in_parent_folders()
  expose = true
}

inputs = {
  name = "KodeKloud-VPC"
  cidr = "10.100.0.0/16"
}

Input Parameters Table

Input KeyDescriptionExample
nameVPC resource name"KodeKloud-VPC"
cidrCIDR block for the new VPC"10.100.0.0/16"

Watch Video

Watch video content

Previous
Terragrunt Attribute Overview