HashiCorp Terraform Associate 004 Practice Test 3
Question 20
During a clean initialization of a newly composed infrastructure root module, the following condition occurs: A Git-sourced security module pulls the latest default branch on every clean initialization, producing inconsistent firewall rules across deployment dates. The team must preserve reproducibility across callers. Which TWO complementary choices identify the cause and implement the appropriate fix? Select TWO.
- Add the intended child output declaration and access it through module.network.<output_name> in the caller.
- Inspect the parent composition and whether the network child provides an output representing the created subnet.
- Update the module version together with dependent output references and validate the full root configuration before applying.
- Pin the Git module source to a reviewed immutable commit or controlled tag and update it through an explicit change review.
- Inspect the module Git source URL and whether it contains a commit, tag or versioned ref rather than an unpinned branch.
Explanation
Correct Answers
D:Pin the Git module source to a reviewed immutable commit or controlled tag and update it through an explicit change review. VCS module source versions are controlled by source refs rather than by Terraform registry module version constraints. Confirm the cause with: Inspect the module Git source URL and whether it contains a commit, tag or versioned ref rather than an unpinned branch. A concrete acceptance test is: Two clean deployments retrieve the same module code revision and avoid unnoticed drift from default-branch updates. This forms one element of the required two-step diagnosis and correction.
E:Inspect the module Git source URL and whether it contains a commit, tag or versioned ref rather than an unpinned branch. VCS module source versions are controlled by source refs rather than by Terraform registry module version constraints. A justified correction is: Pin the Git module source to a reviewed immutable commit or controlled tag and update it through an explicit change review. This forms one element of the required two-step diagnosis and correction.
Incorrect Answers
A:Add the intended child output declaration and access it through module.network.<output_name> in the caller. This relates to child output exposure to calling module rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the module Git source URL and whether it contains a commit, tag or versioned ref rather than an unpinned branch. Then change: Pin the Git module source to a reviewed immutable commit or controlled tag and update it through an explicit change review.
B:Inspect the parent composition and whether the network child provides an output representing the created subnet. This relates to module outputs coordinate dependencies instead of duplicate data rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the module Git source URL and whether it contains a commit, tag or versioned ref rather than an unpinned branch. Then change: Pin the Git module source to a reviewed immutable commit or controlled tag and update it through an explicit change review.
C:Update the module version together with dependent output references and validate the full root configuration before applying. This relates to module upgrade plan review with changed outputs rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the module Git source URL and whether it contains a commit, tag or versioned ref rather than an unpinned branch. Then change: Pin the Git module source to a reviewed immutable commit or controlled tag and update it through an explicit change review.
Question 21
During a controlled module integration test for a production Terraform stack, the following condition occurs: A list of application names drives count-based resources, and removing one name shifts indices so Terraform plans to replace unrelated applications. The desired fix must avoid unrelated resource changes. Which investigation would most directly establish the reported Terraform failure?
- Inspect state instance addresses and compare count positions against stable business keys.
- Inspect the shared attributes and whether one expression can derive a value from the environment input.
- Inspect the provider resource schema for supported write-only arguments and associated rotation or version requirements.
- Inspect the variable's ephemeral setting and whether downstream use is an allowed ephemeral context such as provider configuration.
Explanation
Correct Answer
A:Inspect state instance addresses and compare count positions against stable business keys. Count identifies instances by numeric position, while for_each keys can preserve stable identity across list ordering changes. A justified correction is: Use for_each over stable unique names and migrate existing addresses with reviewed moved blocks where appropriate.
Incorrect Answers
B:Inspect the shared attributes and whether one expression can derive a value from the environment input. This inspects conditional expressions for environment configuration rather than the reported for_each stable identity instead of count index issue. The decisive investigation is: Inspect state instance addresses and compare count positions against stable business keys.
C:Inspect the provider resource schema for supported write-only arguments and associated rotation or version requirements. This inspects write-only provider argument for managed secret rotation rather than the reported for_each stable identity instead of count index issue. The decisive investigation is: Inspect state instance addresses and compare count positions against stable business keys.
D:Inspect the variable's ephemeral setting and whether downstream use is an allowed ephemeral context such as provider configuration. This inspects ephemeral variable for short-lived token in terraform 1.12 rather than the reported for_each stable identity instead of count index issue. The decisive investigation is: Inspect state instance addresses and compare count positions against stable business keys.
Question 22
When maintaining Terraform modules used by several application teams, the following condition occurs: A child Terraform module refers directly to var.environment declared only in its parent, causing a missing-variable diagnostic. The module interface must remain stable and reviewable. Which Terraform configuration or workflow change most directly corrects the described issue?
- Pass sensitive inputs through appropriately typed child variables and avoid exposing them via normal outputs or logs.
- Declare an input variable in the child module and pass the parent's value explicitly as a module argument.
- Update the module version together with dependent output references and validate the full root configuration before applying.
- Create a reusable child module with a documented input/output contract and call it from each application's root module.
Explanation
Correct Answer
B:Declare an input variable in the child module and pass the parent's value explicitly as a module argument. Input variables are scoped to their modules and must cross a module boundary through an explicit interface. Confirm the cause with: Inspect the child module's variable declarations and the arguments passed by its calling module block. A concrete acceptance test is: The child module receives the intended environment value without accessing variables declared only in its caller.
Incorrect Answers
A: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 root and child variable scope isolation mechanism. The relevant fix is: Declare an input variable in the child module and pass the parent's value explicitly as a module argument.
C:Update the module version together with dependent output references and validate the full root configuration before applying. This could address module upgrade plan review with changed outputs, but it does not correct the indicated root and child variable scope isolation mechanism. The relevant fix is: Declare an input variable in the child module and pass the parent's value explicitly as a module argument.
D:Create a reusable child module with a documented input/output contract and call it from each application's root module. This could address module blocks reuse standard infrastructure patterns, but it does not correct the indicated root and child variable scope isolation mechanism. The relevant fix is: Declare an input variable in the child module and pass the parent's value explicitly as a module argument.
Question 23
When maintaining Terraform modules used by several application teams, the following condition occurs: A child Terraform module refers directly to var.environment declared only in its parent, causing a missing-variable diagnostic. The module interface must remain stable and reviewable. Which investigation would most directly establish the reported Terraform failure?
- Identify common resource groups and the controlled parameters that vary by application team.
- Inspect the child module's variable declarations and the arguments passed by its calling module block.
- Inspect the child module's output blocks and root expressions that refer to module.network values.
- Inspect the module source syntax and whether the source is a registry address or a generic VCS URL.
Explanation
Correct Answer
B:Inspect the child module's variable declarations and the arguments passed by its calling module block. Input variables are scoped to their modules and must cross a module boundary through an explicit interface. A justified correction is: Declare an input variable in the child module and pass the parent's value explicitly as a module argument.
Incorrect Answers
A:Identify common resource groups and the controlled parameters that vary by application team. This inspects module blocks reuse standard infrastructure patterns rather than the reported root and child variable scope isolation issue. The decisive investigation is: Inspect the child module's variable declarations and the arguments passed by its calling module block.
C:Inspect the child module's output blocks and root expressions that refer to module.network values. This inspects child output exposure to calling module rather than the reported root and child variable scope isolation issue. The decisive investigation is: Inspect the child module's variable declarations and the arguments passed by its calling module block.
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 root and child variable scope isolation issue. The decisive investigation is: Inspect the child module's variable declarations and the arguments passed by its calling module block.
Question 24
During a separate-region Terraform rollout in an approved staging account, the following condition occurs: A Terraform project uses the same cloud provider in development and production accounts but a resource unexpectedly lands in the default development account. The configuration should behave consistently without broadening access. Which investigation would most directly establish the reported Terraform failure?
- Inspect provider alias blocks and the resource's provider selection, including default identity and account-specific configuration.
- Compare state resource addresses to actual remote objects and the active backend's selected state snapshot.
- Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
- Inspect provider alias identities, authentication scopes, and which modules or resources select each instance.
Explanation
Correct Answer
A:Inspect provider alias blocks and the resource's provider selection, including default identity and account-specific configuration. A provider alias selects an alternate configured provider instance; resource blocks must reference it to avoid a default-account fallback. A justified correction is: Define explicitly aliased provider configurations and assign the production resource to the intended alias.
Incorrect Answers
B:Compare state resource addresses to actual remote objects and the active backend's selected state snapshot. This inspects state binding between resource address and remote object rather than the reported provider alias for multiple accounts issue. The decisive investigation is: Inspect provider alias blocks and the resource's provider selection, including default identity and account-specific configuration.
C:Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. This inspects provider source requirement declaration rather than the reported provider alias for multiple accounts issue. The decisive investigation is: Inspect provider alias blocks and the resource's provider selection, including default identity and account-specific configuration.
D:Inspect provider alias identities, authentication scopes, and which modules or resources select each instance. This inspects multiple provider instances requiring separate authentication rather than the reported provider alias for multiple accounts issue. The decisive investigation is: Inspect provider alias blocks and the resource's provider selection, including default identity and account-specific configuration.
Question 25
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. Select TWO: the decisive first check and the change that directly addresses the problem.
- Review required_providers declarations, provider source addresses, existing lock entries, and initialization output.
- Commit the dependency lock file for a root configuration and use ordinary terraform init to honor its selected provider versions.
- Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials.
- Declare the provider's correct registry source and compatible version constraint in required_providers, then initialize again.
- Check which resource attributes are computed by the provider and how state records them after successful operations.
Explanation
Correct Answers
A: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. This forms one element of the required two-step diagnosis and correction.
D:Declare the provider's correct registry source and compatible version constraint in required_providers, then initialize again. The required_providers mapping identifies the plugin source and compatibility constraint, separate from provider authentication settings. Confirm the cause with: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. A concrete acceptance test is: Terraform resolves the intended plugin source consistently instead of relying on historical default namespace guesses. This forms one element of the required two-step diagnosis and correction.
Incorrect Answers
B:Commit the dependency lock file for a root configuration and use ordinary terraform init to honor its selected provider versions. This relates to dependency lock file reproducible selection rather than the matching diagnosis-and-remediation pair required here. Check: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. Then change: Declare the provider's correct registry source and compatible version constraint in required_providers, then initialize again.
C:Keep provider source and version in required_providers and configure authentication via supported provider settings or short-lived environment credentials. This relates to provider block credentials versus required_providers rather than the matching diagnosis-and-remediation pair required here. Check: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. Then change: Declare the provider's correct registry source and compatible version constraint in required_providers, then initialize again.
E:Check which resource attributes are computed by the provider and how state records them after successful operations. This relates to resource attribute outputs supplied by state rather than the matching diagnosis-and-remediation pair required here. Check: Review required_providers declarations, provider source addresses, existing lock entries, and initialization output. Then change: Declare the provider's correct registry source and compatible version constraint in required_providers, then initialize again.
Question 26
During a controlled module integration test for a production Terraform stack, the following condition occurs: An operator adds a Terraform check asserting that an HTTP service is healthy and expects a failed check to halt the same apply as a mandatory precondition. The desired fix must avoid unrelated resource changes. Which diagnostic check provides the strongest evidence for the underlying problem?
- Inspect the variable type constraint and the HCL expression used to access its values.
- Inspect variable blocks for type/default arguments and the module call for an explicitly supplied input value.
- Inspect variable input expectations and whether an explicit validation condition can reject invalid strings early.
- Inspect the chosen custom condition mechanism and whether its failure is advisory or blocking for the intended Terraform version.
Explanation
Correct Answer
D:Inspect the chosen custom condition mechanism and whether its failure is advisory or blocking for the intended Terraform version. Check blocks generally issue warnings rather than blocking applies; lifecycle conditions enforce resource pre/post invariants. A justified correction is: Use a resource precondition or postcondition for a hard lifecycle invariant and reserve check blocks for non-blocking validation reports.
Incorrect Answers
A:Inspect the variable type constraint and the HCL expression used to access its values. This inspects map versus list addressing for environment inputs rather than the reported check block observability versus hard failure issue. The decisive investigation is: Inspect the chosen custom condition mechanism and whether its failure is advisory or blocking for the intended Terraform version.
B:Inspect variable blocks for type/default arguments and the module call for an explicitly supplied input value. This inspects variable default versus required input rather than the reported check block observability versus hard failure issue. The decisive investigation is: Inspect the chosen custom condition mechanism and whether its failure is advisory or blocking for the intended Terraform version.
C:Inspect variable input expectations and whether an explicit validation condition can reject invalid strings early. This inspects input variable custom validation rule rather than the reported check block observability versus hard failure issue. The decisive investigation is: Inspect the chosen custom condition mechanism and whether its failure is advisory or blocking for the intended Terraform version.
Question 27
During a controlled module integration test for a production Terraform stack, the following condition occurs: A Terraform module copies a long-lived API token directly into a committed .tf file so an infrastructure deployment can authenticate to an external service. The desired fix must avoid unrelated resource changes. Which investigation would most directly establish the reported Terraform failure?
- Inspect variable input expectations and whether an explicit validation condition can reject invalid strings early.
- Inspect the variable declaration, resource schema, and stored state behavior for that password input.
- Inspect the provider's replacement behavior, uniqueness constraints, and whether old and new instances can coexist.
- Inspect the repository for embedded secrets and review supported Vault provider/ephemeral integration and token access policy.
Explanation
Correct Answer
D:Inspect the repository for embedded secrets and review supported Vault provider/ephemeral integration and token access policy. Secrets management separates credential issuance from infrastructure definitions; committed passwords remain exposed even if displayed as sensitive. A justified correction is: Rotate the exposed token and retrieve needed credentials through an approved Vault-based ephemeral or runtime authentication flow.
Incorrect Answers
A:Inspect variable input expectations and whether an explicit validation condition can reject invalid strings early. This inspects input variable custom validation rule rather than the reported vault credential lookup without hardcoding secret values issue. The decisive investigation is: Inspect the repository for embedded secrets and review supported Vault provider/ephemeral integration and token access policy.
B:Inspect the variable declaration, resource schema, and stored state behavior for that password input. This inspects sensitive variable does not erase state secrets rather than the reported vault credential lookup without hardcoding secret values issue. The decisive investigation is: Inspect the repository for embedded secrets and review supported Vault provider/ephemeral integration and token access policy.
C:Inspect the provider's replacement behavior, uniqueness constraints, and whether old and new instances can coexist. This inspects create_before_destroy lifecycle for availability rather than the reported vault credential lookup without hardcoding secret values issue. The decisive investigation is: Inspect the repository for embedded secrets and review supported Vault provider/ephemeral integration and token access policy.
Question 28
As the deployment team prepares a reviewed Terraform CLI change, 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 change must preserve the distinction between previewing and modifying infrastructure. Which outcome most directly validates the intended fix?
- The runner completes initialization and can calculate a plan using the intended backend and installed dependencies.
- Only the intended disposable environment's managed objects are removed and shared production resources remain in separate state.
- The execution plan explicitly identifies replacement impact and deployment approval records show the risk was addressed.
- The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory.
Explanation
Correct Answer
A:The runner completes initialization and can calculate a plan using the intended backend and installed dependencies. The init command prepares backend configuration and downloads needed providers/modules; it does not create managed resources by itself. It tests the correction: Execute terraform init in the root configuration directory and resolve backend or provider setup failures before planning.
Incorrect Answers
B:Only the intended disposable environment's managed objects are removed and shared production resources remain in separate state. This might validate terraform destroy is managed-scope deletion, but it does not prove that terraform init backend and provider preparation was resolved. Confirm instead: The runner completes initialization and can calculate a plan using the intended backend and installed dependencies.
C:The execution plan explicitly identifies replacement impact and deployment approval records show the risk was addressed. This might validate plan distinguishes replacement from in-place update, but it does not prove that terraform init backend and provider preparation was resolved. Confirm instead: The runner completes initialization and can calculate a plan using the intended backend and installed dependencies.
D:The module source resolves and validation can analyze the combined configuration without manually copying code into the root directory. This might validate module installation during initial setup, but it does not prove that terraform init backend and provider preparation was resolved. Confirm instead: The runner completes initialization and can calculate a plan using the intended backend and installed dependencies.
Question 29
When reviewing a reusable Terraform HCL configuration before deployment, the following condition occurs: A reusable subnet module expects each entry to contain a CIDR and an enable flag, but callers submit unstructured strings and fail validation. 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.
- Declare a suitable object type such as object({ cidr = string, enabled = bool }) and supply matching attribute values.
- Inspect state instance addresses and compare count positions against stable business keys.
- Inspect the module's input type constraint and the shape of the supplied nested values.
- Expose the required network identifier with an output in the child module and reference module.network.<output_name> from the root.
- Use an appropriate map type with key-based lookup or redesign the input as a list if order-based indexing is truly intended.
Explanation
Correct Answers
A:Declare a suitable object type such as object({ cidr = string, enabled = bool }) and supply matching attribute values. Structured object types validate named attribute contracts; a plain string cannot substitute for an object with multiple typed fields. Confirm the cause with: Inspect the module's input type constraint and the shape of the supplied nested values. A concrete acceptance test is: Invalid caller objects fail early, while well-typed nested values reach their intended configuration expressions. This forms one element of the required two-step diagnosis and correction.
C:Inspect the module's input type constraint and the shape of the supplied nested values. Structured object types validate named attribute contracts; a plain string cannot substitute for an object with multiple typed fields. A justified correction is: Declare a suitable object type such as object({ cidr = string, enabled = bool }) and supply matching attribute values. This forms one element of the required two-step diagnosis and correction.
Incorrect Answers
B:Inspect state instance addresses and compare count positions against stable business keys. This relates to for_each stable identity instead of count index rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the module's input type constraint and the shape of the supplied nested values. Then change: Declare a suitable object type such as object({ cidr = string, enabled = bool }) and supply matching attribute values.
D:Expose the required network identifier with an output in the child module and reference module.network.<output_name> from the root. This relates to module output references across composition rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the module's input type constraint and the shape of the supplied nested values. Then change: Declare a suitable object type such as object({ cidr = string, enabled = bool }) and supply matching attribute values.
E:Use an appropriate map type with key-based lookup or redesign the input as a list if order-based indexing is truly intended. This relates to map versus list addressing for environment inputs rather than the matching diagnosis-and-remediation pair required here. Check: Inspect the module's input type constraint and the shape of the supplied nested values. Then change: Declare a suitable object type such as object({ cidr = string, enabled = bool }) and supply matching attribute values.
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.