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

Question 460

A reviewer is assessing Terraform built-in functions and generated nested blocks. The team must both exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection. Which paired choice implements those distinct goals?

  1. Add if to a for expression + Use a dynamic block to generate nested blocks
  2. Add if to a for expression + Use ... in a grouped object for expression
  3. Use join(delimiter, list) + Use file(path) to read local text
  4. Use zipmap(keys, values) + Use a dynamic block to generate nested blocks

Explanation

Correct Answer

A:

For the first criterion, 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 exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection; this directly addresses the need to exclude source elements that do not meet a condition. For the separate second criterion, 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 exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection; this fulfills the need to repeat provider-specific nested blocks from a collection. Together they cover the independent tasks of exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection without exchanging the responsibilities of these features.

Incorrect Answers

B:

The first measure meets the requirement to exclude source elements that do not meet a condition, 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 exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection. That second component is designed to collect duplicate output keys into lists instead of reporting collisions, so the still-missing criterion is to repeat provider-specific nested blocks from a collection, while the first criterion remains exclude source elements that do not meet a condition.

C:

The first measure is intended to combine a sequence of strings with a separator: Join forms one string from elements; split performs the reverse direction on a string; this behavior should be assessed against the concrete need to exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection. The second measure is intended to obtain existing UTF-8 file contents during expression evaluation: 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 exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection. Neither is the directly designated method for the separate goals of exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection in this review.

D:

The second measure does meet the repeat provider-specific nested blocks from a collection 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 exclude source elements that do not meet a condition and repeat provider-specific nested blocks from a collection. That first component is designed to assemble a map from paired key and value lists, which does not accomplish the requested task to exclude source elements that do not meet a condition, even though the other measure satisfies repeat provider-specific nested blocks from a collection.

Question 461

A platform team must control dependencies and replacements. The requirement is to exclude selected post-creation attribute differences from update planning. Which Terraform mechanism directly meets this requirement?

  1. Use ignore_changes = [tags]
  2. Use replace_triggered_by rather than depends_on for forced rebuilding
  3. Use create_before_destroy = true
  4. Recognize propagated create_before_destroy behavior

Explanation

Correct Answer

A:

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 exclude selected post-creation attribute differences from update planning. This directly supports the task to exclude selected post-creation attribute differences from update planning during a planned migration.

Incorrect Answers

B:

A dependency establishes when work runs; it does not by itself demand a replacement of an unchanged dependent object; this behavior should be assessed against the concrete need to exclude selected post-creation attribute differences from update planning. The stated requirement is to exclude selected post-creation attribute differences from update planning, not to differentiate operation ordering from replacement semantics; this alternative addresses a different control or phase.

C:

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 exclude selected post-creation attribute differences from update planning. That can be useful when the aim is to request creation of a replacement before deleting the old instance, but it does not directly deliver the requested ability to exclude selected post-creation attribute differences from update planning.

D:

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 exclude selected post-creation attribute differences from update planning. The distinction matters here: using that mechanism to understand why a dependency may also be retained during a replacement would still leave the objective to exclude selected post-creation attribute differences from update planning unmet.

Question 462

During a module implementation, one task is to monitor an infrastructure invariant and report failed checks without blocking the whole operation, while another is to tell users which contract failed and why. Select the matching pair of techniques.

  1. Use a check block with assertions + Use error_message for actionable custom diagnostics
  2. Use variable validation for valid network prefixes + Use a variable validation block
  3. Use a check block with assertions + Use try for optional nested values
  4. Use a resource precondition + Use error_message for actionable custom diagnostics

Explanation

Correct Answer

A:

For the first criterion, 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 monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why; this directly addresses the need to monitor an infrastructure invariant and report failed checks without blocking the whole operation. For the separate second criterion, 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 monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why; this fulfills the need to tell users which contract failed and why. Together they cover the independent tasks of monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why without exchanging the responsibilities of these features.

Incorrect Answers

B:

The first measure is intended to reject malformed or disallowed input before resource creation: Functions like can(cidrhost(...)) can validate address-format assumptions; this is input correctness, distinct from connectivity tests of a deployed network; this behavior should be assessed against the concrete need to monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why. The second measure is intended to reject a malformed module input with a custom message: 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 monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why. Neither is the directly designated method for the separate goals of monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why in this review.

C:

The first measure meets the requirement to monitor an infrastructure invariant and report failed checks without blocking the whole operation, but its partner serves a different role: Try handles dynamic evaluation failures in expressions and can help normalize inputs; it does not itself fail the configuration when the fallback is used; this behavior should be assessed against the concrete need to monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why. That second component is designed to provide a fallback when a dynamic attribute path is absent, so the still-missing criterion is to tell users which contract failed and why, while the first criterion remains monitor an infrastructure invariant and report failed checks without blocking the whole operation.

D:

The second measure does meet the tell users which contract failed and why requirement, but the first is designed for another concern: 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 monitor an infrastructure invariant and report failed checks without blocking the whole operation and tell users which contract failed and why. That first component is designed to verify an assumption before Terraform processes the target resource operation, which does not accomplish the requested task to monitor an infrastructure invariant and report failed checks without blocking the whole operation, even though the other measure satisfies tell users which contract failed and why.

Question 463

A Terraform review separates 2 requirements: (1) avoid embedding long-lived credentials in HCL provider blocks; (2) preserve Terraform's safety indicator for secret-bearing expressions. Identify the two features that each directly handle one of those requirements. Choose TWO.

  1. Use Vault to centralize secret access
  2. Avoid unnecessary nonsensitive(...) calls
  3. Distinguish ephemeral from sensitive
  4. Use environment-based provider authentication when supported
  5. Protect access to remote state

Explanation

Correct Answers

B:

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 avoid embedding long-lived credentials in HCL provider blocks and preserve Terraform's safety indicator for secret-bearing expressions. This matches the distinct objective to preserve Terraform's safety indicator for secret-bearing expressions; the remaining chosen features address avoid embedding long-lived credentials in HCL provider blocks.

D:

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 avoid embedding long-lived credentials in HCL provider blocks and preserve Terraform's safety indicator for secret-bearing expressions. This matches the distinct objective to avoid embedding long-lived credentials in HCL provider blocks; the remaining chosen features address preserve Terraform's safety indicator for secret-bearing expressions.

Incorrect Answers

A:

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 avoid embedding long-lived credentials in HCL provider blocks and preserve Terraform's safety indicator for secret-bearing expressions. Its main application is to retrieve or distribute sensitive credentials under explicit access policy; the checklist instead asks for avoid embedding long-lived credentials in HCL provider blocks; and preserve Terraform's safety indicator for secret-bearing expressions. None of those distinct criteria specifically calls for this alternative.

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 avoid embedding long-lived credentials in HCL provider blocks and preserve Terraform's safety indicator for secret-bearing expressions. Its main application is to choose secrecy controls based on persistence as well as output redaction; the checklist instead asks for avoid embedding long-lived credentials in HCL provider blocks; and preserve Terraform's safety indicator for secret-bearing expressions. None of those distinct criteria specifically calls for this alternative.

E:

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 avoid embedding long-lived credentials in HCL provider blocks and preserve Terraform's safety indicator for secret-bearing expressions. Its main application is to secure resource attributes and possibly persisted secrets; the checklist instead asks for avoid embedding long-lived credentials in HCL provider blocks; and preserve Terraform's safety indicator for secret-bearing expressions. None of those distinct criteria specifically calls for this alternative.

Question 464

In an automated release, the requested result is to automatically load documented variable files in a root module. What should the engineer select?

  1. Omit default to require a variable value
  2. Use validation inside a variable block
  3. Declare variable "name" with a type constraint
  4. Use TF_VAR_name environment variables
  5. Use terraform.tfvars or *.auto.tfvars
  6. Set default for an optional configuration input

Explanation

Correct Answer

E:

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 automatically load documented variable files in a root module. This directly supports the task to automatically load documented variable files in a root module during a module implementation.

Incorrect Answers

A:

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 automatically load documented variable files in a root module. It may support a related workflow, but the question specifically requires the mechanism for automatically load documented variable files in a root module rather than make callers supply a necessary input during planning or applying.

B:

The condition and custom error message give feedback near the module boundary; it is not an HCP policy set or a provider API permission check; this behavior should be assessed against the concrete need to automatically load documented variable files in a root module. The stated requirement is to automatically load documented variable files in a root module, not to reject caller inputs that violate a Boolean rule; this alternative addresses a different control or phase.

C:

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 automatically load documented variable files in a root module. That can be useful when the aim is to enforce the expected shape of a module input, but it does not directly deliver the requested ability to automatically load documented variable files in a root module.

D:

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 automatically load documented variable files in a root module. The distinction matters here: using that mechanism to provide a root input value without writing it in a tfvars file would still leave the objective to automatically load documented variable files in a root module unmet.

F:

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 automatically load documented variable files in a root module. The stated requirement is to automatically load documented variable files in a root module, not to supply a fallback when the caller omits the variable; this alternative addresses a different control or phase.

Question 465

A module author is replacing repetitive HCL with expressions. The requirement is to derive a smaller subnet CIDR from a parent prefix. Which Terraform mechanism directly meets this requirement?

  1. Use alltrue(list_of_bools)
  2. Use ... in a grouped object for expression
  3. Use cidrsubnet(prefix, newbits, netnum)
  4. Use coalesce(a, b, ...)

Explanation

Correct Answer

C:

CIDR functions perform address arithmetic on a known network; they do not create cloud networks or allocate provider resources; this behavior should be assessed against the concrete need to derive a smaller subnet CIDR from a parent prefix. This directly supports the task to derive a smaller subnet CIDR from a parent prefix during a planned migration.

Incorrect Answers

A:

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 derive a smaller subnet CIDR from a parent prefix. That can be useful when the aim is to require every evaluated Boolean in a collection to be true, but it does not directly deliver the requested ability to derive a smaller subnet CIDR from a parent prefix.

B:

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 derive a smaller subnet CIDR from a parent prefix. The distinction matters here: using that mechanism to collect duplicate output keys into lists instead of reporting collisions would still leave the objective to derive a smaller subnet CIDR from a parent prefix unmet.

D:

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 derive a smaller subnet CIDR from a parent prefix. The stated requirement is to derive a smaller subnet CIDR from a parent prefix, not to choose the first non-null and nonempty-string value; this alternative addresses a different control or phase.

Question 466

The immediate Terraform task is to verify an assumption before Terraform processes the target resource operation. Which method handles that task most directly?

  1. Use a resource precondition
  2. Use try for optional nested values
  3. Use a check block with assertions
  4. Use error_message for actionable custom diagnostics

Explanation

Correct Answer

A:

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 verify an assumption before Terraform processes the target resource operation. This directly supports the task to verify an assumption before Terraform processes the target resource operation during a platform review.

Incorrect Answers

B:

Try handles dynamic evaluation failures in expressions and can help normalize inputs; it does not itself fail the configuration when the fallback is used; this behavior should be assessed against the concrete need to verify an assumption before Terraform processes the target resource operation. The stated requirement is to verify an assumption before Terraform processes the target resource operation, not to provide a fallback when a dynamic attribute path is absent; this alternative addresses a different control or phase.

C:

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 verify an assumption before Terraform processes the target resource operation. That can be useful when the aim is to monitor an infrastructure invariant and report failed checks without blocking the whole operation, but it does not directly deliver the requested ability to verify an assumption before Terraform processes the target resource operation.

D:

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 verify an assumption before Terraform processes the target resource operation. The distinction matters here: using that mechanism to tell users which contract failed and why would still leave the objective to verify an assumption before Terraform processes the target resource operation unmet.

Question 467

A Terraform rollout has separate acceptance criteria: preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs. Which combined approach directly satisfies the two criteria?

  1. Avoid unnecessary nonsensitive(...) calls + Distinguish ephemeral from sensitive
  2. Protect access to remote state + Use environment-based provider authentication when supported
  3. Avoid unnecessary nonsensitive(...) calls + Use HCP Terraform sensitive workspace variables
  4. Use Vault to centralize secret access + Use HCP Terraform sensitive workspace variables

Explanation

Correct Answer

C:

For the first criterion, 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 and restrict display of secret input values in hosted runs; this directly addresses the need to preserve Terraform's safety indicator for secret-bearing expressions. For the separate second criterion, 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 preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs; this fulfills the need to restrict display of secret input values in hosted runs. Together they cover the independent tasks of preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure meets the requirement to preserve Terraform's safety indicator for secret-bearing expressions, but its partner serves a different role: 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 and restrict display of secret input values in hosted runs. That second component is designed to choose secrecy controls based on persistence as well as output redaction, so the still-missing criterion is to restrict display of secret input values in hosted runs, while the first criterion remains preserve Terraform's safety indicator for secret-bearing expressions.

B:

The first measure is intended to secure resource attributes and possibly persisted secrets: 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 preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs. The second measure is intended to avoid embedding long-lived credentials in HCL provider blocks: 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 preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs. Neither is the directly designated method for the separate goals of preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs in this review.

D:

The second measure does meet the restrict display of secret input values in hosted runs requirement, but the first is designed for another concern: 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 preserve Terraform's safety indicator for secret-bearing expressions and restrict display of secret input values in hosted runs. That first component is designed to retrieve or distribute sensitive credentials under explicit access policy, which does not accomplish the requested task to preserve Terraform's safety indicator for secret-bearing expressions, even though the other measure satisfies restrict display of secret input values in hosted runs.

Question 468

A reviewer is auditing variable scopes and disclosure behavior. The team must both reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration. Which paired choice implements those distinct goals?

  1. Set nullable = false for a required non-null variable + Declare variable "name" with a type constraint
  2. Use terraform output -json for machine-readable results + Mark an input variable ephemeral = true
  3. Set nullable = false for a required non-null variable + Recognize variable scope is per module
  4. Use validation inside a variable block + Use terraform output -raw NAME for a string result
  5. Set default for an optional configuration input + Use terraform output -raw NAME for a string result
  6. Set nullable = false for a required non-null variable + Use terraform output -raw NAME for a string result

Explanation

Correct Answer

F:

For the first criterion, 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 reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration; this directly addresses the need to reject explicit null values instead of treating them as ordinary accepted inputs. For the separate second criterion, 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 reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration; this fulfills the need to retrieve a plain scalar output for shell integration. Together they cover the independent tasks of reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure meets the requirement to reject explicit null values instead of treating them as ordinary accepted inputs, but its partner serves a different role: 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 reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration. That second component is designed to enforce the expected shape of a module input, so the still-missing criterion is to retrieve a plain scalar output for shell integration, while the first criterion remains reject explicit null values instead of treating them as ordinary accepted inputs.

B:

The first 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 reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration. The second measure is intended to prevent a temporary secret from being persisted to state and plan files: Ephemeral inputs have restricted reference contexts such as provider blocks and write-only arguments; sensitivity by itself does not provide the same omission guarantee; this behavior should be assessed against the concrete need to reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration. Neither is the directly designated method for the separate goals of reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration in this review.

C:

The first measure meets the requirement to reject explicit null values instead of treating them as ordinary accepted inputs, but its partner serves a different role: 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 reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration. That second component is designed to avoid reading a root input directly from an unrelated child module, so the still-missing criterion is to retrieve a plain scalar output for shell integration, while the first criterion remains reject explicit null values instead of treating them as ordinary accepted inputs.

D:

The second measure does meet the retrieve a plain scalar output for shell integration requirement, but the first is designed for another concern: The condition and custom error message give feedback near the module boundary; it is not an HCP policy set or a provider API permission check; this behavior should be assessed against the concrete need to reject explicit null values instead of treating them as ordinary accepted inputs and retrieve a plain scalar output for shell integration. That first component is designed to reject caller inputs that violate a Boolean rule, which does not accomplish the requested task to reject explicit null values instead of treating them as ordinary accepted inputs, even though the other measure satisfies retrieve a plain scalar output for shell integration.

E:

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

Question 469

A developer is transforming collection values. A reviewer must determine how to build a string using a controlled formatting pattern. Which action is the appropriate choice?

  1. Use [for item in items : item.name]
  2. Use cidrsubnet(prefix, newbits, netnum)
  3. Use format("%s-%d", name, number)
  4. Use a conditional condition ? yes : no

Explanation

Correct Answer

C:

Format substitutes values into placeholders; it does not validate whether the resulting identifier is accepted by a cloud provider; this behavior should be assessed against the concrete need to build a string using a controlled formatting pattern. This directly supports the task to build a string using a controlled formatting pattern during a cross-team handoff.

Incorrect Answers

A:

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 build a string using a controlled formatting pattern. The distinction matters here: using that mechanism to transform a collection into a derived list would still leave the objective to build a string using a controlled formatting pattern unmet.

B:

CIDR functions perform address arithmetic on a known network; they do not create cloud networks or allocate provider resources; this behavior should be assessed against the concrete need to build a string using a controlled formatting pattern. It may support a related workflow, but the question specifically requires the mechanism for build a string using a controlled formatting pattern rather than derive a smaller subnet CIDR from a parent prefix.

D:

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 build a string using a controlled formatting pattern. That can be useful when the aim is to select between two expression results based on a Boolean test, but it does not directly deliver the requested ability to build a string using a controlled formatting pattern.

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.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests