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

Question 350

During a module implementation, the team must accomplish all of these distinct aims: (1) collect an attribute from a list-like collection of resource instances; (2) let Terraform infer safe operation order through data flow. Select exactly the two relevant mechanisms. Choose TWO.

  1. Use resource.items[*].id for counted instances
  2. Avoid cyclic resource references
  3. Use direct attribute references to create implicit dependencies
  4. Use local.prefix
  5. Use depends_on for hidden ordering requirements
  6. Use resource_type.name.attribute

Explanation

Correct Answers

A:

Splat expressions iterate list, set, or tuple values, including count-created instances. for_each maps are normally traversed using a for expression; this behavior should be assessed against the concrete need to collect an attribute from a list-like collection of resource instances and let Terraform infer safe operation order through data flow. This matches the distinct objective to collect an attribute from a list-like collection of resource instances; the remaining chosen features address let Terraform infer safe operation order through data flow.

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 collect an attribute from a list-like collection of resource instances and let Terraform infer safe operation order through data flow. This matches the distinct objective to let Terraform infer safe operation order through data flow; the remaining chosen features address collect an attribute from a list-like collection of resource instances.

Incorrect Answers

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 collect an attribute from a list-like collection of resource instances and let Terraform infer safe operation order through data flow. Its main application is to prevent a graph in which objects depend on each other without a valid ordering; the checklist instead asks for collect an attribute from a list-like collection of resource instances; and let Terraform infer safe operation order through data flow. None of those distinct criteria specifically calls for this alternative.

D:

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 collect an attribute from a list-like collection of resource instances and let Terraform infer safe operation order through data flow. Its main application is to reference a computed local value in the same module; the checklist instead asks for collect an attribute from a list-like collection of resource instances; and let Terraform infer safe operation order through data flow. None of those distinct criteria specifically calls for this alternative.

E:

Terraform's graph uses the explicit edge even without a data reference; overusing whole-resource dependencies may defer reads and reduce concurrency; this behavior should be assessed against the concrete need to collect an attribute from a list-like collection of resource instances and let Terraform infer safe operation order through data flow. Its main application is to declare a relationship that cannot be expressed through an input attribute; the checklist instead asks for collect an attribute from a list-like collection of resource instances; and let Terraform infer safe operation order through data flow. None of those distinct criteria specifically calls for this alternative.

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 collect an attribute from a list-like collection of resource instances and let Terraform infer safe operation order through data flow. Its main application is to read a named attribute from a managed resource; the checklist instead asks for collect an attribute from a list-like collection of resource instances; and let Terraform infer safe operation order through data flow. None of those distinct criteria specifically calls for this alternative.

Question 351

A Terraform rollout has separate acceptance criteria: supply a fallback when the caller omits the variable and load named environment inputs that are not automatically discovered. Which combined approach directly satisfies the two criteria?

  1. Use terraform output -raw NAME for a string result + Use terraform output -json for machine-readable results
  2. Set default for an optional configuration input + Pass values through -var-file=custom.tfvars
  3. Set nullable = false for a required non-null variable + Pass values through -var-file=custom.tfvars
  4. Set default for an optional configuration input + Use terraform.tfvars or *.auto.tfvars

Explanation

Correct Answer

B:

For the first criterion, 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 and load named environment inputs that are not automatically discovered; this directly addresses the need to supply a fallback when the caller omits the variable. For the separate second criterion, explicit variable files let separate runs use separate configurations; the file supplies module inputs, not resource lifecycle commands; this behavior should be assessed against the concrete need to supply a fallback when the caller omits the variable and load named environment inputs that are not automatically discovered; this fulfills the need to load named environment inputs that are not automatically discovered. Together they cover the independent tasks of supply a fallback when the caller omits the variable and load named environment inputs that are not automatically discovered without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure is intended to retrieve a plain scalar output for shell integration: 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 and load named environment inputs that are not automatically discovered. The second measure is intended to obtain structured output values in scripts: JSON mode includes values and sensitivity metadata; downstream tooling must treat sensitive data carefully; this command reads recorded outputs, not arbitrary provider API properties; this behavior should be assessed against the concrete need to supply a fallback when the caller omits the variable and load named environment inputs that are not automatically discovered. Neither is the directly designated method for the separate goals of supply a fallback when the caller omits the variable and load named environment inputs that are not automatically discovered in this review.

C:

