Free Terraform 004 practice questions: 20

Updated November 23, 2026

Twenty original questions across the eight objectives of the Terraform Associate (004), with an explanation for every answer. HashiCorp publishes no objective weights, so this set is spread by the number of sub-objectives instead: two questions each on objectives 1, 2, 5, 6, 7 and 8, and four each on objectives 3 and 4. That mirrors the published content list, but it is a planning choice, not a statement about the real exam. The questions are written from the objective list and Terraform 1.12 behaviour; none comes from the real exam. Aim for 16 or more correct, then use the study plan to turn misses into review time.

Objective 1: Infrastructure as Code

Question 1. A team wants to describe the end state of its network and let the tool work out which API calls are needed to reach it. Which property of Terraform does this describe?

  • A. It is imperative, so you script every step
  • B. It runs only inside the HCP Terraform service
  • C. It is declarative, so you describe the desired state
  • D. It depends on the public registry to decide the order of changes
Show answer

Answer: C

Terraform is declarative: you state the desired result and Terraform compares it with state and real objects to decide what to create, change or remove. An imperative tool would need you to script each step in order. Providers and the registry are mechanisms, not the property being described.

Want more questions like this? Full Terraform 004 practice tests →

Question 2. A company manages resources in two clouds and a DNS service. An engineer says the same configuration file can be applied unchanged to either cloud. What is the accurate correction?

  • A. It is correct, because providers translate every resource type to the other cloud
  • B. The workflow and language are shared, but resource types are provider-specific
  • C. Terraform can only manage one provider per configuration
  • D. Multi-cloud is possible only with HCP Terraform
Show answer

Answer: B

Terraform gives one workflow and one language across platforms, but resource types belong to providers, so an AWS resource block is not valid for another cloud. You write provider-specific resources and reuse the workflow, state handling and modules. The claim that providers translate resources automatically between clouds is wrong.

Want more questions like this? Full Terraform 004 practice tests →

Objective 2: Terraform fundamentals

Question 3. Developers on one team get different minor provider versions on their laptops, and plans differ between them. Which practice makes everyone use the same selected provider versions?

  • A. Run terraform fmt before every commit
  • B. Add the provider version to the state file by hand
  • C. Remove all version constraints so the newest is always used
  • D. Commit the dependency lock file .terraform.lock.hcl
Show answer

Answer: D

The dependency lock file, .terraform.lock.hcl, records the provider versions selected during init, and committing it to version control makes teammates use the same selections. Version constraints alone allow a range, the state file does not pin provider selections, and terraform fmt only formats files.

Want more questions like this? Full Terraform 004 practice tests →

Question 4. A configuration must create one resource in us-east-1 and another in eu-west-1 using the same provider. What is the correct approach?

  • A. Add a second provider block with an alias and set provider on the second resource
  • B. Declare two unaliased provider blocks for the same provider
  • C. Run the configuration twice with a different workspace for each region
  • D. Put the region in the resource name
Show answer

Answer: A

Define a second provider configuration with an alias and point the second resource to it with the provider argument. Two unaliased configurations of the same provider are not allowed, and a variable cannot change the region of a single provider block per resource.

Want more questions like this? Full Terraform 004 practice tests →

Objective 3: Core workflow

Question 5. Which statement about terraform validate is correct?

  • A. It confirms the cloud API will accept every value
  • B. It checks syntax and internal consistency without changing infrastructure
  • C. It rewrites files to the canonical style
  • D. It applies the configuration in a test mode
Show answer

Answer: B

Validate checks that the configuration is syntactically valid and internally consistent, for example that references and argument types make sense. It does not compare against real infrastructure or confirm that a remote API will accept your values, which is what planning and applying reveal. It also does not change anything.

Want more questions like this? Full Terraform 004 practice tests →

Question 6. A CI pipeline must fail when any configuration file is not in canonical style, without rewriting the files. Which command fits?

  • A. terraform fmt
  • B. terraform validate
  • C. terraform fmt -check
  • D. terraform init
Show answer

Answer: C

terraform fmt -check reports whether files need formatting and returns a non-zero exit status if they do, without changing them. Plain terraform fmt rewrites files, validate does not check style, and init prepares the working directory.

Want more questions like this? Full Terraform 004 practice tests →

Question 7. One server created by Terraform has become unhealthy, and the team wants to rebuild just that resource in the next run while keeping its configuration. Which approach is current and correct?

  • A. terraform apply with the replace option naming that resource address
  • B. Edit terraform.tfstate by hand to remove the server
  • C. Run terraform destroy for the whole configuration
  • D. Run terraform fmt on the file
Show answer

Answer: A

The replace option on plan or apply forces the named resource to be destroyed and created again in that run. Editing the state file by hand is unsafe, destroying everything is far wider than needed, and terraform fmt has no effect on resources.

Want more questions like this? Full Terraform 004 practice tests →

Question 8. An engineer runs terraform destroy in a directory. Which objects does it remove?

  • A. Every resource in the cloud account
  • B. The configuration files in the directory
  • C. Only the resources created in the last apply
  • D. The infrastructure tracked by that configuration and its state
Show answer

Answer: D

Destroy plans the removal of the objects that the configuration and its state manage, and it shows the plan for approval first. Unmanaged resources in the same account are not tracked, so they are left alone. It does not delete the configuration files.

Want more questions like this? Full Terraform 004 practice tests →

Objective 4: Terraform configuration

Question 9. A team wants Terraform to fail if a created resource ends up with an attribute value that the module author considers invalid, checked after the object exists. Where does this rule belong?

  • A. A validation block in a variable
  • B. A postcondition in the lifecycle block of the resource
  • C. A depends_on argument on the resource
  • D. The sensitive argument on an output
Show answer

Answer: B

A postcondition in the lifecycle block of a resource or data source checks the result after it exists and can reference the object through self. A variable validation block only checks inputs, depends_on only orders operations, and marking a value sensitive only hides it in output.

Want more questions like this? Full Terraform 004 practice tests →

Question 10. A variable has a default of t3.small. A terraform.tfvars file sets it to t3.medium, the environment variable TF_VAR_instance_type is t3.large, and the command line includes -var with t3.xlarge. Which value is used?

  • A. t3.small, because the default is declared in code
  • B. t3.medium, because tfvars files always win
  • C. t3.large, because environment variables always win
  • D. t3.xlarge, because command line values have the highest precedence
Show answer

Answer: D

Variable values are applied in order and later sources win: defaults, environment variables, terraform.tfvars, auto tfvars files, then -var and -var-file options from the command line, which have the highest precedence. So the command line value t3.xlarge is used.

Want more questions like this? Full Terraform 004 practice tests →

Question 11. A configuration passes a list of three strings to for_each on a resource and fails with an error about the argument type. What is the right fix?

  • A. Add depends_on to the resource
  • B. Mark the variable as sensitive
  • C. Convert the list with the toset function
  • D. Rename the resource
Show answer

Answer: C

for_each accepts a map or a set of strings, not a list. Wrapping the list in toset gives it a stable unique key per element. Switching to depends_on does not create instances, and sensitive and count do not change the type that for_each needs.

Want more questions like this? Full Terraform 004 practice tests →

Question 12. A variable holding a database password is marked sensitive. A colleague with read access to the remote state backend asks whether the password is protected there. What is correct?

  • A. No, the value is still stored in state, so state access must be protected
  • B. Yes, sensitive encrypts the value inside the state file
  • C. Yes, sensitive keeps the value out of the state file
  • D. No, but only for string values
Show answer

Answer: A

The sensitive argument redacts a value in CLI and UI output, but Terraform still stores it in state and plan files, so anyone who can read state can see it. That is why state access must be restricted and why secrets should be fetched at run time, and ephemeral values or write-only arguments avoid storing some values at all.

Want more questions like this? Full Terraform 004 practice tests →

Objective 5: Modules

Question 13. A team wants to create the same module once for each of three environments defined in a map. Which feature fits?

  • A. Declare an output for each environment
  • B. Use for_each on the module block with the map
  • C. Add three provider blocks and no module block
  • D. Use depends_on on the module block
Show answer

Answer: B

A module block accepts for_each (and count), creating one instance of the module per key. Copying the module block three times works but does not scale from a map, and neither outputs nor providers create instances.

Want more questions like this? Full Terraform 004 practice tests →

Question 14. Which version constraint on a registry module allows 5.1.4 and 5.1.9 but not 5.2.0?

  • A. version = “>= 5.1.0”
  • B. version = “~> 5.1”
  • C. version = “~> 5.1.0”
  • D. version = “5.1.4”
Show answer

Answer: C

