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
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
- 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 Key | Description | Example |
---|---|---|
name | VPC resource name | "KodeKloud-VPC" |
cidr | CIDR block for the new VPC | "10.100.0.0/16" |
Links and References
Watch Video
Watch video content