Overview
- Declared in
variable
blocks
- Arguments:
default
- Causes variable to be optional.
- If omitted, value is set to the
default
argument
type
string
number
bool
- Complex types:
list(<TYPE>)
, set(<TYPE>)
, map(<TYPE>)
, object({<ATTR_NAME> = <TYPE>, ...}
, tuple([<TYPE>, ...])
any
description
validation
sensitive
- Suppresses display of value in the CLI output
- Value still stored in plain text in state
- Sent to provider without obfuscation
- Could be disclosed e.g. as part of an ID
nullable
- Allows/disallows
null
values
Validation
- In addition to type constraints.
validation.condition
must use value of variable to return true
if valid, otherwise false
- Must not produce errors
- May use
can
function to detect errors and return true
/false
- e.g.
Setting Variables
- Precedence:
- Environment variables—in format
TF_VAR_<variable name>
terraform.tfvars
terraform.tfvars.json
*.auto.tfvars
/ *.auto.tfvars.json
-var
/ -var-file
on the command line