HashiCorp Terraform Associate (HashiCorp Certified: Terraform Associate) Practice Test 17

Question 160

A Terraform reviewer encounters “for_each with a map” while assessing how to create instances using stable logical keys rather than shifting numeric indexes. Which statement correctly describes its actual behavior?

  1. The type constraint list(string) represents ordered string elements and supports numeric indexing, preserving element order.
  2. A resource's for_each meta-argument accepts maps or sets of strings; map keys appear in resource addresses.
  3. The set(string) type deduplicates values and does not preserve a meaningful input element order.
  4. An unknown value represents future information and can propagate through expressions until a provider supplies the result.

Explanation

Correct Answer

B:

The named mechanism is used when the objective is to create instances using stable logical keys rather than shifting numeric indexes, so it produces the behavior described. In contrast, an unknown plan-time value serves a different goal: identify a computed attribute that Terraform cannot determine until apply, not create instances using stable logical keys rather than shifting numeric indexes.

Incorrect Answers

A:

The description applies to a list of strings type when an engineer needs to accept an ordered collection of same-type string values; the named for_each with a map instead handles the requirement to create instances using stable logical keys rather than shifting numeric indexes, so this behavior does not describe for_each with a map in the situation named.

C:

The description applies to a set of strings type when an engineer needs to store a collection with no duplicate members and no guaranteed order; the named for_each with a map instead handles the requirement to create instances using stable logical keys rather than shifting numeric indexes, so this behavior does not describe for_each with a map in the situation named.

D:

The description applies to an unknown plan-time value when an engineer needs to identify a computed attribute that Terraform cannot determine until apply; the named for_each with a map instead handles the requirement to create instances using stable logical keys rather than shifting numeric indexes, so this behavior does not describe for_each with a map in the situation named.

Question 161

A runbook lists “Policy sets” for the task to attach a shared governance policy collection to selected workspace scopes. Which technical effect should its description include?

  1. Projects group workspaces and support scoped access management for organizational teams.
  2. Policy sets organize policy rules and their workspace or project applicability rather than modifying provider schemas directly.
  3. HCP Terraform approval workflow separates viewing a plan from the permission to proceed with an apply.
  4. HCP Terraform permissions differentiate viewing configuration and runs from authorized apply or administration operations.

Explanation

Correct Answer

B:

The named mechanism is used when the objective is to attach a shared governance policy collection to selected workspace scopes, so it produces the behavior described. In contrast, workspace access separation serves a different goal: prevent a developer with read access from automatically applying production changes, not attach a shared governance policy collection to selected workspace scopes.

Incorrect Answers

A:

The description applies to project-based permission boundaries when an engineer needs to delegate administration of grouped HCP Terraform workspaces; the named policy sets instead handles the requirement to attach a shared governance policy collection to selected workspace scopes, so this behavior does not describe Policy sets in the situation named.

C:

The description applies to workspace run approvals when an engineer needs to require an authorized person to approve a run before applying changes; the named policy sets instead handles the requirement to attach a shared governance policy collection to selected workspace scopes, so this behavior does not describe Policy sets in the situation named.

D:

The description applies to workspace access separation when an engineer needs to prevent a developer with read access from automatically applying production changes; the named policy sets instead handles the requirement to attach a shared governance policy collection to selected workspace scopes, so this behavior does not describe Policy sets in the situation named.

Question 162

A change request asks an engineer to share repeatable plugin selections with a development team. Which choice best implements the requested behavior?

  1. Lockfile source control
  2. A major-series compatible constraint
  3. A provider mirror
  4. terraform init

Explanation

Correct Answer

A:

Checking .terraform.lock.hcl into version control preserves provider version selections and integrity hashes across workstations; this directly meets the requirement to share repeatable plugin selections with a development team. By comparison, a major-series compatible constraint is intended to accept minor and patch updates without crossing the next major version, which is a different task from share repeatable plugin selections with a development team.

Incorrect Answers

B:

