Terraform Associate 004

Free Terraform Associate 004 practice questions

10 questions from our Terraform Associate 004 practice tests, each with the correct answer and a written explanation. Read them with the answers shown, or switch to quiz mode and answer first.

Back to the Terraform Associate 004 practice exams

Question 1 of 10, Infrastructure as Code (IaC) with Terraform. 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.)

  1. AA requirement that every provider uses the same resource types and arguments
  2. BAutomatic sharing of a single API credential across all configured providers
  3. CA dependency graph that can order resources even when they span several providers Correct answer
  4. DA built-in translator that ports resource definitions from one cloud to another
  5. EA provider ecosystem that exposes many platforms through one configuration language Correct answer

Answer and 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, Terraform Fundamentals. Choose 2.

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

  1. AOnly HashiCorp-maintained providers can be installed from the public Terraform Registry
  2. BEach provider adds resource types and data sources that wrap a target platform's API Correct answer
  3. CProviders are compiled into the Terraform binary, so upgrading Terraform upgrades them
  4. DProviders are plugins that Terraform installs during init, separately from the Terraform binary Correct answer
  5. EA configuration can use at most one provider from each cloud vendor in a single module

Answer and 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, Core Terraform Workflow

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?

  1. Aterraform apply -replace="aws_instance.web" Correct answer
  2. Bterraform state rm aws_instance.web followed by terraform plan
  3. Cterraform apply -target=aws_instance.web -refresh=false
  4. Dterraform taint aws_instance.web followed by terraform refresh

Answer and 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, Core Terraform Workflow

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

  1. Aterraform validate -json -recursive
  2. Bterraform plan -lock=false -check
  3. Cterraform fmt -check -recursive Correct answer
  4. Dterraform fmt -write=true -diff

Answer and 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, Terraform Configuration

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?

  1. AA precondition in the aws_instance lifecycle block comparing both AZs Correct answer
  2. BA postcondition on the EBS volume that inspects the instance after creation
  3. CA check block containing an assert that compares both availability zones
  4. DA validation block on the subnet variable that reads the volume's data source

Answer and 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, Terraform Configuration

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

  1. AA resource block manages an object's lifecycle; a data block only reads an existing object Correct answer
  2. BA data block stores secrets outside state, while a resource block always writes values into state
  3. CA data block can only reference local files, while a resource block can reference any provider object
  4. DA resource block reads existing objects, while a data block creates new objects through the provider

Answer and 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, Terraform Modules

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?

  1. AAdd providers = { aws = aws.west } to the module block Correct answer
  2. BAdd provider = aws.west to every resource inside the child module
  3. CDeclare a new required_providers block named west in the root
  4. DSet region = "us-west-2" as an input in the module block

Answer and 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, Terraform State Management

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

  1. AAutomatic state versioning, which merges both engineers' changes once each run finishes
  2. BWorkspace isolation, which gives each engineer a separate copy of state
  3. CThe dependency lock file, which serializes runs that share a provider
  4. DState locking, which lets only one operation write to the state at a time Correct answer

Answer and 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, Maintain Infrastructure with Terraform

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?

  1. AWrite import blocks and run terraform plan -generate-config-out=generated.tf Correct answer
  2. BRun terraform apply -refresh-only so Terraform discovers the unmanaged machines in the account and adds them
  3. CRun terraform import -all with the subscription ID to scan the account
  4. DRun terraform state pull to download the machines from the provider API

Answer and 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, HCP Terraform

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

  1. AThe local execution mode
  2. BThe agent pool workflow
  3. CThe CLI-driven workflow
  4. DThe VCS-driven workflow Correct answer

Answer and 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.