Skip to content

inputs

unitoptional(map(any))

Usage

The inputs attribute sets a module’s variables. Each key sets the variable of the same name.

  • Directorylive
    • Directoryapp
      • terragrunt.hcl sets the inputs
  • Directorymodules
    • Directoryapp
      • main.tf
      • variables.tf declares the variables
modules/app/variables.tf
variable "instance_type" {
type = string
}
variable "instance_count" {
type = number
}
variable "tags" {
type = map(string)
}
live/app/terragrunt.hcl
terraform {
source = "../..//modules/app"
}
inputs = {
instance_type = "t2.micro"
instance_count = 10
tags = {
Name = "example-app"
}
}

Terragrunt passes each input to OpenTofu/Terraform as a TF_VAR_ environment variable, with the value encoded as JSON. Running terragrunt apply in live/app is roughly equivalent to running:

Terminal window
TF_VAR_instance_type="t2.micro" \
TF_VAR_instance_count=10 \
TF_VAR_tags='{"Name":"example-app"}' \
tofu apply # or terraform apply

A null input reaches the module as null, which overrides the variable’s default. A literal ${...} in a value reaches the module as written.

A unit with many or large inputs can exceed the operating system’s limit on the size of a process environment. The variables-block experiment adds a variables block that can write inputs to an auto-loaded variables file.

Variable precedence

OpenTofu/Terraform uses the first of these that sets a variable:

  1. -var and -var-file options on the command line. If several set it, the last one wins.
  2. *.auto.tfvars and *.auto.tfvars.json files. If several set it, the last filename in lexical order wins.
  3. A terraform.tfvars.json file.
  4. A terraform.tfvars file.
  5. A TF_VAR_ environment variable you set yourself.
  6. inputs.

By default, a unit’s inputs merge with those of the files it includes, key by key. The unit’s value wins for a key set in both.

Examples

terragrunt.hcl
inputs = {
string = "string"
number = 42
bool = true
list_string = ["a", "b", "c"]
list_number = [1, 2, 3]
list_bool = [true, false]
map_string = {
foo = "bar"
}
map_number = {
foo = 42
bar = 12345
}
map_bool = {
foo = true
bar = false
baz = true
}
object = {
str = "string"
num = 42
list = [1, 2, 3]
map = {
foo = "bar"
}
}
from_env = get_env("FROM_ENV", "default")
}