Can You Answer These 5 TF-IEP002 Questions on Terraform configuration?
Terraform configuration is a recurring theme in the HashiCorp Terraform Infrastructure Engineer Professional (002) (TF-IEP002) exam. The 5 questions below come with a full explanation of why each option is right or wrong.

HashiCorp Terraform Infrastructure Engineer Professional (002) (TF-IEP002) · Terraform configuration · 5 questions with answers and explanations
🧠How Terraform configuration is tested
Expect short HCL snippets and team requirements rather than definitions. Some items ask you to predict what an expression returns, others ask which construct enforces a rule, reads an outside fact or configures a provider. The wrong answers tend to be constructs that look close but behave differently, such as a warning where a hard stop was asked for, or a function that treats null and errors alike.
Watch for these while you work
• Decide first whether the rule must stop the run or only report a problem. Validation and preconditions block; a check block only warns.
• When a function result is asked, trace null, missing attributes and errors separately. try, coalesce and merge each treat these cases in their own way.
• For assistant and registry questions, remember that the Terraform MCP server supplies current documentation and workspace data as tools; it does not retrain the model.
📊 This set at a glance
Exam: TF-IEP002 · 60 questions · 90 minutes
This set: 4 applied, 1 advanced · 2 scenario, 1 comparison, 1 trade-off, 1 troubleshooting · 1 with more than one answer
Topics: Terraform, EC2
Question 1 of 5
Security publishes a golden AMI by tagging it approved=true. The application team wants every new plan to use the newest approved image and to fail early if none exists. Which approach implements this?
Show answer
✅ Answer: C
Difficulty: applied · Topic: Terraform, EC2
Reading existing facts with a data source
A data source queries something Terraform does not manage and exposes its attributes. data "aws_ami" "golden" with most_recent = true and a filter on tag approved resolves the newest matching image at each plan.
• The lookup removes the human step and the stale hard-coded ID.
• A precondition in a lifecycle block (on the consuming resource) or a postcondition on the data block states the assumption, for example that the image architecture is as expected, and fails the run with your message instead of an obscure provider error.
Because the ID is resolved at plan time, a new golden image shows up as a proposed change to the instance, which reviewers see in the plan.
Why each option works or fails
• ✗ A. Manual variable: it keeps a human lookup in the loop, so values go stale or get mistyped, and nothing in the code states the approval requirement.
• ✗ B. aws_ami resource: that registers a new image from a snapshot; the team only wants to read an image that security already owns.
• ✓ C. Data source with filter and condition (correct): the newest approved image is found automatically on every plan, and a failed assumption stops the run early with a readable message.
• ✗ D. Hard-coded ID: it is predictable but needs a pull request for every release, and the code cannot show that the image is approved.
Question 2 of 5
A module has local.cfg = { db = { port = null } } and the expression try(local.cfg.db.port, 5432). A teammate expects 5432. What value does the expression produce?
5432, because try replaces null values with the fallback"5432", converted to a string to match the null typenull, because the attribute exists and evaluating it raised no errorShow answer
✅ Answer: D
Difficulty: advanced · Topic: Terraform
try catches errors, not nulls
try(expr1, expr2, ...) evaluates its arguments in order and returns the first one that does not produce an error. The docs recommend using it sparingly, because it also hides typos in attribute names.
• If local.cfg.db.port were missing, evaluating it would raise "Unsupported attribute", and try would return the fallback.
• Here the attribute exists and its value is null. Reading it is not an error, so try returns null as is.
• To treat null as "unset", use coalesce(local.cfg.db.port, 5432), or combine them: coalesce(try(local.cfg.db.port, null), 5432).
Why each option works or fails
• ✗ A. Replaces nulls: try has no null handling; that is the job of coalesce or a conditional.
• ✗ B. String conversion: no conversion happens; the result is the first argument as evaluated, and a number fallback is never converted.
• ✗ C. Error: reading an attribute whose value is null is valid, and try would hide an error anyway.
• ✓ D. null (correct): the attribute is present, so no error occurs and try hands back the first argument unchanged, including a null.
Question 3 of 5
Which TWO statements about configuring providers for several accounts are accurate? (Select TWO)
region can be set from an input variablefor_each creates one configuration per accountassume_role to make calls in another accountShow answer
✅ Answer: A, E
Difficulty: applied · Topic: Terraform
Multiple accounts and regions
Each account or region needs its own provider configuration, selected with alias.
• Provider arguments are ordinary expressions, so values like region = var.region work. Avoid values that are known only after apply.
• A provider block can carry settings such as assume_role { role_arn = ... } (AWS) so one set of base credentials can act in other accounts.
• The set of configurations is static: for_each and count are not allowed on provider blocks, so each alias is written out.
• Reusable modules take configurations from the caller, with configuration_aliases, and do not carry their own provider blocks.
Why each option works or fails
• ✓ A. Variables in provider arguments (correct): the region or other settings can come from input variables.
• ✗ B. Automatic alias inheritance: only default configurations are inherited; aliases are passed in providers.
• ✗ C. Provider blocks in modules: legacy and discouraged, since they block count, for_each and depends_on on the module.
• ✗ D. for_each on providers: not supported; each configuration must be written as its own block.
• ✓ E. assume_role (correct): a provider configuration can assume a role in the target account, so one pipeline identity reaches several accounts.
Question 4 of 5
A subnet module must only be used with private subnets. Reviewers want a violation to block the apply, not just warn. Which construct fits?
Show answer
✅ Answer: B
Difficulty: applied · Topic: Terraform
Which assertion can block
Terraform has several ways to assert something about infrastructure.
• precondition and postcondition (lifecycle blocks of resources and data sources, and directly inside output blocks) stop the run when false. A precondition is evaluated before the object is acted on; a postcondition after.
• A check block with assert is for ongoing validation of whole-infrastructure assumptions. Failed assertions only produce warnings and never block plan or apply.
• Variable validation blocks check inputs only.
Because the stated goal is to block the apply, a precondition (or validation on the input) is the right tool.
Why each option works or fails
• ✗ A. Sensitive output read afterwards: this inspects the result only after infrastructure already exists and enforces nothing.
• ✓ B. Precondition (correct): a false condition raises the error message and halts the operation, so a public subnet cannot be created.
• ✗ C. check block: its assertions surface as warnings, so the run continues; it is for monitoring, not for gating.
• ✗ D. Comment: comments are ignored by Terraform and cannot fail a plan.
Question 5 of 5
A developer's AI coding assistant keeps writing arguments that a provider deprecated two releases ago. Which capability does connecting it to the Terraform MCP server add?
terraform apply locally with no credentials or approvalShow answer
✅ Answer: B
Difficulty: applied · Topic: Terraform
What the Terraform MCP server does
The Model Context Protocol (MCP) is an open standard for connecting AI models to external tools and data. The Terraform MCP server exposes Terraform-specific tools to the model through its MCP client.
• Registry tools such as search_providers, get_provider_details, get_latest_provider_version and the module tools return current documentation instead of what the model learned in training.
• This lowers the chance of outdated or invented arguments in generated configuration.
• With a token for HCP Terraform or Terraform Enterprise, it can also reach private registries and workspaces.
It does not train models, replace the lock file, or bypass your access controls.
Why each option works or fails
• ✗ A. Replacing the lock file: version selection stays in Terraform's own constraints and .terraform.lock.hcl.
• ✓ B. Registry documentation tools (correct): the assistant fetches up-to-date provider docs on demand, so suggestions follow the current schema.
• ✗ C. Credential-free apply: workspace and run tools need a valid token, and destructive ones are off unless enabled explicitly.
• ✗ D. Retraining: the server supplies information at request time; it does not change the model.
🎯 Takeaways
• Facts that live outside your state (the newest approved image) are read with data sources and protected with conditions.
• try falls back on errors only; a present attribute holding null is returned as null (use coalesce for that).
• Provider arguments can use variables and assume_role, but configurations are static blocks and aliases are passed explicitly.
• Block with preconditions/postconditions/validation; check blocks only warn.
• The MCP server gives AI assistants live registry, module and workspace information so generated code uses current data.
🔗 Keep practicing on this blog
• All TF-IEP002 practice sets
• Every exam on this blog
📚 Keep studying TF-IEP002
More TF-IEP002 questions: https://hyunhp.github.io/cert-bank/#exam=TF-IEP002
Study guide: https://hyunhp.github.io/cert-bank/study.html#exam=TF-IEP002
These are original practice questions, not real exam questions, and cert-bank is not affiliated with any certification vendor.
Original practice questions written for this blog, not exam dumps.
Comments
Post a Comment