# Free Terraform Associate 004 practice questions

> 10 free Terraform Associate 004 practice questions with the correct answer and an explanation.

Page: https://devopscodelab.com/exams/terraform-associate-004/free-practice-questions/
Practice exams: https://devopscodelab.com/exams/terraform-associate-004/

### Question 1 of 10 (choose 2)

A company manages Kubernetes clusters on two clouds plus GitHub repositories and Datadog monitors. Which characteristics of Terraform make a single workflow possible? (Choose two.)

- A. A requirement that every provider uses the same resource types and arguments
- B. Automatic sharing of a single API credential across all configured providers
- C. A dependency graph that can order resources even when they span several providers
- D. A built-in translator that ports resource definitions from one cloud to another
- E. A provider ecosystem that exposes many platforms through one configuration language

**Answer:** C, E

**Explanation:** Terraform uses providers to cover clouds, SaaS tools, and other APIs with one language, and its dependency graph can link resources across providers, for example passing a cluster endpoint into a monitoring resource. Terraform does not translate resources between clouds, each provider has its own resource types and arguments, and every provider uses its own credentials.

### Question 2 of 10 (choose 2)

Which statements about Terraform providers are correct? (Choose two.)

- A. Only HashiCorp-maintained providers can be installed from the public Terraform Registry
- B. Each provider adds resource types and data sources that wrap a target platform's API
- C. Providers are compiled into the Terraform binary, so upgrading Terraform upgrades them
- D. Providers are plugins that Terraform installs during init, separately from the Terraform binary
- E. A configuration can use at most one provider from each cloud vendor in a single module

**Answer:** B, D

**Explanation:** Providers are separate plugins downloaded by terraform init, and each one defines resource and data source types that translate configuration into API calls. They are versioned independently of Terraform core, the public registry hosts official, partner, and community providers, and a module can use multiple providers and multiple configurations of the same provider.

### Question 3 of 10

An EC2 instance is unhealthy even though its configuration has not changed. The team wants Terraform to recreate only that instance. Which command is the recommended approach?

- A. terraform apply -replace="aws_instance.web"
- B. terraform state rm aws_instance.web followed by terraform plan
- C. terraform apply -target=aws_instance.web -refresh=false
- D. terraform taint aws_instance.web followed by terraform refresh

**Answer:** A

**Explanation:** The -replace option on plan or apply forces replacement of a specific instance and shows it in the plan; it supersedes the deprecated taint command, and refresh would not perform a replacement anyway. -target with -refresh=false would find no changes, and state rm makes Terraform forget the instance, leaving the old one running unmanaged while creating a duplicate.

### Question 4 of 10

Which command checks whether all .tf files in a directory tree follow the canonical style, returning a non-zero exit code without rewriting anything?

- A. terraform validate -json -recursive
- B. terraform plan -lock=false -check
- C. terraform fmt -check -recursive
- D. terraform fmt -write=true -diff

**Answer:** C

**Explanation:** terraform fmt -check reports files that are not canonically formatted and exits non-zero without modifying them, and -recursive includes subdirectories. validate checks syntax and internal consistency rather than style and has no -recursive flag, -write=true rewrites files, and plan has no -check flag.

### Question 5 of 10

A team wants to guarantee that an instance's chosen subnet is in the same availability zone as an existing EBS volume, and stop before creating the instance otherwise. Which construct fits best?

- A. A precondition in the aws_instance lifecycle block comparing both AZs
- B. A postcondition on the EBS volume that inspects the instance after creation
- C. A check block containing an assert that compares both availability zones
- D. A validation block on the subnet variable that reads the volume's data source

**Answer:** A

**Explanation:** Preconditions are evaluated before Terraform creates or updates the resource and can reference other objects, so they can stop the instance from being created. A check block only warns, a postcondition after creation is too late to prevent the instance, and while validation rules can reference other values since Terraform 1.9, a resource precondition is the clearer fit for comparing two objects' attributes.

### Question 6 of 10

What is the key difference between a resource block and a data block?

- A. A resource block manages an object's lifecycle; a data block only reads an existing object
- B. A data block stores secrets outside state, while a resource block always writes values into state
- C. A data block can only reference local files, while a resource block can reference any provider object
- D. A resource block reads existing objects, while a data block creates new objects through the provider

**Answer:** A

**Explanation:** Resource blocks tell Terraform to create, update, and delete infrastructure objects, whereas data blocks only read existing information for use elsewhere in the configuration. The roles are not reversed, data sources are provided by any provider rather than only local files, and data source results are stored in state just like resource attributes.

### Question 7 of 10

A child module contains resources that must be created in a second AWS region using an aliased provider aws.west in the root module. How should the root module pass it?

- A. Add providers = { aws = aws.west } to the module block
- B. Add provider = aws.west to every resource inside the child module
- C. Declare a new required_providers block named west in the root
- D. Set region = "us-west-2" as an input in the module block

**Answer:** A

**Explanation:** The providers meta-argument on a module block maps the child's provider name to a specific configuration from the caller, such as aws = aws.west. Editing every resource in the child couples it to the caller's alias names, a region input only works if the module explicitly supports it, and required_providers does not define provider configurations.

### Question 8 of 10

Two engineers run terraform apply at the same time against an S3 backend configured with use_lockfile = true. What prevents them from corrupting state?

- A. Automatic state versioning, which merges both engineers' changes once each run finishes
- B. Workspace isolation, which gives each engineer a separate copy of state
- C. The dependency lock file, which serializes runs that share a provider
- D. State locking, which lets only one operation write to the state at a time

**Answer:** D

**Explanation:** State locking makes Terraform acquire a lock before writing state, so the second operation fails to acquire it instead of overwriting the first; the S3 backend supports native lock files with use_lockfile. Workspaces separate state only when engineers deliberately select different ones, the dependency lock file pins providers, and Terraform never merges concurrent state writes.

### Question 9 of 10

An engineer must bring 40 existing virtual machines under Terraform management and does not want to write all the resource blocks by hand. Which approach helps?

- A. Write import blocks and run terraform plan -generate-config-out=generated.tf
- B. Run terraform apply -refresh-only so Terraform discovers the unmanaged machines in the account and adds them
- C. Run terraform import -all with the subscription ID to scan the account
- D. Run terraform state pull to download the machines from the provider API

**Answer:** A

**Explanation:** With import blocks in place, terraform plan -generate-config-out writes starter resource configuration for the imported objects, which you then review and refine. There is no import -all scanning option, refresh-only only updates objects already in state, and state pull downloads the current state rather than discovering infrastructure.

### Question 10 of 10

Which HCP Terraform run workflow is triggered by commits to a linked repository branch rather than by commands on a developer's laptop?

- A. The local execution mode
- B. The agent pool workflow
- C. The CLI-driven workflow
- D. The VCS-driven workflow

**Answer:** D

**Explanation:** In the VCS-driven workflow, HCP Terraform queues runs when commits land on the workspace's configured branch. The CLI-driven workflow starts runs from terraform plan or apply on a workstation, local execution mode runs Terraform locally and only stores state remotely, and agent pools define where runs execute rather than what triggers them.

Ready for a timed run? Take the free 15-question Terraform Associate 004 mini exam: https://devopscodelab.com/app/exams/terraform-associate-004/mini/

DevOpsCode Lab is not affiliated with HashiCorp. Terraform Associate 004 and related names are trademarks of their owners. We write every question ourselves; these are not real exam questions.
