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

Question 260

An infrastructure repository handles database passwords and tokens. A reviewer must determine how to preserve Terraform's safety indicator for secret-bearing expressions. Which action is the appropriate choice?

  1. Use a provider-supported write-only argument
  2. Treat saved plan files as sensitive artifacts
  3. Distinguish ephemeral from sensitive
  4. Avoid unnecessary nonsensitive(...) calls

Explanation

Correct Answer

D:

Nonsensitive removes the sensitivity mark from a value; it does not erase the underlying secret and can expose it in outputs or logs; this behavior should be assessed against the concrete need to preserve Terraform's safety indicator for secret-bearing expressions. This directly supports the task to preserve Terraform's safety indicator for secret-bearing expressions during a staged rollout.

Incorrect Answers

A:

Write-only arguments exist only where the provider schema supports them; they are available in Terraform 1.11+, including the tested 1.12 release; this behavior should be assessed against the concrete need to preserve Terraform's safety indicator for secret-bearing expressions. It may support a related workflow, but the question specifically requires the mechanism for preserve Terraform's safety indicator for secret-bearing expressions rather than send a secret to a managed resource without storing its value in plan or state.

B:

Binary plans can preserve configuration values and secrets; redaction in human-readable output does not make the saved plan safe to publish; this behavior should be assessed against the concrete need to preserve Terraform's safety indicator for secret-bearing expressions. The stated requirement is to preserve Terraform's safety indicator for secret-bearing expressions, not to avoid leaking inputs and backend information through CI downloads; this alternative addresses a different control or phase.

C:

Sensitive marks affect presentation; ephemeral marks constrain persistence and permitted expression contexts; they solve related but nonidentical problems; this behavior should be assessed against the concrete need to preserve Terraform's safety indicator for secret-bearing expressions. That can be useful when the aim is to choose secrecy controls based on persistence as well as output redaction, but it does not directly deliver the requested ability to preserve Terraform's safety indicator for secret-bearing expressions.

Question 261

An engineer is deciding whether Terraform should own an existing object. The requirement is to make intentional destruction part of Terraform's lifecycle model. Which Terraform mechanism directly meets this requirement?

  1. Declare a managed object with resource
  2. Understand data source failure on a missing object
  3. Reference aws_instance.web.id for a managed resource
  4. Recognize terraform_data as a built-in managed resource
  5. Select resource instead of data when deletion must be managed

Explanation

Correct Answer

E:

A data source never directs Terraform to delete the looked-up object; lifecycle ownership requires a managed declaration or an adopted resource; this behavior should be assessed against the concrete need to make intentional destruction part of Terraform's lifecycle model. This directly supports the task to make intentional destruction part of Terraform's lifecycle model during a planned migration.

Incorrect Answers

A:

A resource block is part of the desired managed infrastructure; terraform tracks its remote identity in state and may create, update, replace, or destroy it; this behavior should be assessed against the concrete need to make intentional destruction part of Terraform's lifecycle model. It may support a related workflow, but the question specifically requires the mechanism for make intentional destruction part of Terraform's lifecycle model rather than ask Terraform to own the lifecycle of a remote object.

B:

Many provider data sources require a matching remote object and report an error when none exists; terraform does not create a replacement solely because the data block is present; this behavior should be assessed against the concrete need to make intentional destruction part of Terraform's lifecycle model. The stated requirement is to make intentional destruction part of Terraform's lifecycle model, not to distinguish a failed lookup from a request to create the missing object; this alternative addresses a different control or phase.

C:

A managed resource reference omits the data. prefix; terraform derives a dependency when an argument uses its computed attributes; this behavior should be assessed against the concrete need to make intentional destruction part of Terraform's lifecycle model. That can be useful when the aim is to consume the ID of an object declared through a resource block, but it does not directly deliver the requested ability to make intentional destruction part of Terraform's lifecycle model.

D:

The built-in Terraform provider supplies this resource for lifecycle-oriented uses; it is not a general substitute for querying arbitrary cloud objects; this behavior should be assessed against the concrete need to make intentional destruction part of Terraform's lifecycle model. The distinction matters here: using that mechanism to store arbitrary values or trigger replacements without a third-party resource API would still leave the objective to make intentional destruction part of Terraform's lifecycle model unmet.

Question 262

A module consumer must reference attributes from other blocks. A reviewer must determine how to prevent a graph in which objects depend on each other without a valid ordering. Which action is the appropriate choice?

  1. Use resource_type.name.attribute
  2. Avoid cyclic resource references
  3. Use count.index inside counted blocks
  4. Understand values unknown until apply

Explanation

Correct Answer

B:

A circular dependency has no acyclic execution order; splitting responsibilities or breaking unnecessary references resolves the cycle; this behavior should be assessed against the concrete need to prevent a graph in which objects depend on each other without a valid ordering. This directly supports the task to prevent a graph in which objects depend on each other without a valid ordering during a cross-team handoff.

Incorrect Answers

A:

The expression resolves through the address and provider schema; terraform sees the dependency and can wait for an unknown computed value until apply; this behavior should be assessed against the concrete need to prevent a graph in which objects depend on each other without a valid ordering. The distinction matters here: using that mechanism to read a named attribute from a managed resource would still leave the objective to prevent a graph in which objects depend on each other without a valid ordering unmet.

C:

A count meta-argument creates numerically indexed instances. count.index is available in blocks that use count, not as a global value; this behavior should be assessed against the concrete need to prevent a graph in which objects depend on each other without a valid ordering. The stated requirement is to prevent a graph in which objects depend on each other without a valid ordering, not to identify the zero-based index of the current instance; this alternative addresses a different control or phase.

D:

Terraform can propagate unknown values through expressions and defer dependent evaluations; unknown does not necessarily mean the configuration is invalid; this behavior should be assessed against the concrete need to prevent a graph in which objects depend on each other without a valid ordering. That can be useful when the aim is to avoid assuming every computed attribute is fixed during planning, but it does not directly deliver the requested ability to prevent a graph in which objects depend on each other without a valid ordering.

Question 263

The immediate Terraform task is to supply a fallback when the caller omits the variable. Which method handles that task most directly?

  1. Use terraform.tfvars or *.auto.tfvars
  2. Set nullable = false for a required non-null variable
  3. Use terraform output -raw NAME for a string result
  4. Set default for an optional configuration input

Explanation

Correct Answer

D:

A default provides a value without per-run input; a caller can still override it using a supported variable assignment mechanism; this behavior should be assessed against the concrete need to supply a fallback when the caller omits the variable. This directly supports the task to supply a fallback when the caller omits the variable during a platform review.

Incorrect Answers

A:

Terraform discovers these conventional names during CLI runs; arbitrarily named .tfvars files require explicit selection; this behavior should be assessed against the concrete need to supply a fallback when the caller omits the variable. That can be useful when the aim is to automatically load documented variable files in a root module, but it does not directly deliver the requested ability to supply a fallback when the caller omits the variable.

B:

The nullable setting controls whether null can be supplied; it is different from a missing default and distinct from sensitive output masking; this behavior should be assessed against the concrete need to supply a fallback when the caller omits the variable. The distinction matters here: using that mechanism to reject explicit null values instead of treating them as ordinary accepted inputs would still leave the objective to supply a fallback when the caller omits the variable unmet.

C:

Raw output formats a supported string, number, or Boolean directly without extra Terraform representation; complex objects require another output format; this behavior should be assessed against the concrete need to supply a fallback when the caller omits the variable. It may support a related workflow, but the question specifically requires the mechanism for supply a fallback when the caller omits the variable rather than retrieve a plain scalar output for shell integration.

Question 264

A Terraform rollout has separate acceptance criteria: collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences. Which combined approach directly satisfies the two criteria?

  1. Convert values with toset(...) + Use type = any sparingly
  2. Convert values with tolist(...) + Recognize map iteration's key ordering
  3. Use flatten(...) for nested lists + Use optional(...) in object attributes
  4. Use flatten(...) for nested lists + Recognize map iteration's key ordering

Explanation

Correct Answer

D:

For the first criterion, flatten recursively reduces nested list/tuple containers while preserving the flattened order; it does not merge map attributes; this behavior should be assessed against the concrete need to collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences; this directly addresses the need to collapse a list of lists into one sequence. For the separate second criterion, when Terraform converts map elements into an ordered result, it sorts keys lexically; this differs from an explicitly ordered input list; this behavior should be assessed against the concrete need to collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences; this fulfills the need to avoid interpreting maps as insertion-ordered sequences. Together they cover the independent tasks of collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure is intended to remove duplicates and produce set semantics for iteration: Conversion is useful for stable for_each string keys; it is not equivalent to preserving the original list order; this behavior should be assessed against the concrete need to collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences. The second measure is intended to permit values of varying shapes where a strict contract is impractical: The any placeholder relaxes static expectations but sacrifices early type guarantees; most module interfaces benefit from a concrete type; this behavior should be assessed against the concrete need to collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences. Neither is the directly designated method for the separate goals of collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences in this review.

