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

Question 470

An application module needs reliable input and output contracts. The requirement is to set a variable for one CLI operation. Which Terraform mechanism directly meets this requirement?

  1. Use TF_VAR_name environment variables
  2. Mark a variable sensitive = true
  3. Pass values through -var='name=value'
  4. Define output for a root result
  5. Set nullable = false for a required non-null variable

Explanation

Correct Answer

C:

CLI assignments have high precedence among standard CLI variable sources; they do not change the default declaration in source control; this behavior should be assessed against the concrete need to set a variable for one CLI operation. This directly supports the task to set a variable for one CLI operation during a planned migration.

Incorrect Answers

A:

Terraform reads variables with the TF_VAR_ prefix, subject to other higher-precedence input sources; environment variables can still leak in logs or process environments; this behavior should be assessed against the concrete need to set a variable for one CLI operation. That can be useful when the aim is to provide a root input value without writing it in a tfvars file, but it does not directly deliver the requested ability to set a variable for one CLI operation.

B:

The mark affects display and propagation of sensitivity; ordinary sensitive values may still be persisted in state and saved plans; this behavior should be assessed against the concrete need to set a variable for one CLI operation. The distinction matters here: using that mechanism to suppress ordinary disclosure of a secret in Terraform output would still leave the objective to set a variable for one CLI operation unmet.

D:

Outputs provide a documented interface for command output and automation; they can be inspected with terraform output when recorded in state; this behavior should be assessed against the concrete need to set a variable for one CLI operation. The stated requirement is to set a variable for one CLI operation, not to expose a selected computed value after provisioning; this alternative addresses a different control or phase.

E:

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 set a variable for one CLI operation. That can be useful when the aim is to reject explicit null values instead of treating them as ordinary accepted inputs, but it does not directly deliver the requested ability to set a variable for one CLI operation.

Question 471

A reviewer has to approve a two-part design: select between two expression results based on a Boolean test; additionally, build an object keyed by input identifiers. Which option pairs the correct mechanisms?

  1. Use zipmap(keys, values) + Use { for k, v in items : k => v.id }
  2. Use a conditional condition ? yes : no + Use { for k, v in items : k => v.id }
  3. Use a conditional condition ? yes : no + Use templatefile(path, vars)
  4. Use alltrue(list_of_bools) + Use a dynamic block to generate nested blocks

Explanation

Correct Answer

B:

For the first criterion, the conditional expression evaluates a condition to choose a result; its two result arms must have compatible types for Terraform to infer a usable value; this behavior should be assessed against the concrete need to select between two expression results based on a Boolean test and build an object keyed by input identifiers; this directly addresses the need to select between two expression results based on a Boolean test. For the separate second criterion, object-form for expressions produce named entries; duplicate output keys require deliberate grouping rather than silently overwriting an element; this behavior should be assessed against the concrete need to select between two expression results based on a Boolean test and build an object keyed by input identifiers; this fulfills the need to build an object keyed by input identifiers. Together they cover the independent tasks of select between two expression results based on a Boolean test and build an object keyed by input identifiers without exchanging the responsibilities of these features.

Incorrect Answers

A:

The second measure does meet the build an object keyed by input identifiers requirement, but the first is designed for another concern: 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 select between two expression results based on a Boolean test and build an object keyed by input identifiers. That first component is designed to assemble a map from paired key and value lists, which does not accomplish the requested task to select between two expression results based on a Boolean test, even though the other measure satisfies build an object keyed by input identifiers.

C:

The first measure meets the requirement to select between two expression results based on a Boolean test, but its partner serves a different role: The function reads a template and evaluates references using the supplied variable map; it does not execute the rendered text as a shell script by itself; this behavior should be assessed against the concrete need to select between two expression results based on a Boolean test and build an object keyed by input identifiers. That second component is designed to render a local template with named variables, so the still-missing criterion is to build an object keyed by input identifiers, while the first criterion remains select between two expression results based on a Boolean test.

D:

The first measure is intended to require every evaluated Boolean in a collection to be true: 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 select between two expression results based on a Boolean test and build an object keyed by input identifiers. The second measure is intended to repeat provider-specific nested blocks from a collection: Dynamic blocks create nested configuration blocks, not top-level resources or meta-argument blocks; iteration can use for_each inside the dynamic block; this behavior should be assessed against the concrete need to select between two expression results based on a Boolean test and build an object keyed by input identifiers. Neither is the directly designated method for the separate goals of select between two expression results based on a Boolean test and build an object keyed by input identifiers in this review.

Question 472

A CI job injects environment-dependent values. A reviewer must determine how to enforce the expected shape of a module input. Which action is the appropriate choice?

  1. Pass values through -var-file=custom.tfvars
  2. Use a child-module output as module.app.endpoint
  3. Pass values through -var='name=value'
  4. Declare variable "name" with a type constraint
  5. Mark a variable sensitive = true

Explanation

Correct Answer

D:

Input types such as string, list(string), or object(...) describe accepted values; terraform checks the supplied value against this contract; this behavior should be assessed against the concrete need to enforce the expected shape of a module input. This directly supports the task to enforce the expected shape of a module input during a cross-team handoff.

Incorrect Answers

A:

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 enforce the expected shape of a module input. The distinction matters here: using that mechanism to load named environment inputs that are not automatically discovered would still leave the objective to enforce the expected shape of a module input unmet.

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 enforce the expected shape of a module input. It may support a related workflow, but the question specifically requires the mechanism for enforce the expected shape of a module input rather than transfer computed values from a child module to its caller.

C:

CLI assignments have high precedence among standard CLI variable sources; they do not change the default declaration in source control; this behavior should be assessed against the concrete need to enforce the expected shape of a module input. The stated requirement is to enforce the expected shape of a module input, not to set a variable for one CLI operation; this alternative addresses a different control or phase.

E:

The mark affects display and propagation of sensitivity; ordinary sensitive values may still be persisted in state and saved plans; this behavior should be assessed against the concrete need to enforce the expected shape of a module input. The distinction matters here: using that mechanism to suppress ordinary disclosure of a secret in Terraform output would still leave the objective to enforce the expected shape of a module input unmet.

Question 473

A Terraform rollout has separate acceptance criteria: build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions. Which combined approach directly satisfies the two criteria?

  1. Use merge(map1, map2) + Use ... in a grouped object for expression
  2. Use a splat expression items[*].id + Use count for numbered resource instances
  3. Use { for k, v in items : k => v.id } + Use ... in a grouped object for expression
  4. Use { for k, v in items : k => v.id } + Use jsondecode(text)

Explanation

Correct Answer

C:

For the first criterion, object-form for expressions produce named entries; duplicate output keys require deliberate grouping rather than silently overwriting an element; this behavior should be assessed against the concrete need to build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions; this directly addresses the need to build an object keyed by input identifiers. For the separate second criterion, grouping mode aggregates multiple values under the same generated key; ordinary object comprehensions require unique keys; this behavior should be assessed against the concrete need to build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions; this fulfills the need to collect duplicate output keys into lists instead of reporting collisions. Together they cover the independent tasks of build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions without exchanging the responsibilities of these features.

Incorrect Answers

A:

The second measure does meet the collect duplicate output keys into lists instead of reporting collisions 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 build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions. That first component is designed to combine maps with later arguments overriding duplicate keys, which does not accomplish the requested task to build an object keyed by input identifiers, even though the other measure satisfies collect duplicate output keys into lists instead of reporting collisions.

B:

The first measure is intended to collect the same attribute from every list-like object: The [*] form is concise for sequences; map-valued for_each resources usually require a for expression instead; this behavior should be assessed against the concrete need to build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions. The second 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 build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions. Neither is the directly designated method for the separate goals of build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions in this review.

D:

The first measure meets the requirement to build an object keyed by input identifiers, but its partner serves a different role: Decoding returns native expression values; it is not a remote data-source read or a YAML parser; this behavior should be assessed against the concrete need to build an object keyed by input identifiers and collect duplicate output keys into lists instead of reporting collisions. That second component is designed to parse JSON into Terraform lists, objects, numbers, strings, and Booleans, so the still-missing criterion is to collect duplicate output keys into lists instead of reporting collisions, while the first criterion remains build an object keyed by input identifiers.

Question 474

A reviewer has to approve a two-part design: make callers supply a necessary input during planning or applying; additionally, set a variable for one CLI operation. Which option pairs the correct mechanisms?

  1. Omit default to require a variable value + Pass values through -var-file=custom.tfvars
  2. Use terraform output -json for machine-readable results + Pass values through -var='name=value'
  3. Use terraform.tfvars or *.auto.tfvars + Use terraform output -raw NAME for a string result
  4. Set nullable = false for a required non-null variable + Pass values through -var='name=value'
  5. Omit default to require a variable value + Pass values through -var='name=value'

Explanation

Correct Answer

E:

For the first criterion, a variable without a default is required; terraform prompts when interactive input is allowed or reports missing input otherwise; this behavior should be assessed against the concrete need to make callers supply a necessary input during planning or applying and set a variable for one CLI operation; this directly addresses the need to make callers supply a necessary input during planning or applying. For the separate second criterion, cLI assignments have high precedence among standard CLI variable sources; they do not change the default declaration in source control; this behavior should be assessed against the concrete need to make callers supply a necessary input during planning or applying and set a variable for one CLI operation; this fulfills the need to set a variable for one CLI operation. Together they cover the independent tasks of make callers supply a necessary input during planning or applying and set a variable for one CLI operation without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure meets the requirement to make callers supply a necessary input during planning or applying, but its partner serves a different role: 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 make callers supply a necessary input during planning or applying and set a variable for one CLI operation. That second component is designed to load named environment inputs that are not automatically discovered, so the still-missing criterion is to set a variable for one CLI operation, while the first criterion remains make callers supply a necessary input during planning or applying.

B:

The second measure does meet the set a variable for one CLI operation requirement, but the first is designed for another concern: 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 make callers supply a necessary input during planning or applying and set a variable for one CLI operation. That first component is designed to obtain structured output values in scripts, which does not accomplish the requested task to make callers supply a necessary input during planning or applying, even though the other measure satisfies set a variable for one CLI operation.

C:

The first measure is intended to automatically load documented variable files in a root module: 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 make callers supply a necessary input during planning or applying and set a variable for one CLI operation. The second 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 make callers supply a necessary input during planning or applying and set a variable for one CLI operation. Neither is the directly designated method for the separate goals of make callers supply a necessary input during planning or applying and set a variable for one CLI operation in this review.

D:

The second measure does meet the set a variable for one CLI operation 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 make callers supply a necessary input during planning or applying and set a variable for one CLI operation. 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 make callers supply a necessary input during planning or applying, even though the other measure satisfies set a variable for one CLI operation.

Question 475

An engineer needs to choose the first non-null and nonempty-string value as part of a planned migration. Which option is the best fit?

  1. Use coalesce(a, b, ...)
  2. Add if to a for expression
  3. Use templatefile(path, vars)
  4. Use length(value) for a collection or string
  5. Use join(delimiter, list)
  6. Use merge(map1, map2)

Explanation

Correct Answer

A:

Coalesce provides a fallback over suitable scalar values; it does not catch arbitrary expression errors like try; this behavior should be assessed against the concrete need to choose the first non-null and nonempty-string value. This directly supports the task to choose the first non-null and nonempty-string value during a maintenance request.

Incorrect Answers

B:

Filtering occurs while constructing the new collection; it is different from count, which controls the number of resource instances; this behavior should be assessed against the concrete need to choose the first non-null and nonempty-string value. The distinction matters here: using that mechanism to exclude source elements that do not meet a condition would still leave the objective to choose the first non-null and nonempty-string value unmet.

