HashiCorp Terraform Associate 004 Practice Test 4
Question 30
While diagnosing a Terraform state or import issue in a staging workspace, the following condition occurs: A debugging session needs the stored attributes of module.network.resource_name for one key, but the engineer runs terraform output and finds no corresponding root output. The investigator must avoid unreviewed state writes. Which investigation would most directly establish the reported Terraform failure?
- Inspect terraform state list output for complete resource addresses including count indexes, for_each keys, and module paths.
- Identify the exact resource instance address from terraform state list and inspect it with terraform state show.
- Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data.
- Inspect the resource's provider selection, active credentials and which account owns the remote object.
Explanation
Correct Answer
B:Identify the exact resource instance address from terraform state list and inspect it with terraform state show. State inspection commands read tracked resource details; root outputs expose only values explicitly declared for outputs. A justified correction is: Use terraform state show on the selected address to review tracked attributes without changing resources.
Incorrect Answers
A:Inspect terraform state list output for complete resource addresses including count indexes, for_each keys, and module paths. This inspects state list for tracking managed addresses rather than the reported state show inspects one stored resource instance issue. The decisive investigation is: Identify the exact resource instance address from terraform state list and inspect it with terraform state show.
C:Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data. This inspects tf_log for troubleshooting provider and cli diagnostics rather than the reported state show inspects one stored resource instance issue. The decisive investigation is: Identify the exact resource instance address from terraform state list and inspect it with terraform state show.
D:Inspect the resource's provider selection, active credentials and which account owns the remote object. This inspects import source account and provider selection rather than the reported state show inspects one stored resource instance issue. The decisive investigation is: Identify the exact resource instance address from terraform state list and inspect it with terraform state show.
Question 31
During a controlled Terraform CLI recovery exercise, the following condition occurs: A debugging session needs the stored attributes of module.network.resource_name for one key, but the engineer runs terraform output and finds no corresponding root output. The same infrastructure must remain managed without unintended replacements. Which outcome most directly validates the intended fix?
- The reviewer sees the requested resource's stored values while no import, state edit or remote mutation is performed.
- The target restricted log file contains troubleshooting detail without leaving verbose tracing enabled for normal builds.
- The planned refactor covers every tracked instance and does not omit resources merely because source code is abstract.
- The existing object is tracked under the intended resource address and Terraform no longer proposes a duplicate creation.
Explanation
Correct Answer
A:The reviewer sees the requested resource's stored values while no import, state edit or remote mutation is performed. State inspection commands read tracked resource details; root outputs expose only values explicitly declared for outputs. It tests the correction: Use terraform state show on the selected address to review tracked attributes without changing resources.
Incorrect Answers
B:The target restricted log file contains troubleshooting detail without leaving verbose tracing enabled for normal builds. This might validate tf_log_path requires enabled logging, but it does not prove that state show inspects one stored resource instance was resolved. Confirm instead: The reviewer sees the requested resource's stored values while no import, state edit or remote mutation is performed.
C:The planned refactor covers every tracked instance and does not omit resources merely because source code is abstract. This might validate state list for tracking managed addresses, but it does not prove that state show inspects one stored resource instance was resolved. Confirm instead: The reviewer sees the requested resource's stored values while no import, state edit or remote mutation is performed.
D:The existing object is tracked under the intended resource address and Terraform no longer proposes a duplicate creation. This might validate terraform import binds preexisting remote object, but it does not prove that state show inspects one stored resource instance was resolved. Confirm instead: The reviewer sees the requested resource's stored values while no import, state edit or remote mutation is performed.
Question 32
During a separate-region Terraform rollout in an approved staging account, the following condition occurs: An engineer embeds cloud credentials inside required_providers and expects Terraform to authenticate because the source and version were specified there. The configuration should behave consistently without broadening access. Which Terraform configuration or workflow change most directly corrects the described issue?
- Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials.
- Use a justified upper-bound or compatible-release constraint such as ~> 5.0 and test upgrades before committing them.
- Install and configure the appropriate provider through terraform init so Terraform can use its resource and data source implementations.
- Use resource references and output values so computed identifiers resolve after creation rather than hardcoding an invented ID.
Explanation
Correct Answer
A:Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials. Plugin installation requirements and runtime provider configuration are different parts of Terraform's execution model. Confirm the cause with: Review provider requirement declarations, provider configuration blocks, and the platform's supported authentication mechanisms. A concrete acceptance test is: Initialization installs the intended plugin and authenticated operations use the proper provider configuration without credentials in version declarations.
Incorrect Answers
B:Use a justified upper-bound or compatible-release constraint such as ~> 5.0 and test upgrades before committing them. This could address provider version range semantics, but it does not correct the indicated provider block credentials versus required_providers mechanism. The relevant fix is: Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials.
C:Install and configure the appropriate provider through terraform init so Terraform can use its resource and data source implementations. This could address provider plugin manages api resources and data reads, but it does not correct the indicated provider block credentials versus required_providers mechanism. The relevant fix is: Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials.
D:Use resource references and output values so computed identifiers resolve after creation rather than hardcoding an invented ID. This could address resource attribute outputs supplied by state, but it does not correct the indicated provider block credentials versus required_providers mechanism. The relevant fix is: Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials.
Question 33
As an infrastructure team integrates an existing repository with HCP Terraform, the following condition occurs: An HCP Terraform organization gives all users organization-wide apply privileges for convenience, despite only a small release team needing production access. The workflow must apply least privilege and preserve workspace isolation. Which outcome most directly validates the intended fix?
- A noncompliant plan is rejected at policy evaluation while a compliant plan continues through its required approvals.
- A shared setting update reaches exactly the approved workspaces while unrelated projects retain independent configuration.
- Teams locate and administer their approved workspaces without accidentally gaining access to unrelated project state.
- Contributors can collaborate on plans while unauthorized accounts cannot approve or apply production infrastructure changes.
Explanation
Correct Answer
D:Contributors can collaborate on plans while unauthorized accounts cannot approve or apply production infrastructure changes. Workspace team permissions separate collaboration from privileged operations and support auditable Terraform governance. It tests the correction: Grant scoped team access with read or plan permissions as appropriate, reserving apply and administration for authorized groups.
Incorrect Answers
A:A noncompliant plan is rejected at policy evaluation while a compliant plan continues through its required approvals. This might validate hcp terraform policy enforcement governance, but it does not prove that hcp terraform team permissions and audit trail was resolved. Confirm instead: Contributors can collaborate on plans while unauthorized accounts cannot approve or apply production infrastructure changes.
B:A shared setting update reaches exactly the approved workspaces while unrelated projects retain independent configuration. This might validate hcp workspace variable sets share scoped configuration, but it does not prove that hcp terraform team permissions and audit trail was resolved. Confirm instead: Contributors can collaborate on plans while unauthorized accounts cannot approve or apply production infrastructure changes.
C:Teams locate and administer their approved workspaces without accidentally gaining access to unrelated project state. This might validate hcp projects group workspaces by ownership, but it does not prove that hcp terraform team permissions and audit trail was resolved. Confirm instead: Contributors can collaborate on plans while unauthorized accounts cannot approve or apply production infrastructure changes.
Question 34
In a clean CI runner initializing a Terraform root configuration, the following condition occurs: An inherited Terraform configuration references a provider without declaring its registry source, so a team cannot reliably establish which plugin will manage resources. The engineers must keep provider choices and identities reproducible. What should the engineer inspect FIRST to distinguish this issue from unrelated failures?
- Inspect the resource type prefixes and required_providers source mappings before running terraform init.
- Examine required_providers version constraints and the selected version recorded in the dependency lock file.
- Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
- Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions.
Explanation
Correct Answer
C:Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. The required_providers mapping identifies the plugin source and compatibility constraint, separate from provider authentication settings. A justified correction is: Declare the provider's correct registry source and compatible version constraint in required_providers, then initialize again.
Incorrect Answers
A:Inspect the resource type prefixes and required_providers source mappings before running terraform init. This inspects provider plugin manages api resources and data reads rather than the reported provider source requirement declaration issue. The decisive investigation is: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
B:Examine required_providers version constraints and the selected version recorded in the dependency lock file. This inspects provider version range semantics rather than the reported provider source requirement declaration issue. The decisive investigation is: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
D:Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions. This inspects provider authorization versus installation failure rather than the reported provider source requirement declaration issue. The decisive investigation is: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
Question 35
In a clean CI runner initializing a Terraform root configuration, the following condition occurs: Two engineers initialize the same project at different times and unexpectedly use different provider binaries after compatible new releases appear. The engineers must keep provider choices and identities reproducible. Which diagnostic check provides the strongest evidence for the underlying problem?
- Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions.
- Compare .terraform.lock.hcl checksums and selected versions against required_providers constraints and provider init logs.
- Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
- Inspect the resource type prefixes and required_providers source mappings before running terraform init.
Explanation
Correct Answer
B:Compare.terraform.lock.hcl checksums and selected versions against required_providers constraints and provider init logs. Version constraints define acceptable releases; the dependency lock file records concrete chosen provider selections and checksums. A justified correction is: Commit the dependency lock file for a root configuration and use ordinary terraform init to honor its selected provider versions.
Incorrect Answers
A:Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions. This inspects provider authorization versus installation failure rather than the reported dependency lock file reproducible selection issue. The decisive investigation is: Compare.terraform.lock.hcl checksums and selected versions against required_providers constraints and provider init logs.
C:Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. This inspects provider source requirement declaration rather than the reported dependency lock file reproducible selection issue. The decisive investigation is: Compare.terraform.lock.hcl checksums and selected versions against required_providers constraints and provider init logs.
D:Inspect the resource type prefixes and required_providers source mappings before running terraform init. This inspects provider plugin manages api resources and data reads rather than the reported dependency lock file reproducible selection issue. The decisive investigation is: Compare.terraform.lock.hcl checksums and selected versions against required_providers constraints and provider init logs.
Question 36
During a controlled Terraform CLI recovery exercise, the following condition occurs: Terraform init fails sporadically with a provider connectivity error, but its normal CLI output lacks sufficient context for investigating the failed request. The same infrastructure must remain managed without unintended replacements. Which TWO complementary choices identify the cause and implement the appropriate fix? Select TWO.
- Temporarily set TF_LOG to a useful level such as DEBUG or TRACE and capture restricted diagnostic output for the failing command.
- Inspect terraform state list output for complete resource addresses including count indexes, for_each keys, and module paths.
- Set TF_LOG to the intended log level together with TF_LOG_PATH and rerun the failing Terraform command.
- Select the appropriate aliased provider configuration and import using the real identifier in its owning account.
- Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data.
Explanation
Correct Answers
A:Temporarily set TF_LOG to a useful level such as DEBUG or TRACE and capture restricted diagnostic output for the failing command. Terraform logging through TF_LOG adds CLI/provider diagnostics; verbose traces may include sensitive operational information. Confirm the cause with: Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data. A concrete acceptance test is: The logs identify the failing initialization or provider interaction and can be disabled after troubleshooting. This forms one element of the required two-step diagnosis and correction.
E:Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data. Terraform logging through TF_LOG adds CLI/provider diagnostics; verbose traces may include sensitive operational information. A justified correction is: Temporarily set TF_LOG to a useful level such as DEBUG or TRACE and capture restricted diagnostic output for the failing command. This forms one element of the required two-step diagnosis and correction.
Incorrect Answers
B:Inspect terraform state list output for complete resource addresses including count indexes, for_each keys, and module paths. This relates to state list for tracking managed addresses rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data. Then change: Temporarily set TF_LOG to a useful level such as DEBUG or TRACE and capture restricted diagnostic output for the failing command.
C:Set TF_LOG to the intended log level together with TF_LOG_PATH and rerun the failing Terraform command. This relates to tf_log_path requires enabled logging rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data. Then change: Temporarily set TF_LOG to a useful level such as DEBUG or TRACE and capture restricted diagnostic output for the failing command.
D:Select the appropriate aliased provider configuration and import using the real identifier in its owning account. This relates to import source account and provider selection rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the failure mode and select an appropriate TF_LOG verbosity level while protecting credential-bearing log data. Then change: Temporarily set TF_LOG to a useful level such as DEBUG or TRACE and capture restricted diagnostic output for the failing command.
Question 37
In a clean CI runner initializing a Terraform root configuration, the following condition occurs: A fresh Terraform initialization succeeds, but planning an external service resource fails with an access-denied response and the team tries reinstalling the plugin. The engineers must keep provider choices and identities reproducible. Which outcome most directly validates the intended fix?
- Terraform can plan supported target API operations through the selected provider plugin and reports schema errors when arguments are invalid.
- The same initialized provider can read the required resource metadata using an approved identity and the access-denied error disappears.
- Routine initialization stays within the intended major version while explicit change review governs the next major update.
- Terraform resolves the intended plugin source consistently instead of relying on historical default namespace guesses.
Explanation
Correct Answer
B:The same initialized provider can read the required resource metadata using an approved identity and the access-denied error disappears. Successful installation proves a plugin is present, not that the provider identity has permission to operate its remote API. It tests the correction: Correct the provider's supported credentials or least-privilege permissions without changing a successfully installed plugin.
Incorrect Answers
A:Terraform can plan supported target API operations through the selected provider plugin and reports schema errors when arguments are invalid. This might validate provider plugin manages api resources and data reads, but it does not prove that provider authorization versus installation failure was resolved. Confirm instead: The same initialized provider can read the required resource metadata using an approved identity and the access-denied error disappears.
C:Routine initialization stays within the intended major version while explicit change review governs the next major update. This might validate provider version range semantics, but it does not prove that provider authorization versus installation failure was resolved. Confirm instead: The same initialized provider can read the required resource metadata using an approved identity and the access-denied error disappears.
D:Terraform resolves the intended plugin source consistently instead of relying on historical default namespace guesses. This might validate provider source requirement declaration, but it does not prove that provider authorization versus installation failure was resolved. Confirm instead: The same initialized provider can read the required resource metadata using an approved identity and the access-denied error disappears.
Question 38
During a controlled module integration test for a production Terraform stack, the following condition occurs: A compliance controller adds a standard cost tag after provisioning and each Terraform plan tries to revert the independently managed tag. The desired fix must avoid unrelated resource changes. What acceptance evidence best establishes that the Terraform issue has been resolved?
- The plan orders the policy attachment before the application service, and the service no longer races its prerequisite.
- The plan resolves the intended instance and avoids accidental replacement caused solely by a configuration address rename.
- The plan records the authorized region value, and a second run produces the same selection under the same variable inputs.
- Normal plans do not oscillate the delegated tag, while other resource drift remains visible and managed.
Explanation
Correct Answer
D:Normal plans do not oscillate the delegated tag, while other resource drift remains visible and managed. ignore_changes omits configured attribute differences from update decisions and should not be a blanket excuse to hide drift. It tests the correction: Use a narrowly scoped lifecycle ignore_changes list for that attribute only when its ownership has been formally delegated.
Incorrect Answers
A:The plan orders the policy attachment before the application service, and the service no longer races its prerequisite. This might validate explicit depends_on for behavior-only dependencies, but it does not prove that ignore_changes ownership of externally managed tag was resolved. Confirm instead: Normal plans do not oscillate the delegated tag, while other resource drift remains visible and managed.
B:The plan resolves the intended instance and avoids accidental replacement caused solely by a configuration address rename. This might validate resource addressing with repeated instances, but it does not prove that ignore_changes ownership of externally managed tag was resolved. Confirm instead: Normal plans do not oscillate the delegated tag, while other resource drift remains visible and managed.
C:The plan records the authorized region value, and a second run produces the same selection under the same variable inputs. This might validate variable input precedence and configuration injection, but it does not prove that ignore_changes ownership of externally managed tag was resolved. Confirm instead: Normal plans do not oscillate the delegated tag, while other resource drift remains visible and managed.
Question 39
When maintaining Terraform modules used by several application teams, the following condition occurs: A root module duplicates nearly identical module blocks for every application name, causing the staging and QA copies to diverge in their configurations. The module interface must remain stable and reviewable. What acceptance evidence best establishes that the Terraform issue has been resolved?
- Web resources use the subnet created in the same reviewed configuration and maintain a graph dependency on it.
- The root plan resolves the new module output names with no dangling references or unintended replacements.
- The child module receives the intended environment value without accessing variables declared only in its caller.
- New applications gain consistent module behavior and removing one key does not renumber unrelated module instances.
Explanation
Correct Answer
D:New applications gain consistent module behavior and removing one key does not renumber unrelated module instances. Module calls support for_each to create keyed instances of reusable infrastructure components with stable addresses. It tests the correction: Use for_each on the module block with a stable keyed collection and pass each.key or each.value to the child input contract.
Incorrect Answers
A:Web resources use the subnet created in the same reviewed configuration and maintain a graph dependency on it. This might validate module outputs coordinate dependencies instead of duplicate data, but it does not prove that for_each at module call for multiple environments was resolved. Confirm instead: New applications gain consistent module behavior and removing one key does not renumber unrelated module instances.
B:The root plan resolves the new module output names with no dangling references or unintended replacements. This might validate module upgrade plan review with changed outputs, but it does not prove that for_each at module call for multiple environments was resolved. Confirm instead: New applications gain consistent module behavior and removing one key does not renumber unrelated module instances.
C:The child module receives the intended environment value without accessing variables declared only in its caller. This might validate root and child variable scope isolation, but it does not prove that for_each at module call for multiple environments was resolved. Confirm instead: New applications gain consistent module behavior and removing one key does not renumber unrelated module instances.
Question 40
When reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A Terraform configuration changes a resource to for_each and a team still refers to the unkeyed address, causing an invalid reference or planned replacement. The engineer must respect declared resource contracts and data security boundaries. What targeted engineering response should the team implement?
- Use a provider-supported data block to look up the existing zone and reserve resource declarations for objects this state should manage.
- Use a lifecycle precondition with a precise boolean condition and actionable error message on the resource.
- Use suitable Terraform string functions such as lower, trimspace, and format to normalize the intended names consistently.
- Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.
Explanation
Correct Answer
D:Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring. Repeated resources have instance addresses that include their keys or indexes, rather than a single unqualified instance address. Confirm the cause with: Inspect the declared for_each keys, current state addresses, and references elsewhere in the configuration. A concrete acceptance test is: The plan resolves the intended instance and avoids accidental replacement caused solely by a configuration address rename. This matters here because when reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A Terraform….
Incorrect Answers
A:Use a provider-supported data block to look up the existing zone and reserve resource declarations for objects this state should manage. This could address data source versus managed resource definition, but it does not correct the indicated resource addressing with repeated instances mechanism. The relevant fix is: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring. This matters here because when reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A Terraform….
B:Use a lifecycle precondition with a precise boolean condition and actionable error message on the resource. This could address resource precondition for unsafe configuration, but it does not correct the indicated resource addressing with repeated instances mechanism. The relevant fix is: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.
C:Use suitable Terraform string functions such as lower, trimspace, and format to normalize the intended names consistently. This could address built-in functions for deterministic naming, but it does not correct the indicated resource addressing with repeated instances mechanism. The relevant fix is: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.