B:

The second measure does meet the avoid interpreting maps as insertion-ordered sequences requirement, but the first is designed for another concern: The conversion yields a list but an unordered source set may produce an arbitrary order; do not use it to promise stable positions for set elements; this behavior should be assessed against the concrete need to collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences. That first component is designed to produce a list value when a downstream expression requires list semantics, which does not accomplish the requested task to collapse a list of lists into one sequence, even though the other measure satisfies avoid interpreting maps as insertion-ordered sequences.

C:

The first measure meets the requirement to collapse a list of lists into one sequence, but its partner serves a different role: Optional attributes let module callers omit selected fields and may provide defaults; they do not make unrelated required object attributes optional; this behavior should be assessed against the concrete need to collapse a list of lists into one sequence and avoid interpreting maps as insertion-ordered sequences. That second component is designed to allow an object field to be omitted from a typed input, so the still-missing criterion is to avoid interpreting maps as insertion-ordered sequences, while the first criterion remains collapse a list of lists into one sequence.

Question 265

An engineer needs to obtain a map entry with a fallback for an absent key as part of a planned migration. Which option is the best fit?

  1. Use lookup(map, key, default)
  2. Use concat(list1, list2)
  3. Use zipmap(keys, values)
  4. Use alltrue(list_of_bools)

Explanation

Correct Answer

A:

Lookup returns the named value when present and the fallback otherwise; direct map indexing may fail when the key is missing; this behavior should be assessed against the concrete need to obtain a map entry with a fallback for an absent key. This directly supports the task to obtain a map entry with a fallback for an absent key during a maintenance request.

Incorrect Answers

B:

Concat combines lists or tuples into one sequence; it does not remove duplicates as a set conversion would; this behavior should be assessed against the concrete need to obtain a map entry with a fallback for an absent key. The stated requirement is to obtain a map entry with a fallback for an absent key, not to append sequences while retaining element order; this alternative addresses a different control or phase.

C:

Zipmap associates entries positionally and expects compatible list lengths; it is different from merging two already formed maps; this behavior should be assessed against the concrete need to obtain a map entry with a fallback for an absent key. That can be useful when the aim is to assemble a map from paired key and value lists, but it does not directly deliver the requested ability to obtain a map entry with a fallback for an absent key.

D:

Alltrue is useful for validating all entries in an input list; anytrue instead tests whether at least one entry succeeds; this behavior should be assessed against the concrete need to obtain a map entry with a fallback for an absent key. The distinction matters here: using that mechanism to require every evaluated Boolean in a collection to be true would still leave the objective to obtain a map entry with a fallback for an absent key unmet.

Question 266

A Terraform review distinguishes lifecycle safeguards from graph edges. Two independent changes are requested: first, order resources when the second consumes a value from the first; second, represent an input change through a managed resource lifecycle. Which pair of measures fulfills both?

  1. Recognize lifecycle arguments are evaluated early + Understand destroy order as dependency-aware
  2. Use an attribute reference for an implicit edge + Use explicit dependencies on module calls carefully
  3. Use prevent_destroy = true on a configured resource + Use terraform_data for value-driven replacement triggers
  4. Use an attribute reference for an implicit edge + Use terraform_data for value-driven replacement triggers

Explanation

Correct Answer

D:

For the first criterion, terraform builds a dependency from the expression reference; a separate explicit ordering rule is unnecessary when data flow already expresses the relationship; this behavior should be assessed against the concrete need to order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle; this directly addresses the need to order resources when the second consumes a value from the first. For the separate second criterion, a terraform_data resource can turn a changing value into a planned change that replace_triggered_by can reference; this avoids trying to reference a bare variable as a resource action; this behavior should be assessed against the concrete need to order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle; this fulfills the need to represent an input change through a managed resource lifecycle. Together they cover the independent tasks of order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure is intended to avoid dynamic expressions for create_before_destroy and similar rules: These lifecycle settings shape the graph construction stage and typically require literal values; a runtime input cannot freely toggle them as ordinary arguments; this behavior should be assessed against the concrete need to order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle. The second measure is intended to remove dependents before the infrastructure they rely on: Terraform generally reverses dependency order for teardown; this minimizes failures caused by destroying prerequisites too early; this behavior should be assessed against the concrete need to order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle. Neither is the directly designated method for the separate goals of order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle in this review.

B:

The first measure meets the requirement to order resources when the second consumes a value from the first, but its partner serves a different role: depends_on on a module applies to the module's relevant actions, not just one output; it may be broader than a targeted output reference; this behavior should be assessed against the concrete need to order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle. That second component is designed to delay all operations in a child module until required prerequisites complete, so the still-missing criterion is to represent an input change through a managed resource lifecycle, while the first criterion remains order resources when the second consumes a value from the first.

C:

The second measure does meet the represent an input change through a managed resource lifecycle requirement, but the first is designed for another concern: This is a lifecycle safety check, not a remote deletion-protection feature; removing the resource block also removes the rule from consideration; this behavior should be assessed against the concrete need to order resources when the second consumes a value from the first and represent an input change through a managed resource lifecycle. That first component is designed to fail a plan that would destroy the protected resource while its block remains, which does not accomplish the requested task to order resources when the second consumes a value from the first, even though the other measure satisfies represent an input change through a managed resource lifecycle.

Question 267

A module needs configuration guardrails. A reviewer must determine how to validate every element of a collection against one rule. Which action is the appropriate choice?

  1. Use a precondition rather than a check for an unsafe prerequisite
  2. Use a check block with assertions
  3. Use a resource precondition
  4. Use alltrue over transformed entries

Explanation

Correct Answer

D:

Combining a for expression with alltrue yields a single Boolean input contract; it is not the same as testing only the first list element; this behavior should be assessed against the concrete need to validate every element of a collection against one rule. This directly supports the task to validate every element of a collection against one rule during a staged rollout.

Incorrect Answers

A:

Blocking conditions are appropriate when continuing could create invalid infrastructure; a check block typically reports a warning and lets operations proceed; this behavior should be assessed against the concrete need to validate every element of a collection against one rule. That can be useful when the aim is to stop a deployment when a required assumption fails, but it does not directly deliver the requested ability to validate every element of a collection against one rule.

B:

Checks are designed for nonblocking validation and can report warnings during plan/apply; critical prerequisites belong in blocking custom conditions; this behavior should be assessed against the concrete need to validate every element of a collection against one rule. The distinction matters here: using that mechanism to monitor an infrastructure invariant and report failed checks without blocking the whole operation would still leave the objective to validate every element of a collection against one rule unmet.

C:

A lifecycle precondition can inspect values needed for a safe operation; failure blocks proceeding instead of simply recording a health warning; this behavior should be assessed against the concrete need to validate every element of a collection against one rule. It may support a related workflow, but the question specifically requires the mechanism for validate every element of a collection against one rule rather than verify an assumption before Terraform processes the target resource operation.

Question 268

The immediate Terraform task is to restrict display of secret input values in hosted runs. Which method handles that task most directly?

  1. Use HCP Terraform sensitive workspace variables
  2. Mark a secret root output sensitive = true
  3. Use environment-based provider authentication when supported
  4. Mark a variable sensitive = true

Explanation

Correct Answer

A:

HCP Terraform offers marked-sensitive variables for workspace runs; their handling is a platform feature, not evidence that every resulting resource attribute is absent from state; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs. This directly supports the task to restrict display of secret input values in hosted runs during a configuration change.

Incorrect Answers

B:

Output sensitivity masks typical CLI views; authorized state readers and certain machine-readable commands may still reveal the value; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs. That can be useful when the aim is to avoid normal display of an output carrying sensitive data, but it does not directly deliver the requested ability to restrict display of secret input values in hosted runs.

C:

Many providers support environment variables or workload identity; this lowers credential exposure in source but still requires secure runtime injection; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs. The distinction matters here: using that mechanism to avoid embedding long-lived credentials in HCL provider blocks would still leave the objective to restrict display of secret input values in hosted runs unmet.

D:

Sensitivity propagates through expressions and hides values in many UI contexts; it does not, by itself, keep the original secret out of state or saved plan files; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs. It may support a related workflow, but the question specifically requires the mechanism for restrict display of secret input values in hosted runs rather than hide a secret from ordinary CLI displays.

Question 269

An HCL author is separating managed infrastructure from lookups. A reviewer must determine how to adopt a previously existing object into Terraform management. Which action is the appropriate choice?

  1. Distinguish locals from remote resource declarations
  2. Use an ephemeral resource for supported temporary data
  3. Use a resource block together with an import block
  4. Declare a managed object with resource
  5. Use provider selection on both resource and data blocks

Explanation

Correct Answer

C:

Import associates the provider's existing remote object with a declared resource address; simply reading it as a data source does not establish that lifecycle ownership; this behavior should be assessed against the concrete need to adopt a previously existing object into Terraform management. This directly supports the task to adopt a previously existing object into Terraform management during a cross-team handoff.

Incorrect Answers

A:

Local values are named expressions evaluated inside a module; they neither invoke resource creation nor bind a remote object into state; this behavior should be assessed against the concrete need to adopt a previously existing object into Terraform management. The stated requirement is to adopt a previously existing object into Terraform management, not to compute reusable expression results without creating an API object; this alternative addresses a different control or phase.

B:

Ephemeral resources are available for supported providers and valid contexts; they are not ordinary managed resources with persistent state identity; this behavior should be assessed against the concrete need to adopt a previously existing object into Terraform management. That can be useful when the aim is to obtain a short-lived value without persisting it in state or plan, but it does not directly deliver the requested ability to adopt a previously existing object into Terraform management.

D:

A resource block is part of the desired managed infrastructure; terraform tracks its remote identity in state and may create, update, replace, or destroy it; this behavior should be assessed against the concrete need to adopt a previously existing object into Terraform management. It may support a related workflow, but the question specifically requires the mechanism for adopt a previously existing object into Terraform management rather than ask Terraform to own the lifecycle of a remote object.

E:

Provider aliases control where the relevant API call is sent; a data source without an explicit alias may query the default context even when a nearby resource uses an alternate one; this behavior should be assessed against the concrete need to adopt a previously existing object into Terraform management. The stated requirement is to adopt a previously existing object into Terraform management, not to direct API operations and lookups to the intended account or region; this alternative addresses a different control or phase.

Question 270

The immediate Terraform task is to read a named attribute from a managed resource. Which method handles that task most directly?

  1. Use output to expose child internals intentionally
  2. Use local.prefix
  3. Use direct attribute references to create implicit dependencies
  4. Use count.index inside counted blocks
  5. Understand values unknown until apply
  6. Use resource_type.name.attribute

Explanation

Correct Answer

F:

The expression resolves through the address and provider schema; terraform sees the dependency and can wait for an unknown computed value until apply; this behavior should be assessed against the concrete need to read a named attribute from a managed resource. This directly supports the task to read a named attribute from a managed resource during a platform review.

Incorrect Answers

A:

An output value makes selected internal attributes available as module.name.output; child resources themselves remain encapsulated behind the module boundary; this behavior should be assessed against the concrete need to read a named attribute from a managed resource. It may support a related workflow, but the question specifically requires the mechanism for read a named attribute from a managed resource rather than create a stable boundary for modules that callers depend on.

B:

Local expressions help avoid repeating calculations; each module has its own local namespace; callers cannot directly inspect a child's locals; this behavior should be assessed against the concrete need to read a named attribute from a managed resource. The stated requirement is to read a named attribute from a managed resource, not to reference a computed local value in the same module; this alternative addresses a different control or phase.

C:

A resource that consumes another's attribute implicitly depends on it; explicit depends_on is unnecessary when the reference already captures the ordering need; this behavior should be assessed against the concrete need to read a named attribute from a managed resource. That can be useful when the aim is to let Terraform infer safe operation order through data flow, but it does not directly deliver the requested ability to read a named attribute from a managed resource.

D:

A count meta-argument creates numerically indexed instances. count.index is available in blocks that use count, not as a global value; this behavior should be assessed against the concrete need to read a named attribute from a managed resource. The distinction matters here: using that mechanism to identify the zero-based index of the current instance would still leave the objective to read a named attribute from a managed resource unmet.

E:

Terraform can propagate unknown values through expressions and defer dependent evaluations; unknown does not necessarily mean the configuration is invalid; this behavior should be assessed against the concrete need to read a named attribute from a managed resource. It may support a related workflow, but the question specifically requires the mechanism for read a named attribute from a managed resource rather than avoid assuming every computed attribute is fixed during planning.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests