CertLumen

Free practice questions · DevOps

10 HashiCorp Certified: Terraform Associate (004) practice questions, with answers

Exam-style questions from the CertLumen course, spread over the exam's sections by their weights. Each has its answer and why. They're written for practice: never questions from the real exam.

Question 1 · Infrastructure as Code (IaC) with Terraform

A platform team wants reviewers to see exactly what an infrastructure change will do before it is merged, without making the change. Which practice and command should they use?

  1. ARun terraform plan in the pull request pipeline and let reviewers read the proposed changes
  2. BRun terraform fmt on the pull request so the formatting diff shows what will change in the cloud
  3. CRun terraform apply against production and revert the commit if the result is wrong
  4. DRun terraform validate, which lists the resources that would be created or destroyed
Show the answer

A. terraform plan produces an execution plan that shows what Terraform would create, update or destroy, and it does not change infrastructure. Putting it in the review pipeline lets reviewers approve with full knowledge. This is a key IaC advantage.

Question 2 · Terraform fundamentals

A configuration defines a default provider "aws" for us-east-1 and a second one with alias = "west" for us-west-2. Which change makes a bucket be created in us-west-2?

  1. ADeclare a second required_providers entry also named aws with another source
  2. BRun terraform workspace new west before applying
  3. CAdd provider = aws.west to the aws_s3_bucket resource
  4. DAdd region = "us-west-2" to the lifecycle block
Show the answer

C. Additional configurations of the same provider need a unique alias. A resource selects one with provider = aws.west; if it omits the argument, it uses the default configuration.

Question 3 · Core Terraform workflow

A virtual machine managed by Terraform is misbehaving, although terraform plan reports no changes. The team wants Terraform to destroy and re-create exactly that instance in the next apply. Which command should they use?

  1. Aterraform apply -target="aws_instance.web"
  2. Bterraform refresh
  3. Cterraform plan -destroy
  4. Dterraform apply -replace="aws_instance.web"
Show the answer

D. -replace=ADDRESS plans a replacement for one object even when its configuration did not change. It supersedes the older terraform taint workflow.

Question 4 · Terraform configuration

A configuration builds three Docker containers using count = length(var.names) and var.names = ["a", "b", "c"]. An engineer removes "a" from the list and runs terraform plan. What does the plan show?

  1. AOnly the container for a is destroyed, and the others are untouched
  2. BInstances 0 and 1 are updated to the new values
  3. CNo changes, because count ignores the content of the list
  4. DAn error, because count cannot use length() of a variable
Show the answer

B. count identifies instances by position. Removing an element from the middle or start shifts every later element down one index, so the plan changes several instances. for_each keyed by name avoids this.

Question 5 · Terraform configuration

A module should create an optional monitoring container only when var.enable_monitoring is true. Which approach is idiomatic?

  1. Acount = var.enable_monitoring ? 1 : 0 on the resource
  2. Benabled = var.enable_monitoring as a meta-argument on the resource
  3. Cdepends_on = [var.enable_monitoring]
  4. Dlifecycle { prevent_destroy = var.enable_monitoring }
Show the answer

A. A conditional expression that yields 1 or 0 for count is the standard way to create a resource conditionally.

Question 6 · Terraform modules

An engineer changes version = "3.0.0" to version = "3.1.0" in a registry module block and immediately runs terraform plan. What is the result?

  1. ATerraform says the module must be re-installed and asks for terraform init
  2. BTerraform silently downloads 3.1.0 during the plan and then continues with the plan
  3. CTerraform plans using the previously installed 3.0.0 code and ignores the new version
  4. DTerraform deletes the resources created from 3.0.0 first and then creates new ones
Show the answer

A. Installed module code is tied to the source and version recorded in .terraform/modules/modules.json. When they no longer match the configuration, you must run terraform init.

Question 7 · Terraform state management

After adding a backend "s3" block to a project that has used local state, an engineer runs terraform plan and gets an error that backend initialization is required. What should they do?

  1. ARun terraform init and answer yes to copy the existing state to the new backend
  2. BRun terraform apply -refresh-only so the state is rewritten into the new bucket
  3. CDelete terraform.tfstate so that Terraform creates a fresh state in S3
  4. DRun terraform state push before any other command
Show the answer

A. Any change to backend configuration needs terraform init before plan or apply. Terraform detects the change and asks whether to copy existing state to the new backend. Use -migrate-state to do this explicitly.

Question 8 · Maintain infrastructure with Terraform

A resource block was written by hand for an imported bucket. After the import, terraform plan shows ~ update in-place for the tags argument. What does this indicate?

  1. AThe import failed and the bucket was not saved in state, so the import block must be re-run
  2. BThe configuration differs from the real bucket; edit it until the plan shows no changes
  3. CTerraform will delete the imported bucket and create a new one that has the tags
  4. DThe import block must be kept, otherwise the update cannot be applied to the bucket
Show the answer

B. After a successful import the object is in state and the next plan compares it with your configuration. An update means your configuration disagrees with the real object. Adjust the configuration until the plan is empty, or apply the change if it is intended.

Question 9 · HCP Terraform

Two teams use the same cloud credentials. Currently each of 60 workspaces holds a copy. A key rotation takes a day. What is the best improvement?

  1. AMark each variable as HCL so that it can be rotated in bulk
  2. BPut the credentials in a variable set and apply it to the projects
  3. CPut the keys in each repository's terraform.tfvars file and commit them
  4. DUse a run trigger from one workspace to the others
Show the answer

B. A variable set applied at the organization or project scope is the managed way to share values across workspaces.

Question 10 · HCP Terraform

A team has local state and adds a cloud block. After terraform init, what does Terraform do with the existing state?

  1. ADeletes it and starts with an empty workspace
  2. BIgnores it and uses the configuration only
  3. CUploads it without asking
  4. DAsks whether to copy it to the HCP Terraform workspace
Show the answer

D. The migration happens at init. After it you should see a state version in the workspace and an empty plan.

How ready are you?

Take ten more, weighted like the real exam, and see your score by section and a rough chance of passing. The course has 372 questions and 4 timed practice exams.

Take the free check

About the course · Free study guide · A question a day by email