The pessimistic constraint ~> 5.3 permits version 5.3 and later releases below 6.0.0; this mechanism is useful when the job is to accept minor and patch updates without crossing the next major version, whereas the current scenario requires the engineer to share repeatable plugin selections with a development team. These operations have different effects in the stated Terraform workflow.

C:

A CLI provider_installation configuration can direct provider package discovery to a network or filesystem mirror; this mechanism is useful when the job is to install approved plugins from an internal distribution location, whereas the current scenario requires the engineer to share repeatable plugin selections with a development team. These operations have different effects in the stated Terraform workflow.

D:

Initialization resolves provider requirements, installs plugins, and prepares modules and backend settings in the working directory; this mechanism is useful when the job is to download missing required provider plugins before planning, whereas the current scenario requires the engineer to share repeatable plugin selections with a development team. These operations have different effects in the stated Terraform workflow.

Question 163

A Terraform change proposal names “The one function” to extract a single element from a collection that contains zero or one elements. Which outcome can reviewers attribute to that particular mechanism?

  1. The condition ? value_a : value_b expression chooses a suitable branch without creating duplicate resource blocks.
  2. templatefile reads a template and evaluates placeholders using the supplied variable map.
  3. jsondecode converts JSON input into native maps, objects, lists or primitives used in expressions.
  4. one returns the lone member, or null if empty, and reports an error when more than one element exists.
  5. sha256 computes a one-way hash of a string, not an encrypted recoverable secret or random credential.
  6. jsonencode converts Terraform values into JSON representation suitable for API fields expecting JSON text.

Explanation

Correct Answer

D:

The named mechanism is used when the objective is to extract a single element from a collection that contains zero or one elements, so it produces the behavior described. In contrast, the templatefile function serves a different goal: render a file containing template expressions with an object of variables, not extract a single element from a collection that contains zero or one elements.

Incorrect Answers

A:

The description applies to the ternary conditional operator when an engineer needs to set a resource argument according to a boolean expression; the named the one function instead handles the requirement to extract a single element from a collection that contains zero or one elements, so this behavior does not describe The one function in the situation named.

B:

The description applies to the templatefile function when an engineer needs to render a file containing template expressions with an object of variables; the named the one function instead handles the requirement to extract a single element from a collection that contains zero or one elements, so this behavior does not describe The one function in the situation named.

C:

The description applies to the jsondecode function when an engineer needs to parse a JSON document string into Terraform values; the named the one function instead handles the requirement to extract a single element from a collection that contains zero or one elements, so this behavior does not describe The one function in the situation named.

E:

The description applies to the sha256 function when an engineer needs to create a deterministic SHA-256 digest for content comparison; the named the one function instead handles the requirement to extract a single element from a collection that contains zero or one elements, so this behavior does not describe The one function in the situation named.

F:

The description applies to the jsonencode function when an engineer needs to serialize a Terraform value into a valid JSON string; the named the one function instead handles the requirement to extract a single element from a collection that contains zero or one elements, so this behavior does not describe The one function in the situation named.

Question 164

A change request asks an engineer to focus logging on error-level diagnostics. Which choice best implements the requested behavior?

  1. TF_LOG_CORE
  2. TF_LOG=ERROR
  3. TF_LOG=TRACE
  4. Disabling TF_LOG
  5. Redacting shared diagnostic logs

Explanation

Correct Answer

B:

ERROR restricts diagnostic output to serious problems rather than normal trace-level activity; this directly meets the requirement to focus logging on error-level diagnostics. By comparison, TF_LOG_CORE is intended to focus verbose diagnostics on Terraform Core rather than all plugin activity, which is a different task from focus logging on error-level diagnostics.

Incorrect Answers

A:

The TF_LOG_CORE variable can control log verbosity for Core messages independently of general logging; this mechanism is useful when the job is to focus verbose diagnostics on Terraform Core rather than all plugin activity, whereas the current scenario requires the engineer to focus logging on error-level diagnostics. These operations have different effects in the stated Terraform workflow.

C:

Terraform logging set to TRACE emits highly verbose diagnostic detail and may contain sensitive information; this mechanism is useful when the job is to obtain detailed Terraform core and provider diagnostic output while troubleshooting, whereas the current scenario requires the engineer to focus logging on error-level diagnostics. These operations have different effects in the stated Terraform workflow.

D:

Unsetting or disabling Terraform's TF_LOG environment setting removes extra diagnostic verbosity from later commands; this mechanism is useful when the job is to return a shell session to ordinary Terraform logging after investigation, whereas the current scenario requires the engineer to focus logging on error-level diagnostics. These operations have different effects in the stated Terraform workflow.

E:

Terraform diagnostic logs can include sensitive data, so access control and careful review are required before sharing them; this mechanism is useful when the job is to prevent troubleshooting output from leaking credentials or resource attributes, whereas the current scenario requires the engineer to focus logging on error-level diagnostics. These operations have different effects in the stated Terraform workflow.

Question 165

A Terraform deployment has independent requirements: (1) replace one managed resource when another managed resource's attribute changes; (2) refer specifically to the second object of a count-created resource. Which TWO mechanisms directly address these needs? Choose TWO.

  1. create_before_destroy
  2. An instance address with count
  3. replace_triggered_by
  4. count and depends_on together
  5. Avoiding dependency cycles
  6. Output-level depends_on

Explanation

Correct Answers

B:

Count instances have numeric indexes such as aws_instance.web[1] for the second instance; this meets the requirement to refer specifically to the second object of a count-created resource, while the other selected techniques address replace one managed resource when another managed resource's attribute changes, which require their own distinct Terraform mechanisms.

C:

This lifecycle rule uses planned resource actions as triggers for replacement and is not a general-purpose dependency selector; this meets the requirement to replace one managed resource when another managed resource's attribute changes, while the other selected techniques address refer specifically to the second object of a count-created resource, which require their own distinct Terraform mechanisms.

Incorrect Answers

A:

This lifecycle setting changes replacement order, but requires names and quotas to permit temporary coexistence; it addresses create a replacement object before deleting the previous instance, but this delivery instead requires replace one managed resource when another managed resource's attribute changes and refer specifically to the second object of a count-created resource. The required combination involves An instance address with count and replace_triggered_by, not the behavior of create_before_destroy.

D:

The depends_on edge can relate the whole counted resource block to an upstream resource, rather than computing one edge by list position; it addresses make multiple resource instances wait for a shared prerequisite, but this delivery instead requires replace one managed resource when another managed resource's attribute changes and refer specifically to the second object of a count-created resource. The required combination involves An instance address with count and replace_triggered_by, not the behavior of count and depends_on together.

E:

Terraform cannot order a cycle of dependencies; restructure references or resource design to remove the circular edge; it addresses resolve a graph where two resources each depend on the other, but this delivery instead requires replace one managed resource when another managed resource's attribute changes and refer specifically to the second object of a count-created resource. The required combination involves An instance address with count and replace_triggered_by, not the behavior of Avoiding dependency cycles.

F:

An output block can express an explicit dependency beyond references contained in its value expression; it addresses prevent a module output from being considered ready before an additional side-effect resource, but this delivery instead requires replace one managed resource when another managed resource's attribute changes and refer specifically to the second object of a count-created resource. The required combination involves An instance address with count and replace_triggered_by, not the behavior of Output-level depends_on.

Question 166

An operations team replacing ad-hoc scripts needs to retain the association between a configuration address and its actual managed object. Which feature or operation is the most direct match?

  1. State-backed object tracking
  2. Version-controlled infrastructure definition
  3. HCL configuration files
  4. Declarative resource configuration

Explanation

Correct Answer

A:

Terraform state records mappings and attributes needed to compare future plans without rediscovering every object's identity from scratch; this directly meets the requirement to retain the association between a configuration address and its actual managed object. By comparison, version-controlled infrastructure definition is intended to review a proposed infrastructure change before team members deploy it, which is a different task from retain the association between a configuration address and its actual managed object.

Incorrect Answers

B:

Infrastructure configuration can be committed and reviewed in version control so the intended change is traceable before a Terraform run; this mechanism is useful when the job is to review a proposed infrastructure change before team members deploy it, whereas the current scenario requires the engineer to retain the association between a configuration address and its actual managed object. These operations have different effects in the stated Terraform workflow.

C:

Terraform reads .tf files written in HCL, including blocks, arguments, expressions and references that describe the intended objects; this mechanism is useful when the job is to represent managed infrastructure using Terraform's native declarative language, whereas the current scenario requires the engineer to retain the association between a configuration address and its actual managed object. These operations have different effects in the stated Terraform workflow.

D:

Terraform interprets resource declarations, constructs a dependency graph, and asks providers to reconcile real objects with that desired state; this mechanism is useful when the job is to describe the desired infrastructure state instead of scripting every API step, whereas the current scenario requires the engineer to retain the association between a configuration address and its actual managed object. These operations have different effects in the stated Terraform workflow.

Question 167

During one infrastructure delivery, the team must satisfy all of the following: (1) use multiple logical state namespaces when the backend implementation supports it; (2) serialize operations that write the same Terraform state. Select TWO appropriate Terraform approaches. Choose TWO.

  1. Remote backend support for workspaces
  2. Init after changing state storage
  3. terraform plan -lock-timeout
  4. terraform init -migrate-state
  5. A backend state lock

Explanation

Correct Answers

A:

Workspace support depends on the selected backend, and each workspace tracks its own state snapshot; this meets the requirement to use multiple logical state namespaces when the backend implementation supports it, while the other selected techniques address serialize operations that write the same Terraform state, which require their own distinct Terraform mechanisms.

E:

Supported backends acquire a state lock so simultaneous writers cannot corrupt or overwrite each other's state changes; this meets the requirement to serialize operations that write the same Terraform state, while the other selected techniques address use multiple logical state namespaces when the backend implementation supports it, which require their own distinct Terraform mechanisms.

Incorrect Answers

B:

Terraform detects changed backend settings and requires initialization with an explicit migration or reconfiguration choice; it addresses adopt a new remote state destination after editing configuration, but this delivery instead requires use multiple logical state namespaces when the backend implementation supports it and serialize operations that write the same Terraform state. The required combination involves A backend state lock and Remote backend support for workspaces, not the behavior of Init after changing state storage.

C:

The lock-timeout option lets Terraform retry lock acquisition for a specified duration before returning an error; it addresses wait for a temporary state lock instead of failing immediately, but this delivery instead requires use multiple logical state namespaces when the backend implementation supports it and serialize operations that write the same Terraform state. The required combination involves A backend state lock and Remote backend support for workspaces, not the behavior of terraform plan -lock-timeout.

D:

After changing backend configuration, migrate-state attempts to transfer existing state instead of starting with an empty one; it addresses copy a known working state's snapshot into a new configured backend, but this delivery instead requires use multiple logical state namespaces when the backend implementation supports it and serialize operations that write the same Terraform state. The required combination involves A backend state lock and Remote backend support for workspaces, not the behavior of terraform init -migrate-state.

Question 168

During a design review, the requirement is to delegate administration of grouped HCP Terraform workspaces. Which option should the engineer select?

  1. HCP provider dynamic credentials
  2. OPA policy enforcement
  3. Project-based permission boundaries
  4. HCP Terraform run tasks

Explanation

Correct Answer

C:

Projects group workspaces and support scoped access management for organizational teams; this directly meets the requirement to delegate administration of grouped HCP Terraform workspaces. By comparison, HCP Terraform run tasks is intended to integrate external checks into a run before applying infrastructure changes, which is a different task from delegate administration of grouped HCP Terraform workspaces.

Incorrect Answers

A:

HCP Terraform can use supported dynamic provider credentials that are generated for runs rather than stored as permanent workspace secrets; this mechanism is useful when the job is to replace standing cloud keys with short-lived run identities, whereas the current scenario requires the engineer to delegate administration of grouped HCP Terraform workspaces. These operations have different effects in the stated Terraform workflow.

B:

HCP Terraform supports OPA-based policy sets for automated governance on applicable runs; this mechanism is useful when the job is to check proposed infrastructure against rules expressed in Open Policy Agent policies, whereas the current scenario requires the engineer to delegate administration of grouped HCP Terraform workspaces. These operations have different effects in the stated Terraform workflow.

D:

Run tasks send run context to integrated systems and can participate in checks or approval workflows, depending on configuration; this mechanism is useful when the job is to integrate external checks into a run before applying infrastructure changes, whereas the current scenario requires the engineer to delegate administration of grouped HCP Terraform workspaces. These operations have different effects in the stated Terraform workflow.

Question 169

An engineer proposes “A module root directory” to keep authentication and deployment-specific region choices outside a reusable child module. Which outcome does the proposed technique actually provide?

  1. The count meta-argument creates numerically indexed module instances such as module.worker[0].
  2. The module block's source points to child configuration and its other arguments supply input variables and relevant meta-arguments.
  3. Reusable modules normally declare provider requirements while callers supply provider configurations and credentials.
  4. All Terraform configuration files in a module directory are combined as one module; filenames do not define separate execution units.

Explanation

Correct Answer

D:

A module root directory is used when an operator needs to understand which source files Terraform loads as one module. Consequently, this choice cannot meet the separate requirement to keep authentication and deployment-specific region choices outside a reusable child module. The intended action would instead require Avoiding hard-coded child credentials.

Incorrect Answers

A:

This behavior belongs to A module with count, which helps engineers instantiate a fixed number of child module copies rather than satisfying the separate requirement to keep authentication and deployment-specific region choices outside a reusable child module. The attempted technique was A module root directory; it would instead be used to understand which source files Terraform loads as one module, not to produce the effect associated with A module with count.

B:

This behavior belongs to A module call block, which helps engineers instantiate a reusable configuration unit under a distinct local name rather than satisfying the separate requirement to keep authentication and deployment-specific region choices outside a reusable child module. The attempted technique was A module root directory; it would instead be used to understand which source files Terraform loads as one module, not to produce the effect associated with A module call block.

C:

That outcome belongs to Avoiding hard-coded child credentials, the mechanism that can keep authentication and deployment-specific region choices outside a reusable child module. The question concerns the engineer’s actual proposal, A module root directory; it is directed at understand which source files Terraform loads as one module, not that result.

Question 170

A new Terraform working directory has a concrete implementation goal: prevent concurrent state writers from overwriting each other's updates. What is the most appropriate Terraform mechanism?

  1. State snapshots
  2. Remote state sharing boundaries
  3. State access protection
  4. State locking

Explanation

Correct Answer

D:

A backend with state-locking support obtains a lock during operations that can modify state, avoiding conflicting simultaneous writes; this directly meets the requirement to prevent concurrent state writers from overwriting each other's updates. By comparison, state snapshots is intended to preserve Terraform's knowledge of managed infrastructure between CLI runs, which is a different task from prevent concurrent state writers from overwriting each other's updates.

Incorrect Answers

A:

The state snapshot records managed instance data and metadata needed to plan future actions; this mechanism is useful when the job is to preserve Terraform's knowledge of managed infrastructure between CLI runs, whereas the current scenario requires the engineer to prevent concurrent state writers from overwriting each other's updates. These operations have different effects in the stated Terraform workflow.

B:

Reading a remote state output still requires access to the underlying snapshot; exporting data through a narrower interface can reduce exposure; this mechanism is useful when the job is to avoid exposing full state when another stack only needs a published identifier, whereas the current scenario requires the engineer to prevent concurrent state writers from overwriting each other's updates. These operations have different effects in the stated Terraform workflow.

C:

State may contain secret values even when CLI output is redacted, so storage encryption and access controls matter; this mechanism is useful when the job is to treat a Terraform state file as potentially sensitive data, whereas the current scenario requires the engineer to prevent concurrent state writers from overwriting each other's updates. These operations have different effects in the stated Terraform workflow.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests