Variable Definitions Flashcards
If there is no values in the terraform.tfvars file for a variable and there is a value in a separate variables file , what will be the value of the variable?
The value in the separate file
If there are values in both terraform.tfvars file for a variable and a separate variables file , what will be the value of the variable?
The value in the TFVARS file takes precedence.
If the file, “terraform.tfvars” is missing from the working directory how do you specify in the CLI which variable file to use?
terraform plan -var-file=
“filename.tfvar”
Ex:
terraform plan -var-file=”prod.tfvars”
terraform plan -var-file=”dev.tfvars”
What happens if you declare a variable but don’t give it a value?
Terraform will ask to input the value in the CLI prompt when you run terraform plan / apply.
How do you declare a value for a variable directly at the CLI when running terraform apply / plan
terraform plan -var=”variable name=value”
Ex:
terraform plan -var=”instance_type=m5.large”
How do you add an environment variable in Linux?
export TF_VAR_variablename=value
Ex: export TF_VAR_instance_type=m5.large
How do you check the value of an Environment variable?
echo $TF_VAR_variablename
Ex:
echo $TF_VAR_instance_type
What will terraform choose if there is a variable value stored in a terraform.tfvars file, a value stored in an environment variable, or a default value stored in a separate .tf file?
Terraform always takes precedence from the environment variable.
What’s the order that Terraform loads variables?
Terraform loads variables in the following order, with later sources taking precedence over earlier ones
- Environment first
- Terraform.tfvars, if present
- Terraform.tfvars.json, if present
4.Any *.auto.tfvars or *.auto.tfvars.json files, processed in lexican order of their filename
- Any -var and -var-file options on the command line.