The second measure does meet the load named environment inputs that are not automatically discovered requirement, but the first is designed for another concern: 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 and load named environment inputs that are not automatically discovered. That first component is designed to reject explicit null values instead of treating them as ordinary accepted inputs, which does not accomplish the requested task to supply a fallback when the caller omits the variable, even though the other measure satisfies load named environment inputs that are not automatically discovered.

D:

The first measure meets the requirement to supply a fallback when the caller omits the variable, but its partner serves a different role: 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 and load named environment inputs that are not automatically discovered. That second component is designed to automatically load documented variable files in a root module, so the still-missing criterion is to load named environment inputs that are not automatically discovered, while the first criterion remains supply a fallback when the caller omits the variable.

Question 352

An engineer needs to produce a list value when a downstream expression requires list semantics as part of a planned migration. Which option is the best fit?

  1. Use optional(...) in object attributes
  2. Use map(string) for named string values
  3. Access a list with var.zones[0]
  4. Convert values with tolist(...)
  5. Use flatten(...) for nested lists

Explanation

Correct Answer

D:

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 produce a list value when a downstream expression requires list semantics. This directly supports the task to produce a list value when a downstream expression requires list semantics during a maintenance request.

Incorrect Answers

A:

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 produce a list value when a downstream expression requires list semantics. It may support a related workflow, but the question specifically requires the mechanism for produce a list value when a downstream expression requires list semantics rather than allow an object field to be omitted from a typed input.

B:

Maps provide a homogeneous value type and stable keys; they differ from lists, which are indexed by position; this behavior should be assessed against the concrete need to produce a list value when a downstream expression requires list semantics. The stated requirement is to produce a list value when a downstream expression requires list semantics, not to look up values by arbitrary string keys; this alternative addresses a different control or phase.

C:

Lists use zero-based positional indices; a set lacks a stable positional index for this purpose; this behavior should be assessed against the concrete need to produce a list value when a downstream expression requires list semantics. That can be useful when the aim is to retrieve the first element of an ordered collection, but it does not directly deliver the requested ability to produce a list value when a downstream expression requires list semantics.

E:

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 produce a list value when a downstream expression requires list semantics. It may support a related workflow, but the question specifically requires the mechanism for produce a list value when a downstream expression requires list semantics rather than collapse a list of lists into one sequence.

Question 353

A module author is replacing repetitive HCL with expressions. Two independent changes are requested: first, remove duplicate list elements while preserving first occurrence order; second, test whether a collection includes a particular element. Which pair of measures fulfills both?

  1. Use distinct(list) + Use try(expr, fallback)
  2. Use merge(map1, map2) + Use contains(collection, value)
  3. Use distinct(list) + Use contains(collection, value)
  4. Use count for numbered resource instances + Use split(delimiter, string)
  5. Use join(delimiter, list) + Use contains(collection, value)

Explanation

Correct Answer

C:

For the first criterion, distinct retains a list representation with unique values; it is useful when order still matters and a set would alter semantics; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element; this directly addresses the need to remove duplicate list elements while preserving first occurrence order. For the separate second criterion, contains returns a Boolean membership result; it does not check whether an object has a named attribute with a separate schema; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element; this fulfills the need to test whether a collection includes a particular element. Together they cover the independent tasks of remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure meets the requirement to remove duplicate list elements while preserving first occurrence order, but its partner serves a different role: Try evaluates arguments until one succeeds; it should not mask known structural errors or replace explicit input validation; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element. That second component is designed to recover from dynamic expression errors with an alternative result, so the still-missing criterion is to test whether a collection includes a particular element, while the first criterion remains remove duplicate list elements while preserving first occurrence order.

B:

The second measure does meet the test whether a collection includes a particular element requirement, but the first is designed for another concern: Merge returns one map/object composed from inputs; it does not concatenate list elements or destroy original remote objects; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element. That first component is designed to combine maps with later arguments overriding duplicate keys, which does not accomplish the requested task to remove duplicate list elements while preserving first occurrence order, even though the other measure satisfies test whether a collection includes a particular element.

D:

The first measure is intended to create a known number of repeated managed resource instances: Count produces addresses indexed by integers; changing list order may shift how items map to instances when coupled with positional inputs; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element. The second measure is intended to divide text into a list around a separator: Split produces a sequence of pieces; it does not construct a map from the resulting values automatically; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element. Neither is the directly designated method for the separate goals of remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element in this review.

