HashiCorp Terraform Associate 004 Practice Test 34
Question 330
During an isolated staging rehearsal of the Terraform workflow, the following condition occurs: A repository is cloned into a new runner, and terraform plan fails before generating changes because the workspace has not initialized provider plugins or its backend. The operator must obtain auditable evidence before touching production resources. Which proposed remediation solves this failure without masking its cause?
- Run terraform init to install and configure referenced child modules before attempting configuration validation.
- Run terraform fmt or terraform fmt -recursive where intended, then review the resulting source formatting changes.
- Use the normal full dependency-aware plan and apply workflow; reserve targeting for exceptional recovery rather than routine deployment.
- Execute terraform init in the root configuration directory and resolve backend or provider setup failures before planning.
Explanation
Correct Answer
D:Execute terraform init in the root configuration directory and resolve backend or provider setup failures before planning. The init command prepares backend configuration and downloads needed providers/modules; it does not create managed resources by itself. Confirm the cause with: Inspect the.terraform working directory and initialization output for missing backend, module, and provider setup. A concrete acceptance test is: The runner completes initialization and can calculate a plan using the intended backend and installed dependencies.
Incorrect Answers
A:Run terraform init to install and configure referenced child modules before attempting configuration validation. This could address module installation during initial setup, but it does not correct the indicated terraform init backend and provider preparation mechanism. The relevant fix is: Execute terraform init in the root configuration directory and resolve backend or provider setup failures before planning.
B:Run terraform fmt or terraform fmt -recursive where intended, then review the resulting source formatting changes. This could address terraform fmt normalizes hcl style, but it does not correct the indicated terraform init backend and provider preparation mechanism. The relevant fix is: Execute terraform init in the root configuration directory and resolve backend or provider setup failures before planning.
C:Use the normal full dependency-aware plan and apply workflow; reserve targeting for exceptional recovery rather than routine deployment. This could address targeted apply limitations for normal changes, but it does not correct the indicated terraform init backend and provider preparation mechanism. The relevant fix is: Execute terraform init in the root configuration directory and resolve backend or provider setup failures before planning.
Question 331
When maintaining Terraform modules used by several application teams, the following condition occurs: A monorepo contains many Terraform modules, but a root module downloads the entire Git repository as though its desired network child module lives at repository root. The module interface must remain stable and reviewable. What acceptance evidence best establishes that the Terraform issue has been resolved?
- All six consumers obtain the reviewed shared security behavior while preserving intentional per-application parameters.
- The child module files are located consistently by local and CI runs without copying the same definitions into the root.
- Two clean deployments retrieve the same module code revision and avoid unnoticed drift from default-branch updates.
- Initialization selects the network module code from the intended repository path and revision rather than unrelated root files.
Explanation
Correct Answer
D:Initialization selects the network module code from the intended repository path and revision rather than unrelated root files. Terraform module source addresses can include a package subdirectory; the path after double slash identifies the module inside it. It tests the correction: Use the supported Git module source form with the correct double-slash subdirectory and pinned revision ref.
Incorrect Answers
A:All six consumers obtain the reviewed shared security behavior while preserving intentional per-application parameters. This might validate module blocks reuse standard infrastructure patterns, but it does not prove that git module source with explicit subdirectory was resolved. Confirm instead: Initialization selects the network module code from the intended repository path and revision rather than unrelated root files.
B:The child module files are located consistently by local and CI runs without copying the same definitions into the root. This might validate local child module source path resolution, but it does not prove that git module source with explicit subdirectory was resolved. Confirm instead: Initialization selects the network module code from the intended repository path and revision rather than unrelated root files.
C:Two clean deployments retrieve the same module code revision and avoid unnoticed drift from default-branch updates. This might validate git module ref pin rather than floating main branch, but it does not prove that git module source with explicit subdirectory was resolved. Confirm instead: Initialization selects the network module code from the intended repository path and revision rather than unrelated root files.
Question 332
As a second engineer rehearses an infrastructure state migration, the following condition occurs: A network rule is modified directly in a cloud console and a subsequent Terraform plan proposes reverting it although the Terraform files are unchanged. The operation must not delete or duplicate existing production objects. Which TWO options together provide the relevant diagnosis and its targeted remediation? Select TWO.
- Compare the refreshed real object with its prior state and declared configuration to identify an outside change.
- Select a backend with supported state-locking capabilities and configure its required access controls appropriately.
- Apply a reviewed refresh-only plan when appropriate to synchronize state with current remote objects without an infrastructure change.
- Inspect active runs and lock metadata to determine whether another legitimate operation owns the state lock.
- Review whether to restore desired IaC attributes or update configuration deliberately to adopt the observed change.
Explanation
Correct Answers
A:Compare the refreshed real object with its prior state and declared configuration to identify an outside change. Terraform can detect remote drift during refresh and propose changes back to declared configuration rather than treating console edits as code. A justified correction is: Review whether to restore desired IaC attributes or update configuration deliberately to adopt the observed change. This forms one element of the required two-step diagnosis and correction.
E:Review whether to restore desired IaC attributes or update configuration deliberately to adopt the observed change. Terraform can detect remote drift during refresh and propose changes back to declared configuration rather than treating console edits as code. Confirm the cause with: Compare the refreshed real object with its prior state and declared configuration to identify an outside change. A concrete acceptance test is: The approved reconciliation returns to a stable plan and makes the handling of the external modification explicit. This forms one element of the required two-step diagnosis and correction.
Incorrect Answers
B:Select a backend with supported state-locking capabilities and configure its required access controls appropriately. This relates to backend-specific state locking support rather than the matching diagnosis-and-remediation pair required here. Check: Compare the refreshed real object with its prior state and declared configuration to identify an outside change. Then change: Review whether to restore desired IaC attributes or update configuration deliberately to adopt the observed change.
C:Apply a reviewed refresh-only plan when appropriate to synchronize state with current remote objects without an infrastructure change. This relates to refresh-only state update without infrastructure mutation rather than the matching diagnosis-and-remediation pair required here. Check: Compare the refreshed real object with its prior state and declared configuration to identify an outside change. Then change: Review whether to restore desired IaC attributes or update configuration deliberately to adopt the observed change.
D:Inspect active runs and lock metadata to determine whether another legitimate operation owns the state lock. This relates to state locking prevents concurrent writes rather than the matching diagnosis-and-remediation pair required here. Check: Compare the refreshed real object with its prior state and declared configuration to identify an outside change. Then change: Review whether to restore desired IaC attributes or update configuration deliberately to adopt the observed change.
Question 333
As a second engineer rehearses an infrastructure state migration, the following condition occurs: A Terraform engineer moves a resource from root to a child module and the next plan offers to destroy the old address and create the same remote object at a new address. The operation must not delete or duplicate existing production objects. What acceptance evidence best establishes that the Terraform issue has been resolved?
- Remote state access succeeds without exposing persistent access keys in the repository, saved plan, or shared logs.
- Initialization connects to the intended workspace without conflicting backend configurations or unintended state copies.
- The resource identity is preserved through a state address move and the refactor avoids unnecessary physical replacement.
- The approved reconciliation returns to a stable plan and makes the handling of the external modification explicit.
Explanation
Correct Answer
C:The resource identity is preserved through a state address move and the refactor avoids unnecessary physical replacement. Configuration address refactoring requires a state mapping; moved blocks declare that logical migration without recreating infrastructure. It tests the correction: Add a moved block mapping the old address to the new address before running a reviewed plan.
Incorrect Answers
A:Remote state access succeeds without exposing persistent access keys in the repository, saved plan, or shared logs. This might validate backend credentials kept out of plan artifacts, but it does not prove that moved block preserves state during address refactor was resolved. Confirm instead: The resource identity is preserved through a state address move and the refactor avoids unnecessary physical replacement.
B:Initialization connects to the intended workspace without conflicting backend configurations or unintended state copies. This might validate hcp cloud integration versus remote backend, but it does not prove that moved block preserves state during address refactor was resolved. Confirm instead: The resource identity is preserved through a state address move and the refactor avoids unnecessary physical replacement.
D:The approved reconciliation returns to a stable plan and makes the handling of the external modification explicit. This might validate out-of-band drift detection in managed resource, but it does not prove that moved block preserves state during address refactor was resolved. Confirm instead: The resource identity is preserved through a state address move and the refactor avoids unnecessary physical replacement.
Question 334
When reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A server requires a network subnet that Terraform creates in the same plan, but the author hardcodes the expected subnet name and gets an ordering error. The engineer must respect declared resource contracts and data security boundaries. Which Terraform configuration or workflow change most directly corrects the described issue?
- Declare the token input as ephemeral = true and pass it only into compatible runtime contexts such as provider configuration.
- Use the managed subnet resource's appropriate output attribute directly in the server configuration.
- Add an explicit depends_on reference to the necessary policy attachment where an ordinary attribute reference cannot express the relationship.
- Expose the required network identifier with an output in the child module and reference module.network.<output_name> from the root.
Explanation
Correct Answer
B:Use the managed subnet resource's appropriate output attribute directly in the server configuration. A reference to another resource attribute establishes an implicit graph dependency and avoids fragile guessed identifiers. Confirm the cause with: Inspect the subnet and server blocks for real attribute references versus unrelated hardcoded strings. A concrete acceptance test is: Terraform builds the dependency edge and provisions the subnet before the dependent server without manual delays. This matters here because when reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A server….
Incorrect Answers
A:Declare the token input as ephemeral = true and pass it only into compatible runtime contexts such as provider configuration. This could address ephemeral variable for short-lived token in terraform 1.12, but it does not correct the indicated implicit dependency through resource attribute reference mechanism. The relevant fix is: Use the managed subnet resource's appropriate output attribute directly in the server configuration. This matters here because when reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A server….
C:Add an explicit depends_on reference to the necessary policy attachment where an ordinary attribute reference cannot express the relationship. This could address explicit depends_on for behavior-only dependencies, but it does not correct the indicated implicit dependency through resource attribute reference mechanism. The relevant fix is: Use the managed subnet resource's appropriate output attribute directly in the server configuration.
D:Expose the required network identifier with an output in the child module and reference module.network.<output_name> from the root. This could address module output references across composition, but it does not correct the indicated implicit dependency through resource attribute reference mechanism. The relevant fix is: Use the managed subnet resource's appropriate output attribute directly in the server configuration.
Question 335
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. What should the engineer inspect FIRST to distinguish this issue from unrelated failures?
- Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions.
- Examine required_providers version constraints and the selected version recorded in the dependency lock file.
- Inspect the version constraint, lock file version, and the difference between ordinary terraform init and terraform init -upgrade behavior.
- Review provider requirement declarations, provider configuration blocks, and the platform's supported authentication mechanisms.
Explanation
Correct Answer
A:Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions. Successful installation proves a plugin is present, not that the provider identity has permission to operate its remote API. A justified correction is: Correct the provider's supported credentials or least-privilege permissions without changing a successfully installed plugin.
Incorrect Answers
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 authorization versus installation failure issue. The decisive investigation is: Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions.
C:Inspect the version constraint, lock file version, and the difference between ordinary terraform init and terraform init -upgrade behavior. This inspects controlled provider upgrade using init upgrade rather than the reported provider authorization versus installation failure issue. The decisive investigation is: Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions.
D:Review provider requirement declarations, provider configuration blocks, and the platform's supported authentication mechanisms. This inspects provider block credentials versus required_providers rather than the reported provider authorization versus installation failure issue. The decisive investigation is: Separate plugin resolution logs from runtime API authorization errors and inspect the provider's active identity and scoped permissions.
Question 336
When maintaining Terraform modules used by several application teams, the following condition occurs: An engineer references a public registry module using a Git URL but also supplies a registry version argument and expects Terraform to resolve it as a registry source. The module interface must remain stable and reviewable. What targeted engineering response should the team implement?
- Set the source to an accurate local relative module path and initialize or validate from the correct root directory.
- Use a valid registry module address when controlling versions with the module version argument, or pin an appropriate Git ref in a VCS source URL.
- Pass sensitive inputs through appropriately typed child variables and avoid exposing them via normal outputs or logs.
- Add an appropriate version constraint for a registry module and review upgrades with plans and compatibility tests.
Explanation
Correct Answer
B:Use a valid registry module address when controlling versions with the module version argument, or pin an appropriate Git ref in a VCS source URL. Registry sources support the version argument; a Git source generally selects its revision through its source query ref. Confirm the cause with: Inspect the module source syntax and whether the source is a registry address or a generic VCS URL. A concrete acceptance test is: Terraform fetches the intended module revision without mixing registry-only and Git source selection semantics.
Incorrect Answers
A:Set the source to an accurate local relative module path and initialize or validate from the correct root directory. This could address local child module source path resolution, but it does not correct the indicated registry module source naming contract mechanism. The relevant fix is: Use a valid registry module address when controlling versions with the module version argument, or pin an appropriate Git ref in a VCS source URL.
C:Pass sensitive inputs through appropriately typed child variables and avoid exposing them via normal outputs or logs. This could address sensitive input forwarding between nested modules, but it does not correct the indicated registry module source naming contract mechanism. The relevant fix is: Use a valid registry module address when controlling versions with the module version argument, or pin an appropriate Git ref in a VCS source URL.
D:Add an appropriate version constraint for a registry module and review upgrades with plans and compatibility tests. This could address registry module version pin to avoid breaking releases, but it does not correct the indicated registry module source naming contract mechanism. The relevant fix is: Use a valid registry module address when controlling versions with the module version argument, or pin an appropriate Git ref in a VCS source URL.
Question 337
During a clean initialization of a newly composed infrastructure root module, the following condition occurs: A root Terraform configuration calls a child module with a relative source path that points to a nonexistent sibling directory on the CI runner. The team must preserve reproducibility across callers. What should the engineer inspect FIRST to distinguish this issue from unrelated failures?
- Check the module source address, allowed version range and current module selections from initialization.
- Inspect the module source value and the repository layout relative to the directory containing the calling module.
- Inspect the parent composition and whether the network child provides an output representing the created subnet.
- Inspect the module source syntax and whether the source is a registry address or a generic VCS URL.
Explanation
Correct Answer
B:Inspect the module source value and the repository layout relative to the directory containing the calling module. Local module sources are paths resolved relative to the calling module; incorrect layout cannot be repaired by provider credentials. A justified correction is: Set the source to an accurate local relative module path and initialize or validate from the correct root directory.
Incorrect Answers
A:Check the module source address, allowed version range and current module selections from initialization. This inspects registry module version pin to avoid breaking releases rather than the reported local child module source path resolution issue. The decisive investigation is: Inspect the module source value and the repository layout relative to the directory containing the calling module.
C:Inspect the parent composition and whether the network child provides an output representing the created subnet. This inspects module outputs coordinate dependencies instead of duplicate data rather than the reported local child module source path resolution issue. The decisive investigation is: Inspect the module source value and the repository layout relative to the directory containing the calling module.
D:Inspect the module source syntax and whether the source is a registry address or a generic VCS URL. This inspects registry module source naming contract rather than the reported local child module source path resolution issue. The decisive investigation is: Inspect the module source value and the repository layout relative to the directory containing the calling module.
Question 338
As the deployment team prepares a reviewed Terraform CLI change, the following condition occurs: A root module adds a new remote child module source, but terraform validate reports it cannot find the child module in the local working directory. The change must preserve the distinction between previewing and modifying infrastructure. What measurable postchange observation would confirm that the correction worked?
- The working directory uses the approved remote backend and the existing managed resource bindings remain available without duplicate provisioning.
- The state no longer tracks the bucket and verification confirms the remote bucket and data still exist.
- The apply executes the selected reviewed plan instead of silently producing a new unreviewed plan from changed inputs.
- The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory.
Explanation
Correct Answer
D:The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory. Terraform initialization installs external module dependencies while validation assumes required module code is locally available. It tests the correction: Run terraform init to install and configure referenced child modules before attempting configuration validation.
Incorrect Answers
A:The working directory uses the approved remote backend and the existing managed resource bindings remain available without duplicate provisioning. This might validate reinitializing after backend configuration change, but it does not prove that module installation during initial setup was resolved. Confirm instead: The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory.
B:The state no longer tracks the bucket and verification confirms the remote bucket and data still exist. This might validate selective cleanup without destroying retained object, but it does not prove that module installation during initial setup was resolved. Confirm instead: The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory.
C:The apply executes the selected reviewed plan instead of silently producing a new unreviewed plan from changed inputs. This might validate saved execution plan for controlled deployment, but it does not prove that module installation during initial setup was resolved. Confirm instead: The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory.
Question 339
During a governed HCP Terraform workspace rollout, the following condition occurs: A developer has valid cloud-provider credentials but terraform plan cannot access a private HCP Terraform workspace because the Terraform CLI is unauthenticated to the HCP organization. The organization must retain auditable authorization for runs and state. 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.
- The CLI can access the authorized workspace while provider API access remains governed by separate scoped identities.
- The CLI plan targets the selected HCP Terraform workspace and uses its controlled state rather than a local accidental snapshot.
- A shared setting update reaches exactly the approved workspaces while unrelated projects retain independent configuration.
Explanation
Correct Answer
B:The CLI can access the authorized workspace while provider API access remains governed by separate scoped identities. HCP workspace authentication and cloud provider authentication protect different services and cannot substitute for each other. It tests the correction: Authenticate to HCP Terraform using a supported CLI login or secure token workflow and retain least-privilege provider credentials independently.
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 cli login and execution credentials was resolved. Confirm instead: The CLI can access the authorized workspace while provider API access remains governed by separate scoped identities.
C:The CLI plan targets the selected HCP Terraform workspace and uses its controlled state rather than a local accidental snapshot. This might validate terraform cloud block hcp workspace integration, but it does not prove that hcp terraform cli login and execution credentials was resolved. Confirm instead: The CLI can access the authorized workspace while provider API access remains governed by separate scoped identities.
D: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 cli login and execution credentials was resolved. Confirm instead: The CLI can access the authorized workspace while provider API access remains governed by separate scoped identities.
Question 340
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. Select TWO: the decisive first check and the change that directly addresses the problem.
- Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.
- Check the for_each keys and the collection shape of the declared resource instances.
- Use a provider-supported data block to look up the existing zone and reserve resource declarations for objects this state should manage.
- Inspect the declared for_each keys, current state addresses, and references elsewhere in the configuration.
- Use a narrowly scoped lifecycle ignore_changes list for that attribute only when its ownership has been formally delegated.
Explanation
Correct Answers
A: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 forms one element of the required two-step diagnosis and correction.
D:Inspect the declared for_each keys, current state addresses, and references elsewhere in the configuration. Repeated resources have instance addresses that include their keys or indexes, rather than a single unqualified instance address. A justified correction is: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring. This forms one element of the required two-step diagnosis and correction.
Incorrect Answers
B:Check the for_each keys and the collection shape of the declared resource instances. This relates to collection references for for_each resources rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the declared for_each keys, current state addresses, and references elsewhere in the configuration. Then change: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.
C:Use a provider-supported data block to look up the existing zone and reserve resource declarations for objects this state should manage. This relates to data source versus managed resource definition rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the declared for_each keys, current state addresses, and references elsewhere in the configuration. Then change: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.
E:Use a narrowly scoped lifecycle ignore_changes list for that attribute only when its ownership has been formally delegated. This relates to ignore_changes ownership of externally managed tag rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the declared for_each keys, current state addresses, and references elsewhere in the configuration. Then change: Reference the correct keyed resource instance or use a reviewed moved block to preserve its existing state identity during refactoring.