Terraform variable precedence
The fixed order Terraform uses to decide which value wins when a variable is set in more than one place.
In more detail
From weakest to strongest: the default, TF_VAR_ environment variables, terraform.tfvars, terraform.tfvars.json, *.auto.tfvars files in alphabetical order, then -var and -var-file options in the order given. When someone says their change had no effect, walk this list.
Related terms
- input variable — A named, typed value a configuration or module takes from outside, declared in a variable block and read as var.<name>.
- TF_VAR_ environment variable — An environment variable named TF_VAR_ followed by a variable name, which Terraform reads as that variable's value.
- variable definitions file — A .tfvars file of name = value lines that supplies values for input variables.
- -var — The plan and apply option that sets one input variable on the command line, as in -var="environment=prod".
Taught in
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Input Variables, Outputs, And Which Value Wins — HashiCorp Terraform Associate (004) Exam Prep
- HCP Workspaces, Projects And Variable Sets: Which Value Wins? — HashiCorp Terraform Associate (004) Exam Prep