The pessimistic operator allows only the rightmost specified component to increase, so ~> 5.1.0 allows 5.1.x patch releases but not 5.2.0. The constraint ~> 5.1 would also allow 5.2.0, a greater than or equal rule has no upper bound, and an exact version allows only one release.

Want more questions like this? Full Terraform 004 practice tests →

Objective 6: State management

Question 15. An apply was interrupted when a runner crashed, and the next plan reports that the state is locked by an operation that is no longer running. What is the appropriate action after confirming nobody else is running Terraform?

  • A. Run terraform force-unlock with the lock ID
  • B. Delete the state file and start again
  • C. Run terraform destroy to clear the lock
  • D. Disable locking for every future run
Show answer

Answer: A

terraform force-unlock with the lock ID releases a stale lock, and should only be used when you are sure no other operation holds it. Deleting the state or destroying infrastructure is far too destructive, and disabling locking everywhere removes the protection against concurrent writes.

Want more questions like this? Full Terraform 004 practice tests →

Question 16. Someone changed a tag in the cloud console, and the team decides the new tag value is correct. They want Terraform state to record it without changing any infrastructure. Which approach fits?

  • A. terraform destroy followed by apply
  • B. Edit the state file by hand
  • C. A normal apply, which keeps the console value
  • D. A refresh-only plan and apply
Show answer

Answer: D

A refresh-only plan or apply updates state to match real objects without proposing infrastructure changes, so the team can accept the console change into state. A normal apply would revert the tag to the configuration, and destroy or editing the state file by hand are unsafe or far too wide. The configuration should then be updated to match.

Want more questions like this? Full Terraform 004 practice tests →

Objective 7: Maintain infrastructure

Question 17. A team wants to bring an existing storage bucket under Terraform management and have the import appear as a reviewable change in a plan. Which approach fits?

  • A. A data block for the bucket
  • B. An import block with the resource address and the bucket ID
  • C. terraform state list
  • D. terraform fmt
Show answer

Answer: B

An import block in configuration, with the target resource address and the real object’s ID, lets terraform plan show the import for review before apply. The classic import command acts immediately on state, state list only reads, and a data block reads an object without managing it.

Want more questions like this? Full Terraform 004 practice tests →

Question 18. An engineer sets only TF_LOG_PATH to a file name and runs a plan, but no log file appears. What is the reason?

  • A. Logging is available only in HCP Terraform
  • B. The file must be created by hand first
  • C. TF_LOG must also be set to enable logging at a level
  • D. Logs are written only during terraform init
Show answer

Answer: C

TF_LOG_PATH only chooses where logs are written. Logging is enabled by setting TF_LOG to a level such as TRACE, DEBUG, INFO, WARN or ERROR, and without it nothing is logged even if the path is set.

Want more questions like this? Full Terraform 004 practice tests →

Objective 8: HCP Terraform

Question 19. A team wants a successful apply in a networking workspace to automatically queue a run in a dependent application workspace. Which HCP Terraform feature fits?

  • A. Run triggers
  • B. Variable sets
  • C. A private registry
  • D. Projects
Show answer

Answer: A

Run triggers connect workspaces so that a successful run in a source workspace queues a run in the dependent workspace. Variable sets share values, a private registry distributes modules, and projects group workspaces for access management without triggering runs.

Want more questions like this? Full Terraform 004 practice tests →

Question 20. A security team wants runs in HCP Terraform to authenticate to a cloud provider without storing long-lived access keys in workspace variables. What should they configure?

  • A. Store the keys in a workspace variable marked sensitive
  • B. Store the keys in a variable set shared by all workspaces
  • C. Run Terraform from engineer laptops instead
  • D. Dynamic provider credentials for the workspace
Show answer

Answer: D

Dynamic provider credentials let a run obtain short-lived credentials from the cloud provider at run time, so no long-lived key needs to be stored. Marking a stored key as sensitive still keeps a long-lived secret, and moving it to a variable set only changes where it is kept. Running from laptops moves the credential problem rather than solving it.

Want more questions like this? Full Terraform 004 practice tests →

After the test

Count correct answers per objective, not only the total. Misses on 1 to 3 point to the workflow guide, on 4 to the configuration guide, on 5 to modules, on 6 and 7 to state management and on 8 to HCP Terraform. HashiCorp does not publish the number of questions or the passing score, so this test is a diagnostic and not a prediction. The real exam is one hour, and HashiCorp’s own sample page shows true or false, multiple choice and multiple answer items, where the prompt says how many answers to pick. For the official five samples see study resources.