Question 1
What is the purpose of the .terraform.lock.hcl file?
Correct Answer:
Tracking provider dependencies
Explanation:
The file serves to lock provider versions so runs are reproducible. It records which providers your configuration uses, the exact versions that were resolved, their sources, and a checksum for each provider binary. When you run Terraform init again, Terraform reads this lock file and installs the same provider versions, ensuring consistent behavior across machines and environments. This prevents unexpected upgrades from happening just because new provider versions exist. The lock file is generated and updated by Terraform and is about locking provider dependencies, not about blocking runs or storing workspace data.
Question 2
When you modify a resource in Azure Portal that is managed by Terraform, when does Terraform reflect that change in its state?
Correct Answer:
During the next plan or apply
Explanation:
Terraform tracks resources in a state file and only learns about outside changes when it refreshes that state. If you tweak a resource in Azure Portal, Terraform’s view becomes out of sync. When you run the next plan (or apply), Terraform refreshes its state by querying Azure for the current attributes of the resource. This refresh updates the in-memory state to reflect the real-world resource, and the plan will show any drift. When you then apply, the state file itself is updated to match the actual resource, bringing everything back into alignment. So the change is reflected the next time you run plan or apply.
Question 3
Which option cannot be used to keep secrets out of Terraform configuration files?
Correct Answer:
Secure string
Explanation:
In Terraform, you want to avoid placing secret values directly in configuration files and instead provide them at runtime or via external sources. The only option that would not help with that is a secure string, because it implies embedding the secret value as a literal string in the configuration. That would keep secrets in the code, defeating the goal of externalizing them. Environment variables and the -var flag are common ways to supply secrets without hardcoding them in .tf files, and providers can be configured to read credentials from environment variables or secret stores, further keeping secrets out of the configuration itself.
Question 4
When writing Terraform code, how should you indent each nesting level relative to the level above it?
Correct Answer:
With two spaces
Explanation:
In Terraform's HCL, indent each nesting level by two spaces. This means the first level inside a block uses two spaces, the next level uses four spaces, and so on. Using two spaces per level keeps code readable and aligns with the official style shown in examples, and avoids the inconsistencies that can come from tabs or other indentation amounts. For example: resource "aws_instance" "web" { ami = "ami-12345678" instance_type = "t2.micro" network_interface { device_index = 0 } } Here, top-level lines inside the resource start with two spaces; the nested block inside has four spaces, showing the two-space-per-level rule. Tabs are discouraged because their width can vary between editors, and options like three or four spaces per level aren’t the standard in Terraform.
Question 5
Which file stores the Terraform state locally?
Correct Answer:
terraform.tfstate
Explanation:
Terraform keeps a local state file that tracks what it manages and how resources map to real-world objects. By default, when you don’t configure a different backend, Terraform writes this state to a file named terraform.tfstate in your working directory. This file is JSON and includes resource addresses, IDs assigned by providers, and current attributes and dependencies, which is what allows Terraform to plan changes accurately and reconcile drift. A backup of the previous state is kept as terraform.tfstate.backup. If you configure a remote backend (like S3, Consul, etc.), the state is stored remotely, and there isn’t a local terraform.tfstate file. The other file name options don’t match Terraform’s local-state convention, so terraform.tfstate is the correct choice.
Question 1
Exam overview

About this Exam

Prepare with the HashiCorp Terraform Associate Practice Exam practice quiz. This question bank includes 10 questions covering terraform, state, file, cannot, and level. Use it to review important concepts, identify knowledge gaps, and build confidence for the related exam, course, or assessment.

More details

Additional Information

HashiCorp Terraform Associate Practice Exam

This practice set contains 10 questions from the matching question bank and focuses on terraform, state, file, cannot, and level. Work through each question carefully, review the provided solutions, and revisit topics that need more study before your next attempt.

This is an independent study resource intended for practice and review; it is not an official examination or an endorsement by any organization named in the title.

Quiz information

Frequently Asked Questions

The complete question count is available after full access is unlocked.
No fixed duration is currently configured for this quiz.
Question explanations are included where they are available in the quiz content, helping you review the reasoning after answering.
Yes. You can retake the practice test again as you continue studying during your available access period.
After your access is confirmed, you can continue into the complete practice exam from this quiz flow.
Unless explicitly stated otherwise, this page provides independent practice material for study and exam preparation and is not the official examination itself.
Keep studying

Related Questions