C:

The function reads a template and evaluates references using the supplied variable map; it does not execute the rendered text as a shell script by itself; this behavior should be assessed against the concrete need to choose the first non-null and nonempty-string value. It may support a related workflow, but the question specifically requires the mechanism for choose the first non-null and nonempty-string value rather than render a local template with named variables.

D:

Length works with strings and collections; it does not estimate provisioned resource counts when values are unknown; this behavior should be assessed against the concrete need to choose the first non-null and nonempty-string value. The stated requirement is to choose the first non-null and nonempty-string value, not to measure the number of elements or characters in a value; this alternative addresses a different control or phase.

E:

Join forms one string from elements; split performs the reverse direction on a string; this behavior should be assessed against the concrete need to choose the first non-null and nonempty-string value. That can be useful when the aim is to combine a sequence of strings with a separator, but it does not directly deliver the requested ability to choose the first non-null and nonempty-string value.

F:

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 choose the first non-null and nonempty-string value. The distinction matters here: using that mechanism to combine maps with later arguments overriding duplicate keys would still leave the objective to choose the first non-null and nonempty-string value unmet.

Question 476

A reviewer is assessing Terraform built-in functions and generated nested blocks. Two independent changes are requested: first, create instances keyed by stable identifiers; second, combine maps with later arguments overriding duplicate keys. Which pair of measures fulfills both?

  1. Use length(value) for a collection or string + Use merge(map1, map2)
  2. Use try(expr, fallback) + Use merge(map1, map2)
  3. Use count for numbered resource instances + Use coalesce(a, b, ...)
  4. Use for_each with a map or set of strings + Use jsondecode(text)
  5. Use for_each with a map or set of strings + Use ... in a grouped object for expression
  6. Use for_each with a map or set of strings + Use merge(map1, map2)

Explanation

Correct Answer

F:

For the first criterion, for-each instances use map or set keys in addresses, helping avoid index churn; values must be known before Terraform can choose instance identities; this behavior should be assessed against the concrete need to create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys; this directly addresses the need to create instances keyed by stable identifiers. For the separate second criterion, 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 create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys; this fulfills the need to combine maps with later arguments overriding duplicate keys. Together they cover the independent tasks of create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys without exchanging the responsibilities of these features.

Incorrect Answers

A:

The second measure does meet the combine maps with later arguments overriding duplicate keys requirement, but the first is designed for another concern: Length works with strings and collections; it does not estimate provisioned resource counts when values are unknown; this behavior should be assessed against the concrete need to create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys. That first component is designed to measure the number of elements or characters in a value, which does not accomplish the requested task to create instances keyed by stable identifiers, even though the other measure satisfies combine maps with later arguments overriding duplicate keys.

B:

The second measure does meet the combine maps with later arguments overriding duplicate keys requirement, but the first is designed for another concern: 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 create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys. That first component is designed to recover from dynamic expression errors with an alternative result, which does not accomplish the requested task to create instances keyed by stable identifiers, even though the other measure satisfies combine maps with later arguments overriding duplicate keys.

C:

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 create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys. The second measure is intended to choose the first non-null and nonempty-string value: Coalesce provides a fallback over suitable scalar values; it does not catch arbitrary expression errors like try; this behavior should be assessed against the concrete need to create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys. Neither is the directly designated method for the separate goals of create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys in this review.

D:

The first measure meets the requirement to create instances keyed by stable identifiers, but its partner serves a different role: Decoding returns native expression values; it is not a remote data-source read or a YAML parser; this behavior should be assessed against the concrete need to create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys. That second component is designed to parse JSON into Terraform lists, objects, numbers, strings, and Booleans, so the still-missing criterion is to combine maps with later arguments overriding duplicate keys, while the first criterion remains create instances keyed by stable identifiers.

E:

The first measure meets the requirement to create instances keyed by stable identifiers, but its partner serves a different role: Grouping mode aggregates multiple values under the same generated key; ordinary object comprehensions require unique keys; this behavior should be assessed against the concrete need to create instances keyed by stable identifiers and combine maps with later arguments overriding duplicate keys. That second component is designed to collect duplicate output keys into lists instead of reporting collisions, so the still-missing criterion is to combine maps with later arguments overriding duplicate keys, while the first criterion remains create instances keyed by stable identifiers.

Question 477

A module author is replacing repetitive HCL with expressions. A reviewer must determine how to substitute matching text or patterns in a string. Which action is the appropriate choice?

  1. Use contains(collection, value)
  2. Use replace(text, old, new)
  3. Use jsondecode(text)
  4. Use length(value) for a collection or string
  5. Use split(delimiter, string)

Explanation

Correct Answer

B:

Replace performs value transformation during evaluation; it does not trigger replacement of a managed resource by itself; this behavior should be assessed against the concrete need to substitute matching text or patterns in a string. This directly supports the task to substitute matching text or patterns in a string during a staged rollout.

Incorrect Answers

A:

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 substitute matching text or patterns in a string. It may support a related workflow, but the question specifically requires the mechanism for substitute matching text or patterns in a string rather than test whether a collection includes a particular element.

C:

Decoding returns native expression values; it is not a remote data-source read or a YAML parser; this behavior should be assessed against the concrete need to substitute matching text or patterns in a string. That can be useful when the aim is to parse JSON into Terraform lists, objects, numbers, strings, and Booleans, but it does not directly deliver the requested ability to substitute matching text or patterns in a string.

D:

Length works with strings and collections; it does not estimate provisioned resource counts when values are unknown; this behavior should be assessed against the concrete need to substitute matching text or patterns in a string. The distinction matters here: using that mechanism to measure the number of elements or characters in a value would still leave the objective to substitute matching text or patterns in a string unmet.

E:

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 substitute matching text or patterns in a string. It may support a related workflow, but the question specifically requires the mechanism for substitute matching text or patterns in a string rather than divide text into a list around a separator.

Question 478

The immediate Terraform task is to create every ordered combination across two input collections. Which method handles that task most directly?

  1. Use length(value) for a collection or string
  2. Use can(expr)
  3. Use zipmap(keys, values)
  4. Use setproduct(a, b)
  5. Use [for item in items : item.name]

Explanation

Correct Answer

D:

Setproduct computes the Cartesian product, useful for pairing environments and roles; it is not an alternative to the resource dependency graph; this behavior should be assessed against the concrete need to create every ordered combination across two input collections. This directly supports the task to create every ordered combination across two input collections during a configuration change.

Incorrect Answers

A:

Length works with strings and collections; it does not estimate provisioned resource counts when values are unknown; this behavior should be assessed against the concrete need to create every ordered combination across two input collections. The stated requirement is to create every ordered combination across two input collections, not to measure the number of elements or characters in a value; this alternative addresses a different control or phase.

B:

Can returns a Boolean and is especially useful in custom validation rules; it does not return the underlying expression's successful value; this behavior should be assessed against the concrete need to create every ordered combination across two input collections. That can be useful when the aim is to test whether an expression can be evaluated without an error, but it does not directly deliver the requested ability to create every ordered combination across two input collections.

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 create every ordered combination across two input collections. The distinction matters here: using that mechanism to assemble a map from paired key and value lists would still leave the objective to create every ordered combination across two input collections unmet.

E:

A for expression iterates input elements and constructs values without declaring extra managed resources; it can also filter elements using an if clause; this behavior should be assessed against the concrete need to create every ordered combination across two input collections. The stated requirement is to create every ordered combination across two input collections, not to transform a collection into a derived list; this alternative addresses a different control or phase.

Question 479

A Terraform rollout has separate acceptance criteria: parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation. Which combined approach directly satisfies the two criteria?

  1. Use a dynamic block to generate nested blocks + Use file(path) to read local text
  2. Use jsondecode(text) + Use file(path) to read local text
  3. Use count for numbered resource instances + Use file(path) to read local text
  4. Use split(delimiter, string) + Use [for item in items : item.name]
  5. Use jsondecode(text) + Use distinct(list)

Explanation

Correct Answer

B:

For the first criterion, decoding returns native expression values; it is not a remote data-source read or a YAML parser; this behavior should be assessed against the concrete need to parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation; this directly addresses the need to parse JSON into Terraform lists, objects, numbers, strings, and Booleans. For the separate second criterion, file reads files present when evaluation starts; it is not a dependency-aware way to read a file that a resource will create during apply; this behavior should be assessed against the concrete need to parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation; this fulfills the need to obtain existing UTF-8 file contents during expression evaluation. Together they cover the independent tasks of parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation without exchanging the responsibilities of these features.

Incorrect Answers

A:

The second measure does meet the obtain existing UTF-8 file contents during expression evaluation requirement, but the first is designed for another concern: Dynamic blocks create nested configuration blocks, not top-level resources or meta-argument blocks; iteration can use for_each inside the dynamic block; this behavior should be assessed against the concrete need to parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation. That first component is designed to repeat provider-specific nested blocks from a collection, which does not accomplish the requested task to parse JSON into Terraform lists, objects, numbers, strings, and Booleans, even though the other measure satisfies obtain existing UTF-8 file contents during expression evaluation.

C:

The second measure does meet the obtain existing UTF-8 file contents during expression evaluation requirement, but the first is designed for another concern: 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 parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation. That first component is designed to create a known number of repeated managed resource instances, which does not accomplish the requested task to parse JSON into Terraform lists, objects, numbers, strings, and Booleans, even though the other measure satisfies obtain existing UTF-8 file contents during expression evaluation.

D:

The first 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 parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation. The second measure is intended to transform a collection into a derived list: A for expression iterates input elements and constructs values without declaring extra managed resources; it can also filter elements using an if clause; this behavior should be assessed against the concrete need to parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation. Neither is the directly designated method for the separate goals of parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation in this review.

E:

The first measure meets the requirement to parse JSON into Terraform lists, objects, numbers, strings, and Booleans, but its partner serves a different role: 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 parse JSON into Terraform lists, objects, numbers, strings, and Booleans and obtain existing UTF-8 file contents during expression evaluation. That second component is designed to remove duplicate list elements while preserving first occurrence order, so the still-missing criterion is to obtain existing UTF-8 file contents during expression evaluation, while the first criterion remains parse JSON into Terraform lists, objects, numbers, strings, and Booleans.

Question 480

An engineer needs to require every evaluated Boolean in a collection to be true as part of an automated release. Which option is the best fit?

  1. Use try(expr, fallback)
  2. Use alltrue(list_of_bools)
  3. Use lookup(map, key, default)
  4. Use templatefile(path, vars)
  5. Use split(delimiter, string)

Explanation

Correct Answer

B:

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 require every evaluated Boolean in a collection to be true. This directly supports the task to require every evaluated Boolean in a collection to be true during an infrastructure audit.

Incorrect Answers

A:

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 require every evaluated Boolean in a collection to be true. The distinction matters here: using that mechanism to recover from dynamic expression errors with an alternative result would still leave the objective to require every evaluated Boolean in a collection to be true unmet.

C:

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 require every evaluated Boolean in a collection to be true. The stated requirement is to require every evaluated Boolean in a collection to be true, not to obtain a map entry with a fallback for an absent key; this alternative addresses a different control or phase.

D:

The function reads a template and evaluates references using the supplied variable map; it does not execute the rendered text as a shell script by itself; this behavior should be assessed against the concrete need to require every evaluated Boolean in a collection to be true. That can be useful when the aim is to render a local template with named variables, but it does not directly deliver the requested ability to require every evaluated Boolean in a collection to be true.

E:

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 require every evaluated Boolean in a collection to be true. The distinction matters here: using that mechanism to divide text into a list around a separator would still leave the objective to require every evaluated Boolean in a collection to be true unmet.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests