inputs
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
variable "instance_type" { type = string}
variable "instance_count" { type = number}
variable "tags" { type = map(string)}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:
TF_VAR_instance_type="t2.micro" \TF_VAR_instance_count=10 \TF_VAR_tags='{"Name":"example-app"}' \tofu apply # or terraform applyA 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:
-varand-var-fileoptions on the command line. If several set it, the last one wins.*.auto.tfvarsand*.auto.tfvars.jsonfiles. If several set it, the last filename in lexical order wins.- A
terraform.tfvars.jsonfile. - A
terraform.tfvarsfile. - A
TF_VAR_environment variable you set yourself. 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
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")}