HashiCorp Terraform Associate (004) · 13% practice allocation

HashiCorp 004: Terraform fundamentals Practice Questions

5 free sample questions from the Terraform fundamentals domain, with answers and explanations. The full 004 bank has 282 questions across 8 domains. Questions are scenario-based and written from the official HashiCorp exam guide.

1.

Which of the following commands would you use to rewrite all .tf files in the current directory to conform to Terraform's canonical style without making any logical changes to the configuration?

  • A. terraform validate
  • B. terraform lint
  • C. terraform fmt✓ Correct
  • D. terraform refresh
Explanation

Correct: C. terraform fmt rewrites Terraform configuration files in the current directory to the canonical HCL style (indentation, alignment, spacing) without altering the logical meaning of the configuration. A is wrong — terraform validate checks configuration syntax and internal consistency but does NOT reformat files. B is wrong — terraform lint is not a built-in Terraform command; third-party tools like tflint exist but are not part of the core CLI. D is wrong — terraform refresh updates the Terraform state file to match the real-world infrastructure state; it does not touch source files.

2.

A Terraform configuration includes the following variable files in its working directory: terraform.tfvars, staging.auto.tfvars, and overrides.tfvars. The engineer runs terraform apply with no additional flags. Which files are loaded automatically, and in what order are they processed (first to last)?

  • A. overrides.tfvars is loaded first (it has the highest precedence by filename), then terraform.tfvars, then staging.auto.tfvars.
  • B. All three files are loaded automatically in alphabetical order: overrides.tfvars, staging.auto.tfvars, terraform.tfvars.
  • C. staging.auto.tfvars is loaded first, then terraform.tfvars; overrides.tfvars is NOT loaded automatically.
  • D. terraform.tfvars is loaded first, then staging.auto.tfvars; overrides.tfvars is NOT loaded automatically.✓ Correct
Explanation

Option D is correct: Terraform automatically loads terraform.tfvars (and terraform.tfvars.json) first, then any *.auto.tfvars files in lexicographic order. Files that are neither named terraform.tfvars nor suffixed .auto.tfvars — such as overrides.tfvars — are NOT loaded automatically and must be explicitly passed with -var-file=overrides.tfvars. Therefore terraform.tfvars is loaded first, then staging.auto.tfvars, and overrides.tfvars is ignored unless explicitly specified. Option A is wrong — there is no 'overrides' special file in Terraform's auto-loading rules. Option B is wrong — overrides.tfvars is not auto-loaded at all. Option C is wrong — terraform.tfvars is always loaded before *.auto.tfvars files.

3.

A platform engineer needs to update provider versions in an existing project. The .terraform.lock.hcl file currently pins the AWS provider to version 4.67.0. The engineer wants Terraform to re-evaluate the version constraints in required_providers and potentially select a newer version. Which command accomplishes this?

  • A. terraform init -upgrade✓ Correct
  • B. terraform providers lock
  • C. terraform init
  • D. terraform apply -refresh-only
Explanation

Correct: A. terraform init -upgrade instructs Terraform to ignore the currently recorded versions in .terraform.lock.hcl and re-resolve all provider and module version constraints, potentially selecting newer versions and updating the lock file. C is wrong: Running terraform init without -upgrade respects the existing .terraform.lock.hcl and will not upgrade already-installed providers. B is wrong: terraform providers lock updates the lock file's cryptographic hashes for additional platforms but does not upgrade provider versions. D is wrong: terraform apply -refresh-only reconciles state with actual infrastructure; it has no effect on provider versions or the lock file.

4.

Which of the following statements about terraform destroy are TRUE? (Select TWO)

  • A. terraform destroy is exactly equivalent to running terraform apply -destroy.✓ Correct
  • B. terraform destroy permanently deletes the Terraform configuration files from disk.
  • C. You can target a specific resource for destruction using terraform destroy -target=<resource_address>.✓ Correct
  • D. terraform destroy always skips the interactive confirmation prompt by default.
  • E. terraform destroy removes all resources from state but does not delete them in the cloud provider.
Explanation

Options A and C are correct. A: Since Terraform 0.15+, terraform destroy is an alias for terraform apply -destroy; the two commands are functionally identical. C: The -target flag works with terraform destroy just as with terraform apply, allowing scoped destruction of a single resource. Option B is wrong — terraform destroy never touches configuration files. Option D is wrong — like terraform apply, terraform destroy requires interactive approval unless -auto-approve is supplied. Option E is wrong — terraform destroy both removes resources from the provider AND updates the state file; terraform state rm removes from state only.

5.

A team is migrating from terraform taint to the modern recommended workflow. Which command and flag combination is the current HashiCorp-recommended way to force the replacement of an existing resource on the next apply?

  • A. terraform state mark-replace aws_instance.app
  • B. terraform apply -taint=aws_instance.app
  • C. terraform plan -replace=aws_instance.app followed by terraform apply with the saved plan
  • D. terraform apply -replace=aws_instance.app✓ Correct
Explanation

Correct: The -replace flag (introduced in Terraform 0.15.2) is the modern replacement for terraform taint. Running terraform apply -replace=aws_instance.app forces Terraform to destroy and re-create the specified resource in a single step. HashiCorp deprecated terraform taint in favor of this approach. — Distractor A is wrong because -taint is not a valid flag for terraform apply. — Distractor B is partially correct in concept (you CAN run terraform plan -replace=... and save the plan), but the question asks for the recommended single-step approach, which uses -replace directly with apply. — Distractor D is wrong because terraform state mark-replace is not a valid subcommand.

Test yourself across every 004 domain

The free 004 practice test mixes about 20 questions weighted like the exam. The full 282-question bank adds instant grading, flashcards and a timed mock exam.

Study this domain

Terraform fundamentals study guide (004) →

Other 004 domains

← All HashiCorp Terraform Associate study resources