E:

The second measure does meet the test whether a collection includes a particular element requirement, but the first is designed for another concern: Join forms one string from elements; split performs the reverse direction on a string; this behavior should be assessed against the concrete need to remove duplicate list elements while preserving first occurrence order and test whether a collection includes a particular element. That first component is designed to combine a sequence of strings with a separator, which does not accomplish the requested task to remove duplicate list elements while preserving first occurrence order, even though the other measure satisfies test whether a collection includes a particular element.

Question 354

During a deployment checklist, one task is to delay all operations in a child module until required prerequisites complete, while another is to allow unrelated operations to proceed concurrently. Select the matching pair of techniques.

  1. Use create_before_destroy = true + Use ignore_changes = [tags]
  2. Avoid a circular dependency graph + Use graph parallelism for independent resources
  3. Use an attribute reference for an implicit edge + Use graph parallelism for independent resources
  4. Use explicit dependencies on module calls carefully + Use graph parallelism for independent resources
  5. Use explicit dependencies on module calls carefully + Recognize propagated create_before_destroy behavior

Explanation

Correct Answer

D:

For the first criterion, 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 delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently; this directly addresses the need to delay all operations in a child module until required prerequisites complete. For the separate second criterion, terraform can schedule independent graph nodes in parallel within its configured limit; artificial dependencies reduce parallel execution; this behavior should be assessed against the concrete need to delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently; this fulfills the need to allow unrelated operations to proceed concurrently. Together they cover the independent tasks of delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure is intended to request creation of a replacement before deleting the old instance: This lifecycle rule can reduce service interruption where unique names and quotas allow coexistence; it cannot guarantee an API permits two simultaneous objects; this behavior should be assessed against the concrete need to delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently. The second measure is intended to exclude selected post-creation attribute differences from update planning: Ignore-changes permits another process to adjust specified fields without Terraform constantly reverting them; it does not ignore creation-time arguments; this behavior should be assessed against the concrete need to delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently. Neither is the directly designated method for the separate goals of delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently in this review.

B:

The second measure does meet the allow unrelated operations to proceed concurrently requirement, but the first is designed for another concern: Terraform cannot schedule a true cycle in its directed acyclic graph; rearranging references or splitting resource responsibilities can remove the cycle; this behavior should be assessed against the concrete need to delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently. That first component is designed to break mutual dependencies that prevent Terraform from ordering operations, which does not accomplish the requested task to delay all operations in a child module until required prerequisites complete, even though the other measure satisfies allow unrelated operations to proceed concurrently.

C:

The second measure does meet the allow unrelated operations to proceed concurrently requirement, but the first is designed for another concern: 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 delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently. That first component is designed to order resources when the second consumes a value from the first, which does not accomplish the requested task to delay all operations in a child module until required prerequisites complete, even though the other measure satisfies allow unrelated operations to proceed concurrently.

E:

The first measure meets the requirement to delay all operations in a child module until required prerequisites complete, but its partner serves a different role: Terraform may propagate create-before-destroy to dependencies and preserve that decision in state; a downstream replacement can therefore affect upstream lifecycle ordering; this behavior should be assessed against the concrete need to delay all operations in a child module until required prerequisites complete and allow unrelated operations to proceed concurrently. That second component is designed to understand why a dependency may also be retained during a replacement, so the still-missing criterion is to allow unrelated operations to proceed concurrently, while the first criterion remains delay all operations in a child module until required prerequisites complete.

Question 355

A Terraform review separates 2 requirements: (1) test a string against a pattern without crashing on a nonmatch; (2) express the Boolean invariant and its diagnostic message. Identify the two features that each directly handle one of those requirements. Choose TWO.

  1. Use assert { condition = ... } inside check
  2. Use a variable validation block
  3. Use can(regex(...)) in validation
  4. Use a resource precondition
  5. Use an output precondition
  6. Use error_message for actionable custom diagnostics

Explanation

Correct Answers

A:

An assert block carries the condition and explanatory error text for a named check; it is not a normal managed resource declaration; this behavior should be assessed against the concrete need to test a string against a pattern without crashing on a nonmatch and express the Boolean invariant and its diagnostic message. This matches the distinct objective to express the Boolean invariant and its diagnostic message; the remaining chosen features address test a string against a pattern without crashing on a nonmatch.

C:

Regex can raise an error when no match exists; can converts that evaluability into a Boolean; it makes a precise input-validation rule possible; this behavior should be assessed against the concrete need to test a string against a pattern without crashing on a nonmatch and express the Boolean invariant and its diagnostic message. This matches the distinct objective to test a string against a pattern without crashing on a nonmatch; the remaining chosen features address express the Boolean invariant and its diagnostic message.

Incorrect Answers

B:

A variable validation condition evaluates to a Boolean and reports the specified error when false; it sets the input contract independently of provider API permissions; this behavior should be assessed against the concrete need to test a string against a pattern without crashing on a nonmatch and express the Boolean invariant and its diagnostic message. Its main application is to reject a malformed module input with a custom message; the checklist instead asks for test a string against a pattern without crashing on a nonmatch; and express the Boolean invariant and its diagnostic message. None of those distinct criteria specifically calls for this alternative.

D:

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 test a string against a pattern without crashing on a nonmatch and express the Boolean invariant and its diagnostic message. Its main application is to verify an assumption before Terraform processes the target resource operation; the checklist instead asks for test a string against a pattern without crashing on a nonmatch; and express the Boolean invariant and its diagnostic message. None of those distinct criteria specifically calls for this alternative.

E:

Output preconditions can check values or dependencies before the output is finalized; they keep exported data subject to explicit guarantees; this behavior should be assessed against the concrete need to test a string against a pattern without crashing on a nonmatch and express the Boolean invariant and its diagnostic message. Its main application is to ensure a module only exposes results that satisfy a contract; the checklist instead asks for test a string against a pattern without crashing on a nonmatch; and express the Boolean invariant and its diagnostic message. None of those distinct criteria specifically calls for this alternative.

F:

Variable validation and lifecycle conditions support custom messages; a vague error message makes troubleshooting harder even when the Boolean test is correct; this behavior should be assessed against the concrete need to test a string against a pattern without crashing on a nonmatch and express the Boolean invariant and its diagnostic message. Its main application is to tell users which contract failed and why; the checklist instead asks for test a string against a pattern without crashing on a nonmatch; and express the Boolean invariant and its diagnostic message. None of those distinct criteria specifically calls for this alternative.

Question 356

A Terraform rollout has separate acceptance criteria: retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets. Which combined approach directly satisfies the two criteria?

  1. Use Vault to centralize secret access + Protect access to remote state
  2. Rotate credentials after suspected disclosure + Protect access to remote state
  3. Use Vault to centralize secret access + Use an ephemeral resource to retrieve supported temporary secrets
  4. Distinguish ephemeral from sensitive + Avoid unnecessary nonsensitive(...) calls

Explanation

Correct Answer

A:

For the first criterion, vault provides secret-management and credential capabilities; its Terraform provider can integrate with Vault APIs, but ordinary read results may still be recorded unless ephemeral patterns are used; this behavior should be assessed against the concrete need to retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets; this directly addresses the need to retrieve or distribute sensitive credentials under explicit access policy. For the separate second criterion, a remote backend may encrypt stored state and enforce access controls; terraform sensitive annotations do not replace backend security; this behavior should be assessed against the concrete need to retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets; this fulfills the need to secure resource attributes and possibly persisted secrets. Together they cover the independent tasks of retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets without exchanging the responsibilities of these features.

Incorrect Answers

B:

The second measure does meet the secure resource attributes and possibly persisted secrets requirement, but the first is designed for another concern: Removing a line from code does not revoke already exposed tokens; credential rotation and cleanup of historical artifacts are separate security steps; this behavior should be assessed against the concrete need to retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets. That first component is designed to reduce risk when secrets were written to state or repository history, which does not accomplish the requested task to retrieve or distribute sensitive credentials under explicit access policy, even though the other measure satisfies secure resource attributes and possibly persisted secrets.

C:

The first measure meets the requirement to retrieve or distribute sensitive credentials under explicit access policy, but its partner serves a different role: Ephemeral resources avoid persisting their results in Terraform's normal state and plan artifacts; their values cannot be used in arbitrary persistent resource fields; this behavior should be assessed against the concrete need to retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets. That second component is designed to obtain runtime-only data through an ephemeral provider operation, so the still-missing criterion is to secure resource attributes and possibly persisted secrets, while the first criterion remains retrieve or distribute sensitive credentials under explicit access policy.

D:

The first measure is intended to choose secrecy controls based on persistence as well as output redaction: 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 retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets. The second measure is intended to preserve Terraform's safety indicator for secret-bearing expressions: 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 retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets. Neither is the directly designated method for the separate goals of retrieve or distribute sensitive credentials under explicit access policy and secure resource attributes and possibly persisted secrets in this review.

Question 357

A reviewer has to approve a two-part design: store arbitrary values or trigger replacements without a third-party resource API; additionally, make intentional destruction part of Terraform's lifecycle model. Which option pairs the correct mechanisms?

  1. Recognize terraform_data as a built-in managed resource + Select resource instead of data when deletion must be managed
  2. Use an ephemeral resource for supported temporary data + Select resource instead of data when deletion must be managed
  3. Recognize terraform_data as a built-in managed resource + Distinguish locals from remote resource declarations
  4. Understand data source failure on a missing object + Reference data.aws_ami.base.id for a lookup

Explanation

Correct Answer

A:

For the first criterion, 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 store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model; this directly addresses the need to store arbitrary values or trigger replacements without a third-party resource API. For the separate second criterion, 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 store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model; this fulfills the need to make intentional destruction part of Terraform's lifecycle model. Together they cover the independent tasks of store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model without exchanging the responsibilities of these features.

Incorrect Answers

B:

The second measure does meet the make intentional destruction part of Terraform's lifecycle model requirement, but the first is designed for another concern: 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 store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model. That first component is designed to obtain a short-lived value without persisting it in state or plan, which does not accomplish the requested task to store arbitrary values or trigger replacements without a third-party resource API, even though the other measure satisfies make intentional destruction part of Terraform's lifecycle model.

C:

The first measure meets the requirement to store arbitrary values or trigger replacements without a third-party resource API, but its partner serves a different role: 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 store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model. That second component is designed to compute reusable expression results without creating an API object, so the still-missing criterion is to make intentional destruction part of Terraform's lifecycle model, while the first criterion remains store arbitrary values or trigger replacements without a third-party resource API.

D:

The first measure is intended to distinguish a failed lookup from a request to create the missing object: 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 store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model. The second measure is intended to use an attribute returned by a provider data source: The data. address prefix distinguishes a read-only lookup from a managed resource address; its value can feed managed resources without importing the looked-up object; this behavior should be assessed against the concrete need to store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model. Neither is the directly designated method for the separate goals of store arbitrary values or trigger replacements without a third-party resource API and make intentional destruction part of Terraform's lifecycle model in this review.

Question 358

A Terraform rollout has separate acceptance criteria: consume a value explicitly exposed by a child module and reference a computed local value in the same module. Which combined approach directly satisfies the two criteria?

  1. Use module.network.subnet_id + Use local.prefix
  2. Use module.network.subnet_id + Use count.index inside counted blocks
  3. Use direct attribute references to create implicit dependencies + Use local.prefix
  4. Use var.region + Use resource_type.name.attribute

Explanation

Correct Answer

A:

For the first criterion, a caller sees child-module outputs rather than arbitrary internal resources; the output also communicates dependencies and can serve as an interface contract; this behavior should be assessed against the concrete need to consume a value explicitly exposed by a child module and reference a computed local value in the same module; this directly addresses the need to consume a value explicitly exposed by a child module. For the separate second criterion, 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 consume a value explicitly exposed by a child module and reference a computed local value in the same module; this fulfills the need to reference a computed local value in the same module. Together they cover the independent tasks of consume a value explicitly exposed by a child module and reference a computed local value in the same module without exchanging the responsibilities of these features.

Incorrect Answers

B:

The first measure meets the requirement to consume a value explicitly exposed by a child module, but its partner serves a different role: 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 consume a value explicitly exposed by a child module and reference a computed local value in the same module. That second component is designed to identify the zero-based index of the current instance, so the still-missing criterion is to reference a computed local value in the same module, while the first criterion remains consume a value explicitly exposed by a child module.

C:

The second measure does meet the reference a computed local value in the same module requirement, but the first is designed for another concern: 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 consume a value explicitly exposed by a child module and reference a computed local value in the same module. That first component is designed to let Terraform infer safe operation order through data flow, which does not accomplish the requested task to consume a value explicitly exposed by a child module, even though the other measure satisfies reference a computed local value in the same module.

D:

The first measure is intended to read a module input variable inside that module: The var. namespace refers to values supplied through the module's interface; it does not directly fetch provider configuration or remote state; this behavior should be assessed against the concrete need to consume a value explicitly exposed by a child module and reference a computed local value in the same module. The second measure is intended to read a named attribute from a managed resource: 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 consume a value explicitly exposed by a child module and reference a computed local value in the same module. Neither is the directly designated method for the separate goals of consume a value explicitly exposed by a child module and reference a computed local value in the same module in this review.

Question 359

An engineer needs to retrieve a plain scalar output for shell integration as part of a planned migration. Which option is the best fit?

  1. Use terraform output -raw NAME for a string result
  2. Use a child-module output as module.app.endpoint
  3. Set nullable = false for a required non-null variable
  4. Recognize variable scope is per module

Explanation

Correct Answer

A:

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 retrieve a plain scalar output for shell integration. This directly supports the task to retrieve a plain scalar output for shell integration during a maintenance request.

Incorrect Answers

B:

Only declared outputs form the public child-module interface; the caller cannot directly use an internal resource just by knowing its internal name; this behavior should be assessed against the concrete need to retrieve a plain scalar output for shell integration. The distinction matters here: using that mechanism to transfer computed values from a child module to its caller would still leave the objective to retrieve a plain scalar output for shell integration unmet.

C:

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 retrieve a plain scalar output for shell integration. It may support a related workflow, but the question specifically requires the mechanism for retrieve a plain scalar output for shell integration rather than reject explicit null values instead of treating them as ordinary accepted inputs.

D:

A child declares its own inputs and receives values in the module call; variables do not automatically become global across the module tree; this behavior should be assessed against the concrete need to retrieve a plain scalar output for shell integration. The stated requirement is to retrieve a plain scalar output for shell integration, not to avoid reading a root input directly from an unrelated child module; this alternative addresses a different control or phase.

Question 360

A Terraform module defines strongly typed collections. Two independent changes are requested: first, allow an object field to be omitted from a typed input; second, retrieve the first element of an ordered collection. Which pair of measures fulfills both?

  1. Use optional(...) in object attributes + Access a list with var.zones[0]
  2. Use object({ name = string, enabled = bool }) + Access a list with var.zones[0]
  3. Use optional(...) in object attributes + Use type = any sparingly
  4. Use tomap(...) to make a map + Use list(string) for ordered strings
  5. Convert values with tolist(...) + Access a list with var.zones[0]

Explanation

Correct Answer

A:

For the first criterion, 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 allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection; this directly addresses the need to allow an object field to be omitted from a typed input. For the separate second criterion, lists use zero-based positional indices; a set lacks a stable positional index for this purpose; this behavior should be assessed against the concrete need to allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection; this fulfills the need to retrieve the first element of an ordered collection. Together they cover the independent tasks of allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection without exchanging the responsibilities of these features.

Incorrect Answers

B:

The second measure does meet the retrieve the first element of an ordered collection requirement, but the first is designed for another concern: An object defines an exact attribute schema rather than a homogeneous map; terraform checks and may convert compatible input shapes to that contract; this behavior should be assessed against the concrete need to allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection. That first component is designed to specify a named record with different attribute types, which does not accomplish the requested task to allow an object field to be omitted from a typed input, even though the other measure satisfies retrieve the first element of an ordered collection.

C:

The first measure meets the requirement to allow an object field to be omitted from a typed input, but its partner serves a different role: 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 allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection. That second component is designed to permit values of varying shapes where a strict contract is impractical, so the still-missing criterion is to retrieve the first element of an ordered collection, while the first criterion remains allow an object field to be omitted from a typed input.

D:

The first measure is intended to convert a compatible value into a homogeneous keyed collection: Map conversion attempts a common element type for the values; a heterogeneous object may need a more explicit object contract instead; this behavior should be assessed against the concrete need to allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection. The second measure is intended to preserve a sequence in which position and duplicates may matter: Lists have elements of one element type and maintain order; they are appropriate when resource arguments expect an ordered collection; this behavior should be assessed against the concrete need to allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection. Neither is the directly designated method for the separate goals of allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection in this review.

E:

The second measure does meet the retrieve the first element of an ordered collection 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 allow an object field to be omitted from a typed input and retrieve the first element of an ordered collection. 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 allow an object field to be omitted from a typed input, even though the other measure satisfies retrieve the first element of an ordered collection.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests