HashiCorp Terraform Infrastructure Engineer Professional Practice Exam
HashiCorp Certified: Terraform Infrastructure Engineer Professional (002)
The HashiCorp Certified: Terraform Infrastructure Engineer Professional (002) certification validates the skills to build, automate, secure and maintain scalable infrastructure with Terraform in production, tested on Terraform 1.15. The exam covers seven objective areas: scalable configuration design, state and backend operations, infrastructure lifecycle and operations, CI/CD and automation workflows, security and governance, advanced module usage and registry practices, and HCP Terraform and Enterprise operations. HashiCorp publishes no domain weights. This practice exam mirrors its multiple-choice style with single-answer and multiple-answer questions, many built on scenarios and HCL configuration to read.
Exam version: 002
600 questions in the bank
Question bank updated : questions, answers, explanations and chapters.
Certification Overview
- Exam name: Terraform Infrastructure Engineer Professional
- Vendor: HashiCorp
- Duration: 90 minutes
- Total questions: about 60
- Our practice exam pass mark: 70%
Who Should Take This Exam?
Infrastructure Engineer, Cloud Engineer, DevOps Engineer, Platform Engineer, Site Reliability Engineer, Cloud Architect, Automation Engineer, Solutions Architect
Prerequisites
HashiCorp strongly recommends the Terraform Associate certification, or requires equivalent experience, plus experience with Terraform in a production setting, basic terminal skills and an understanding of on-premises and cloud architecture.
Topics Covered
- Scalable Terraform Configuration Design
- Terraform State and Backend Operations
- Infrastructure Lifecycle and Operations
- CI/CD and Automation Workflows
- Terraform Security and Governance
- Advanced Module Usage and Registry Practices
- HCP Terraform / Enterprise Operations
Question Types
- Multiple Choice (Single Answer)
- Multiple Choice (Multiple Answers)
Terraform Infrastructure Engineer Professional Practice Questions
Our question bank contains 600+ practice questions for this certification. Sample questions from each exam chapter. Expand a question to see the answer choices. With full access, you get unlimited practice exams with randomized questions from our full question bank.
Scalable Terraform Configuration Design
An engineer must generate one ingress block inside an aws_security_group for each entry in var.rules, a list of objects. Which construct does this?
- A. A count argument written inside the ingress block
- B. A for expression used as the ingress block label
- C. for_each set on the aws_security_group resource itself
- D. A dynamic "ingress" block that iterates over var.rules Correct answer
Option D is correct because a dynamic block generates one nested block per element of the collection it iterates over, which is how a variable number of ingress blocks is built. Option A is wrong because count is not allowed inside a nested block. Option B is wrong because block labels are fixed names, not expressions. Option C is wrong because for_each on the resource would create multiple security groups rather than multiple rules inside one.
Consider the following configuration: variable "db_password" { type = string sensitive = true } output "db_url" { value = "postgres://app:${var.db_password}@db.internal/orders" } What happens when the engineer runs terraform plan?
- A. Terraform silently drops db_url from both the plan and the state file
- B. Plan completes and shows db_url in its output as (sensitive value)
- C. Terraform prints the whole connection string, password included, in the plan
- D. Terraform returns an error saying the output must set sensitive = true Correct answer
Option D is correct because the output interpolates a sensitive variable, and Terraform refuses to evaluate an output that carries a sensitive value unless the output itself sets sensitive = true. It stops with an error instead of hiding or printing the value. Options B and C assume the plan succeeds, and option A is wrong because outputs are never silently dropped from the plan or state.
A root module gives variable team the default web and uses it in a local: locals { prefix = "${var.team}-prod" } The directory has a terraform.tfvars file with team = "payments", and the shell exports TF_VAR_team=checkout. The engineer runs terraform plan -var team=billing. What is the value of local.prefix?
- A. payments-prod
- B. checkout-prod
- C. billing-prod Correct answer
- D. web-prod
Option C is correct because a -var flag on the command line has the highest precedence among the ways to set a variable. It overrides terraform.tfvars (payments), the TF_VAR_team environment variable (checkout) and the default (web), so local.prefix is billing-prod.
Terraform State and Backend Operations
A team plans to raise the minimum provider versions across a root module and three child modules. Which command prints the provider requirements of the configuration as a tree, grouped by module?
- A. terraform providers Correct answer
- B. terraform providers schema -json
- C. terraform providers lock
- D. terraform version
Option A is correct because terraform providers prints a tree of the provider requirements for the root module and each child module. Option B (terraform providers schema -json) outputs provider schemas as JSON, not the requirement tree. Option C (terraform providers lock) writes checksums to the dependency lock file, and option D (terraform version) only reports the Terraform and installed provider versions.
After terraform init runs on a root module that calls several local and registry modules, which file records where each installed module was placed on disk?
- A. .terraform.lock.hcl
- B. .terraform/terraform.tfstate
- C. .terraform/modules/modules.json Correct answer
- D. terraform.tfstate.backup
Option C is correct because terraform init records each installed module's key, source and directory in .terraform/modules/modules.json. Option A (.terraform.lock.hcl) pins provider versions and checksums, not modules. Option B (.terraform/terraform.tfstate) holds backend configuration metadata, and option D (terraform.tfstate.backup) is a copy of the previous state.
Resource aws_eip.web sets instance = aws_instance.web.id. Both resources are in state and the engineer runs terraform destroy. In which order does Terraform destroy them?
- A. Both at once, because neither resource sets depends_on
- B. aws_eip.web first, then aws_instance.web Correct answer
- C. aws_instance.web first, then aws_eip.web
- D. In the order the blocks appear in the file
Option B is correct because Terraform destroys resources in reverse dependency order, and the reference to aws_instance.web.id makes aws_eip.web depend on the instance, so the address is destroyed first. Option A is wrong because the reference already creates an implicit dependency, so depends_on is not needed. Option C reverses the order, and option D is wrong because file order never decides execution order.
Infrastructure Lifecycle and Operations
A pipeline engineer wants the Terraform diagnostic log written to a file named debug.log instead of the console. TF_LOG=DEBUG is already exported. Which additional environment variable does this?
- A. TF_LOG_FILE=debug.log
- B. TF_LOG_OUTPUT=debug.log
- C. TF_LOG_PATH=debug.log Correct answer
- D. TF_DEBUG_PATH=debug.log
Option C is correct because TF_LOG_PATH names the file that receives the log output once TF_LOG sets a level. TF_LOG_FILE, TF_LOG_OUTPUT and TF_DEBUG_PATH are not Terraform variables and are ignored.
During a large apply, the cloud provider returns repeated API rate-limit errors because Terraform issues many requests at once. Which option lowers the number of concurrent operations on the next run?
- A. terraform apply -lock-timeout=120s
- B. terraform apply -parallelism=2 Correct answer
- C. terraform apply -refresh=false
- D. terraform apply -replace=aws_instance.web
Option B is correct because -parallelism limits how many resource operations run at once (default 10), which eases provider API rate limits. -lock-timeout only waits for the state lock, -refresh=false skips refresh, and -replace forces one resource to be recreated.
After a developer adds the random provider to required_providers, terraform plan fails with: Error: Inconsistent dependency lock file The following dependency selections recorded in the lock file are inconsistent with the current configuration: - provider registry.terraform.io/hashicorp/random: required by this configuration but no version is selected Which command resolves the error?
- A. terraform providers
- B. terraform get
- C. terraform init Correct answer
- D. terraform validate
Option C is correct because terraform init selects a version for the newly required provider and records it in .terraform.lock.hcl. terraform providers only lists requirements, terraform get fetches modules, and terraform validate does not update the lock file.
CI/CD and Automation Workflows
Which environment variable, when set to any non-empty value, makes Terraform omit its suggestions for the next command to run from its output?
- A. TF_APPEND_USER_AGENT
- B. TF_INPUT
- C. TF_CLI_ARGS
- D. TF_IN_AUTOMATION Correct answer
Option D is correct because setting TF_IN_AUTOMATION to any non-empty value tells Terraform it runs inside a pipeline, so it leaves out the hints about which command to run next. TF_INPUT controls prompting, TF_CLI_ARGS adds default arguments, and TF_APPEND_USER_AGENT only extends the HTTP user agent.
A pipeline checks out a monorepo whose root module sits in envs/prod. The job must run a plan for that module without changing the shell's working directory. Which command does this?
- A. terraform -chdir=envs/prod plan Correct answer
- B. terraform plan -chdir=envs/prod
- C. terraform plan -out=envs/prod
- D. terraform plan envs/prod
Option A is correct because -chdir is a global option and must come before the subcommand: terraform -chdir=envs/prod plan. Placed after plan (option B) it is rejected, -out names a plan file rather than a directory, and a bare path argument to plan is not a module directory.
Which two locations does terraform test search by default for test files when it runs in a module's root directory with no flags? Pick the 2 correct responses below
- A. Files ending in .test.hcl in the root directory
- B. Files ending in .tftest.hcl in the root directory Correct answer
- C. Files ending in .tftest.hcl in a test subdirectory
- D. Files ending in .tftest.hcl in a tests subdirectory Correct answer
- E. Files named main.test.tf in any subdirectory
Options B and D are correct because terraform test with no flags looks for files ending in .tftest.hcl (and .tftest.json) in the current directory and in a subdirectory named tests. Option A uses a suffix Terraform does not recognize. Option C names the wrong directory, since the default is tests rather than test. Option E is wrong because test files are written in test file syntax and are not named .tf files, and subdirectories other than tests are not searched unless you pass -test-directory.
Terraform Security and Governance
A Sentinel policy must reject any run whose estimated monthly cost rises by more than a set amount. Which Sentinel import exposes the cost estimate?
- A. tfrun Correct answer
- B. tfconfig/v2
- C. tfplan/v2
- D. tfstate/v2
Option A is correct because the tfrun import exposes run data, including the cost estimate (tfrun.cost_estimate) that HCP Terraform produces when cost estimation is on. tfplan/v2, tfconfig/v2 and tfstate/v2 expose the planned changes, the configuration and the prior state, so none of them carries a cost figure.
Which file in a Sentinel policy set's directory declares each policy and its enforcement level?
- A. policies.hcl
- B. policyset.json
- C. sentinel.hcl Correct answer
- D. enforcement.yaml
Option C is correct because a Sentinel policy set directory holds a sentinel.hcl file that lists each policy, its source and its enforcement level (advisory, soft-mandatory or hard-mandatory). The other file names are not read by HCP Terraform for this purpose.
A security team must write organization policies and also clear soft-mandatory failures on runs. Which two organization permissions should its team hold? Pick the 2 correct responses below
- A. Manage policies Correct answer
- B. Manage projects
- C. Manage policy overrides Correct answer
- D. Manage VCS settings
- E. Manage run tasks
Options A and C are correct because Manage policies lets a team write and edit organization policies and policy sets, and Manage policy overrides lets it override soft-mandatory failures on runs. Manage projects, Manage VCS settings and Manage run tasks control other areas and give neither ability.
Advanced Module Usage and Registry Practices
A team has declared the same VPC, two subnets and a route table in four root configurations, changing only the CIDR ranges each time. What change removes this duplication?
- A. Extract them into a module with CIDR input variables Correct answer
- B. Wrap each subnet in a dynamic block in every copy
- C. Use a separate workspace per CIDR range in one root
- D. Replace each copy with a data source for the VPC
Option A is correct because the four copies differ only in CIDR ranges, which is exactly what a module with input variables is for: one definition, called four times with different values. A dynamic block only generates nested blocks inside a resource and does not remove duplicated resources. Workspaces keep separate state but still need the same root configuration, and a data source reads an existing VPC instead of creating one.
A configuration must call just the consul-cluster submodule, which lives in the modules directory of the public registry module hashicorp/consul/aws. Which source value does this?
- A. hashicorp/consul-cluster/aws
- B. hashicorp/consul/aws/modules/consul-cluster
- C. hashicorp/consul/aws#modules/consul-cluster
- D. hashicorp/consul/aws//modules/consul-cluster Correct answer
Option D is correct because a double slash separates the package address from the subdirectory inside it, so hashicorp/consul/aws//modules/consul-cluster installs the registry module and uses only that submodule. Option A names a different registry module, option B has no subdirectory separator, and option C uses a # that Terraform does not treat as a subdirectory marker.
Which two situations most clearly justify extracting resources into a module? Pick the 2 correct responses below
- A. Other teams should consume a standard storage setup with fixed inputs as one unit Correct answer
- B. One bucket needs prevent_destroy to guard it against accidental deletion
- C. The same VPC and subnet pattern is declared in four environments with only CIDRs differing Correct answer
- D. Twenty resources owned by one team that nobody else consumes sit in one directory, with no repeats
- E. A single bucket needs one extra tag applied in only the production environment
Options A and C are correct because a module pays off when others consume a standard unit with fixed inputs, or when the same pattern repeats with only a few inputs changing. Option B is a lifecycle setting on one resource, option D is a single-owner group with no repetition, and option E is one conditional tag, so none of them need a module.
HCP Terraform / Enterprise Operations
One root module is deployed to three AWS accounts. The pipeline must point the s3 backend at a different bucket and role for each environment while the backend block in version control stays unchanged. Which command does this for production?
- A. terraform init -backend-config=envs/prod.s3.tfbackend Correct answer
- B. terraform init -var-file=envs/prod.tfvars
- C. TF_VAR_bucket=corp-prod-state terraform init
- D. terraform plan -backend-config=envs/prod.s3.tfbackend
Option A is correct because a partial backend configuration keeps the backend block unchanged and supplies the bucket and role per environment through -backend-config at init time. Option B passes -var-file, which feeds input variables and cannot configure a backend. Option C fails because backend blocks cannot read variables or TF_VAR values. Option D is wrong because -backend-config is an init option, not a plan option.
Consider the following configuration: variable "hosts" { type = list(string) default = ["api", "db", "cache"] } resource "aws_instance" "web" { count = length(var.hosts) ami = "ami-0c55b159cbfafe1f0" instance_type = "t3.micro" tags = { Name = var.hosts[count.index] } } The default list was applied. For production, prod.tfvars sets hosts = ["db", "cache"] and the engineer runs terraform plan -var-file=prod.tfvars against that state. Which result does the plan show?
- A. Replaces web[0] and destroys web[2]
- B. Destroys web[0] and leaves web[1] and web[2] unchanged
- C. Updates web[0] and web[1] in place and destroys web[2] Correct answer
- D. Destroys web[0] and updates web[1] and web[2] in place
Option C is correct because count indexes by position. With hosts = ["db", "cache"], web[0] changes its Name tag from api to db and web[1] from db to cache, both in place, while web[2] no longer has an index and is destroyed. Nothing is replaced because a tag change does not force a new instance, and the instances are matched by index, not by name.
Free Study Guide
Read the free HashiCorp Terraform Infrastructure Engineer Professional study guide: every exam topic explained in plain English, with diagrams, exam tips and the mistakes to avoid.
More HashiCorp Practice Exams
Practice with realistic mock exams to prepare for your HashiCorp certification.