Bitzu

Terraform Associate 004 ยท Configuration building blocks

Input variables

variable block arguments: type, default, description, nullable, ways to set values (-var, tfvars, TF_VAR_ env) (4c).

Key points

  • A variable "NAME" {} block declares a module input.
  • Common arguments: type, default, description, nullable (true by default), sensitive and validation.
  • Without a default, Terraform asks for a value.
  • Values can come from -var, -var-file, *.tfvars files or TF_VAR_name environment variables.
  • Reference a value as var.NAME.

Practice questions

Single choice

What happens when a root module variable has no default and no value is supplied?

  1. Terraform assumes null and continues
  2. Terraform prompts for a value before planning
  3. Terraform uses an empty string
  4. terraform init fails
Show answer

Answer: B. Terraform prompts for a value before planning

Terraform prompts interactively for the value. It does not silently use null or an empty string, and it does not fail at init.

Select all that apply

Which are valid ways to supply a value for a root module variable?

  1. terraform apply -var="name=value"
  2. An environment variable named TF_VAR_name
  3. A line in a terraform.tfvars file
  4. An output block in the same module
  5. A resource block with the same name
Show answer

Answer: A. terraform apply -var="name=value", B. An environment variable named TF_VAR_name, C. A line in a terraform.tfvars file

-var, variable definition files and TF_VAR_ environment variables are all supported. A resource block cannot feed a variable, and output blocks only expose values.

True or false

True or false: marking a variable sensitive = true keeps its value out of the state file.

Show answer

Answer: False

False. sensitive only hides the value in CLI output; it is still stored in state. Protect state accordingly.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module