SaveMyCert
Log in
5 of 5 free questions left today·for 10 a day
Terraform 004 · Domain 4

Terraform configuration practice questions

Terraform configuration is worth 22% of the Terraform 004 exam — the heaviest of the 8 domains. Resources, data sources, variables, outputs, expressions, functions, dependencies, and secrets. Weight approximates the sub-objective share. 6 fully worked examples are further down this page, answers included.

Exam weight
22%
the heaviest of the 8 domains
Questions
86
across 2 topics
Free, no account
5/day
a free account allows 10 a day
Explanations
Every option
right and wrong

Build a practice session

5 free questions left today.

Domains

How many?

5 free questions left today.

Mode

Ready when you are

10 fresh questions drawn across 1 of 8 domains, in Learn mode.

Review what you missed

Every question you answer incorrectly, and every question you flag while practising, is saved here automatically. Finish a session and you can come back to re-drill just those.

6 sample Terraform configuration questions, fully explained

Questions from the Terraform 004 bank mapped to domain 4, with the answer key and the reasoning behind every option. None of them repeat the examples on the main Terraform 004 practice page.

Question 1Terraform configuration

A configuration declares data "aws_ami" "ubuntu" { ... } to look up an image. Which expression passes that image's id to the ami argument of an aws_instance resource?

Choose one.

  • a
    aws_ami.ubuntu.id

    Without the data. prefix this addresses a managed resource of type aws_ami named ubuntu, which the configuration does not declare.

  • b
    data.ubuntu.id

    The data source type is part of the address. Omitting aws_ami leaves Terraform unable to resolve the reference.

  • c
    data.aws_ami.ubuntu.id Correct

    Correct. Data sources are addressed as data.TYPE.NAME, followed by the attribute, here id.

  • d
    data.aws_ami["ubuntu"].id

    The name label is a plain address segment, not a map key. Bracket indexing applies to instances created with count or for_each, not to the block's name.

The concept

Every data source is addressed as data.TYPE.NAME.ATTRIBUTE, while a managed resource is addressed as TYPE.NAME.ATTRIBUTE with no prefix.

Why that’s the answer

The block is a data source, so its address starts with data., followed by the type label aws_ami and the name label ubuntu, then the attribute id. Dropping the prefix points at a non-existent managed resource, dropping the type breaks the address, and treating the name as a bracketed key confuses the name label with instance keys from for_each.

How to reason it out
  1. Identify the block type: data, so the address needs the data. prefix.
  2. Append both labels in order: type aws_ami, then name ubuntu.
  3. Append the attribute: .id.

Exam tip: Managed resources: TYPE.NAME.attr. Data sources: data.TYPE.NAME.attr.

Terraform Resources, Data Sources, Variables, and Outputs — the lesson that teaches this.

Question 2Terraform configuration

An aws_subnet resource sets vpc_id = aws_vpc.main.id, and the configuration contains no depends_on arguments. Which statement describes how Terraform orders the creation of the two resources?

Choose one.

  • a
    VPC first, then subnet: the reference gives the subnet an implicit dependency. Correct

    Correct. Any expression that refers to another resource adds an edge to the dependency graph, so the VPC is created before the subnet (and destroyed after it).

  • b
    Both in parallel: Terraform orders resources by depends_on, which is absent.

    depends_on is only for dependencies Terraform cannot see in an expression. A direct attribute reference is already visible in the graph.

  • c
    Both in parallel: the provider retries the subnet until the VPC ID exists.

    Terraform does not rely on provider retries for ordering. It waits for the VPC because the subnet's argument needs the VPC's id value.

  • d
    VPC first, then subnet: Terraform creates resources in the order of the file.

    The order is right but the reason is wrong. Terraform ignores the order of blocks in files; ordering comes only from the dependency graph.

The concept

Referencing one resource's attribute from another resource creates an implicit dependency in Terraform's graph, which controls the order of create and destroy operations.

Why that’s the answer

The subnet's vpc_id argument needs aws_vpc.main.id, so Terraform must create the VPC first. This implicit dependency is the preferred way to express ordering. The tempting near-twin gets the order right for the wrong reason: block order in .tf files has no effect, and Terraform runs independent resources in parallel regardless of where they are written.

How to reason it out
  1. Look for an expression in one resource that references another resource.
  2. A reference means an edge in the dependency graph: the referenced object is created first and destroyed last.
  3. Reserve depends_on for dependencies no expression reveals.

Exam tip: A reference is a dependency: Terraform orders by the graph, never by file order.

Terraform Resources, Data Sources, Variables, and Outputs — the lesson that teaches this.

Question 3Terraform configuration

Before running terraform plan, an engineer runs export TF_VAR_instance_type=m5.large. The working directory also contains terraform.tfvars with instance_type = "t3.small". No other source sets the variable. Which value does the plan use?

Choose one.

  • a
    t3.small, the value set in the terraform.tfvars file Correct

    Correct. terraform.tfvars is loaded after TF_VAR_ environment variables, so its value overrides the environment variable.

  • b
    m5.large, the value set in the TF_VAR_instance_type variable

    TF_VAR_ environment variables have the lowest precedence of all definition sources; any tfvars file that sets the same variable overrides them.

  • c
    Neither; terraform.tfvars and TF_VAR_ conflict, so the plan stops

    Setting a variable in several sources is normal and not an error; Terraform applies its precedence order and the last-loaded source wins.

  • d
    Neither; Terraform prompts to choose t3.small or m5.large

    Terraform prompts only when a required variable has no value at all. With two values it applies precedence silently.

The concept

Terraform loads variable values from several sources in a fixed order, and a later source overrides an earlier one.

Why that’s the answer

From lowest to highest precedence the order is: TF_VAR_ environment variables, terraform.tfvars, terraform.tfvars.json, *.auto.tfvars files in lexical order, then -var and -var-file options. terraform.tfvars therefore beats the environment variable. Many candidates assume environment variables are strong because they feel like an override, but they are the weakest definition source.

How to reason it out
  1. List the sources that set the variable: an environment variable and terraform.tfvars.
  2. Place them in the precedence order: TF_VAR_ is loaded first, terraform.tfvars after it.
  3. The later source wins, so the plan uses t3.small.

Exam tip: TF_VAR_ environment variables are the weakest definition source; any tfvars file overrides them.

Terraform Resources, Data Sources, Variables, and Outputs — the lesson that teaches this.

Question 4Terraform configuration

A directory contains prod.auto.tfvars with region = "us-east-1". An engineer runs terraform plan -var="region=eu-west-1". Which region does the plan use?

Choose one.

  • a
    us-east-1, from the auto-loaded prod.auto.tfvars file

    *.auto.tfvars files outrank terraform.tfvars and environment variables, but command-line options are processed after them.

  • b
    Neither; Terraform stops with a duplicate value error for region

    Defining the same variable in a file and on the command line is allowed; precedence decides the winner without an error.

  • c
    eu-west-1, from the -var option given on the command line Correct

    Correct. -var and -var-file options have the highest precedence, so the command-line value overrides the auto-loaded file.

  • d
    Neither; Terraform prompts for region since two sources conflict

    Prompting happens only when a required variable has no value. Here two values exist and precedence chooses one.

The concept

Command-line -var and -var-file options are the highest-precedence way to set a variable.

Why that’s the answer

Terraform loads auto-loaded files (terraform.tfvars, terraform.tfvars.json and *.auto.tfvars) before it processes -var and -var-file options, so the command-line value is applied last and wins. The tempting answer treats an auto-loaded file as an override, but auto-loading only means the file needs no flag; it does not raise its precedence above the CLI.

How to reason it out
  1. Identify the two sources: prod.auto.tfvars and a -var option.
  2. Recall that every auto-loaded file is processed before command-line options.
  3. The last source wins: eu-west-1.

Exam tip: -var and -var-file on the command line beat every file Terraform loads automatically.

Terraform Resources, Data Sources, Variables, and Outputs — the lesson that teaches this.

Question 5Terraform configuration

A variable "size" has default = "t3.micro". The environment sets TF_VAR_size=t3.small, terraform.tfvars sets size = "t3.medium", and sizing.auto.tfvars sets size = "t3.large". No -var or -var-file options are used. Which value does Terraform use?

Choose one.

  • a
    t3.small, from TF_VAR_size, which outranks the .auto.tfvars file

    Environment variables are the lowest-precedence definition source; both files in this directory override them.

  • b
    t3.medium, from terraform.tfvars, which outranks sizing.auto.tfvars

    terraform.tfvars beats the environment variable, but *.auto.tfvars files are loaded after it and override it.

  • c
    t3.medium, as auto files just fill variables that terraform.tfvars leaves unset

    Auto-loaded files are not a fallback. They are loaded after terraform.tfvars and override any value it set for the same variable.

  • d
    t3.large, from sizing.auto.tfvars, which outranks the others Correct

    Correct. *.auto.tfvars files are loaded after terraform.tfvars, which is loaded after TF_VAR_ variables, so the auto file's value wins.

The concept

When a variable is set in several places, Terraform applies the last-loaded value; the declared default is used only when nothing sets it.

Why that’s the answer

The load order is environment variables, then terraform.tfvars, then terraform.tfvars.json, then *.auto.tfvars in lexical order, then command-line options. With no -var or -var-file, the highest source present is sizing.auto.tfvars, so t3.large wins. The declared default is used only when no source sets the variable, and auto files are not a fill-in for unset values: they override terraform.tfvars.

How to reason it out
  1. Discard the default: it applies only when no source sets the variable.
  2. Order the three sources: TF_VAR_size, then terraform.tfvars, then sizing.auto.tfvars.
  3. No command-line options are present, so the last-loaded file, sizing.auto.tfvars, wins.

Exam tip: Default < TF_VAR_ < terraform.tfvars < terraform.tfvars.json < *.auto.tfvars < -var / -var-file.

Terraform Resources, Data Sources, Variables, and Outputs — the lesson that teaches this.

Question 6Terraform configuration

A working directory contains a.auto.tfvars with region = "us-east-1" and m.auto.tfvars with region = "us-west-2". No other source sets the variable. Which value does Terraform use?

Choose one.

  • a
    us-east-1, from the first auto file loaded in lexical order

    Terraform loads every *.auto.tfvars file. A later file does not get ignored; its values override earlier ones.

  • b
    Neither; Terraform errors on two auto files that set one variable

    Several auto-loaded files may set the same variable. Terraform resolves it by load order instead of raising an error.

  • c
    us-east-1, from the auto file with the older modification time

    File timestamps play no part in load order. The order is lexical by filename, so the later-sorting file wins.

  • d
    us-west-2, from the auto file loaded last in lexical order Correct

    Correct. *.auto.tfvars files are processed in lexical order of their filenames, so m.auto.tfvars is loaded after a.auto.tfvars and its value wins.

The concept

Multiple *.auto.tfvars files are all loaded, in lexical order of their filenames, and a later file overrides an earlier one.

Why that’s the answer

Because a.auto.tfvars sorts before m.auto.tfvars, Terraform loads it first and then applies m.auto.tfvars, whose region value replaces the earlier one. The near-twin that picks the first file gets the ordering rule right but the override direction wrong, and modification times play no part in load order.

How to reason it out
  1. Recognise that both files are auto-loaded; neither is ignored.
  2. Sort the filenames lexically: a.auto.tfvars, then m.auto.tfvars.
  3. Apply last-one-wins: us-west-2 from m.auto.tfvars.

Exam tip: *.auto.tfvars files load in lexical filename order, and the last one loaded wins.

Terraform Resources, Data Sources, Variables, and Outputs — the lesson that teaches this.

What Terraform 004 domain 4 tests, topic by topic

The official exam guide breaks Terraform configuration into 2 topics. The question bank follows the same split, so a weak topic shows up as a cluster of misses you can go back and read.

Published Terraform 004 practice questions per topic in Terraform configuration
TopicWhat it coversQuestions
Resources, data sources, variables, and outputsOfficial Terraform Associate 004 objective 4 (part 1). Using and differentiating resource and data blocks; referring to resource attributes and creating cross-resource references; using variables and outputs; understanding and using complex types.42
Expressions, functions, dependencies, and sensitive dataOfficial Terraform Associate 004 objective 4 (part 2). Writing dynamic configuration using expressions and functions; defining resource dependencies; validating configuration using custom conditions; best practices for managing sensitive data, including secrets management with Vault.44
Total86

Revise Terraform configuration before you drill it

Other Terraform 004 domains

Terraform configuration: your questions

Terraform configuration is domain 4 of the Terraform 004 exam guide and carries 22% of the scored content — the heaviest of the 8 domains. On a 57-question paper that works out to roughly 13 questions, though HashiCorp does not publish an exact per-domain count and individual exam forms vary.

Source

The domain weight and topic list on this page come from the official Terraform 004 exam guide.