Question 390
The immediate Terraform task is to reference a computed local value in the same module. Which method handles that task most directly?
- Use
output to expose child internals intentionally
- Use a
for expression over a resource map
- Use
local.prefix
- Use direct attribute references to create implicit dependencies
Explanation
Correct Answer
C: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 reference a computed local value in the same module. This directly supports the task to reference a computed local value in the same module during a configuration change.
Incorrect Answers
A:An output value makes selected internal attributes available as module.name.output; child resources themselves remain encapsulated behind the module boundary; this behavior should be assessed against the concrete need to reference a computed local value in the same module. The distinction matters here: using that mechanism to create a stable boundary for modules that callers depend on would still leave the objective to reference a computed local value in the same module unmet.
B:A map-oriented expression can iterate keys and values to build a list or map; a legacy list-style splat is not the right accessor for a for_each resource map; this behavior should be assessed against the concrete need to reference a computed local value in the same module. It may support a related workflow, but the question specifically requires the mechanism for reference a computed local value in the same module rather than extract values from instances created with for_each.
D: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 reference a computed local value in the same module. That can be useful when the aim is to let Terraform infer safe operation order through data flow, but it does not directly deliver the requested ability to reference a computed local value in the same module.
Question 391
A Terraform rollout has separate acceptance criteria: prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays. Which combined approach directly satisfies the two criteria?
- Mark an input variable
ephemeral = true + Use terraform.tfvars or *.auto.tfvars
- Mark an input variable
ephemeral = true + Mark a sensitive output sensitive = true
- Pass values through
-var-file=custom.tfvars + Set default for an optional configuration input
- Use a child-module output as
module.app.endpoint + Mark a sensitive output sensitive = true
Explanation
Correct Answer
B:For the first criterion, 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 prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays; this directly addresses the need to prevent a temporary secret from being persisted to state and plan files. For the separate second criterion, sensitive outputs are redacted in typical CLI presentation but remain recoverable from state by authorized readers; a root output is not secure secret storage; this behavior should be assessed against the concrete need to prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays; this fulfills the need to avoid showing a secret output value in normal human-readable CLI displays. Together they cover the independent tasks of prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays without exchanging the responsibilities of these features.
Incorrect Answers
A:The first measure meets the requirement to prevent a temporary secret from being persisted to state and plan files, 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 prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays. That second component is designed to automatically load documented variable files in a root module, so the still-missing criterion is to avoid showing a secret output value in normal human-readable CLI displays, while the first criterion remains prevent a temporary secret from being persisted to state and plan files.
C:The first measure is intended to load named environment inputs that are not automatically discovered: 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 prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays. The second measure is intended to supply a fallback when the caller omits the variable: 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 prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays. Neither is the directly designated method for the separate goals of prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays in this review.
D:The second measure does meet the avoid showing a secret output value in normal human-readable CLI displays requirement, but the first is designed for another concern: 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 prevent a temporary secret from being persisted to state and plan files and avoid showing a secret output value in normal human-readable CLI displays. That first component is designed to transfer computed values from a child module to its caller, which does not accomplish the requested task to prevent a temporary secret from being persisted to state and plan files, even though the other measure satisfies avoid showing a secret output value in normal human-readable CLI displays.
Question 392
An engineer needs to retrieve the first element of an ordered collection as part of an automated release. Which option is the best fit?
- Use
list(string) for ordered strings
- Use
object({ name = string, enabled = bool })
- Access a list with
var.zones[0]
- Use
flatten(...) for nested lists
Explanation
Correct Answer
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 retrieve the first element of an ordered collection. This directly supports the task to retrieve the first element of an ordered collection during an infrastructure audit.
Incorrect Answers
A: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 retrieve the first element of an ordered collection. The stated requirement is to retrieve the first element of an ordered collection, not to preserve a sequence in which position and duplicates may matter; this alternative addresses a different control or phase.
B: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 retrieve the first element of an ordered collection. That can be useful when the aim is to specify a named record with different attribute types, but it does not directly deliver the requested ability to retrieve the first element of an ordered collection.
D: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 retrieve the first element of an ordered collection. It may support a related workflow, but the question specifically requires the mechanism for retrieve the first element of an ordered collection rather than collapse a list of lists into one sequence.
Question 393
A reviewer is assessing Terraform built-in functions and generated nested blocks. The requirement is to assemble a map from paired key and value lists. Which Terraform mechanism directly meets this requirement?
- Use a
dynamic block to generate nested blocks
- Use
[for item in items : item.name]
- Use
zipmap(keys, values)
- Use
length(value) for a collection or string
Explanation
Correct Answer
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 assemble a map from paired key and value lists. This directly supports the task to assemble a map from paired key and value lists during a planned migration.
Incorrect Answers
A: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 assemble a map from paired key and value lists. It may support a related workflow, but the question specifically requires the mechanism for assemble a map from paired key and value lists rather than repeat provider-specific nested blocks from a collection.
B: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 assemble a map from paired key and value lists. The stated requirement is to assemble a map from paired key and value lists, not to transform a collection into a derived list; this alternative addresses a different control or phase.
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 assemble a map from paired key and value lists. The distinction matters here: using that mechanism to measure the number of elements or characters in a value would still leave the objective to assemble a map from paired key and value lists unmet.
Question 394
During a module implementation, one task is to remove dependents before the infrastructure they rely on, while another is to understand why a dependency may also be retained during a replacement. Select the matching pair of techniques.
- Recognize lifecycle arguments are evaluated early + Recognize propagated
create_before_destroy behavior
- Understand destroy order as dependency-aware + Use
replace_triggered_by rather than depends_on for forced rebuilding
- Use
depends_on for a hidden dependency + Recognize propagated create_before_destroy behavior
- Use
replace_triggered_by for resource change coupling + Use graph parallelism for independent resources
- Understand destroy order as dependency-aware + Recognize propagated
create_before_destroy behavior
Explanation
Correct Answer
E:For the first criterion, terraform generally reverses dependency order for teardown; this minimizes failures caused by destroying prerequisites too early; this behavior should be assessed against the concrete need to remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement; this directly addresses the need to remove dependents before the infrastructure they rely on. For the separate second criterion, 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 remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement; this fulfills the need to understand why a dependency may also be retained during a replacement. Together they cover the independent tasks of remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement without exchanging the responsibilities of these features.
Incorrect Answers
A:The second measure does meet the understand why a dependency may also be retained during a replacement requirement, but the first is designed for another concern: These lifecycle settings shape the graph construction stage and typically require literal values; a runtime input cannot freely toggle them as ordinary arguments; this behavior should be assessed against the concrete need to remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement. That first component is designed to avoid dynamic expressions for create_before_destroy and similar rules, which does not accomplish the requested task to remove dependents before the infrastructure they rely on, even though the other measure satisfies understand why a dependency may also be retained during a replacement.
B:The first measure meets the requirement to remove dependents before the infrastructure they rely on, but its partner serves a different role: 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 remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement. That second component is designed to differentiate operation ordering from replacement semantics, so the still-missing criterion is to understand why a dependency may also be retained during a replacement, while the first criterion remains remove dependents before the infrastructure they rely on.
C:The second measure does meet the understand why a dependency may also be retained during a replacement requirement, but the first is designed for another concern: Explicit dependencies model side effects or prerequisites that Terraform cannot infer from values; they may reduce concurrency or defer data-source reads; this behavior should be assessed against the concrete need to remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement. That first component is designed to order operations even when no output attribute is consumed, which does not accomplish the requested task to remove dependents before the infrastructure they rely on, even though the other measure satisfies understand why a dependency may also be retained during a replacement.
D:The first measure is intended to replace a resource when another managed resource or attribute changes: The rule ties replacement to planned actions on managed resources; plain local values do not themselves have planned resource actions; this behavior should be assessed against the concrete need to remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement. The second measure is intended to allow unrelated operations to proceed concurrently: 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 remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement. Neither is the directly designated method for the separate goals of remove dependents before the infrastructure they rely on and understand why a dependency may also be retained during a replacement in this review.
Question 395
A reviewer has to approve a two-part design: tell users which contract failed and why; additionally, stop a deployment when a required assumption fails. Which option pairs the correct mechanisms?
- Use
error_message for actionable custom diagnostics + Use a precondition rather than a check for an unsafe prerequisite
- Use a variable
validation block + Use a check block with assertions
- Use an output
precondition + Use a precondition rather than a check for an unsafe prerequisite
- Use variable validation for valid network prefixes + Use a precondition rather than a check for an unsafe prerequisite
- Use
error_message for actionable custom diagnostics + Use a resource postcondition
Explanation
Correct Answer
A:For the first 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 tell users which contract failed and why and stop a deployment when a required assumption fails; this directly addresses the need to tell users which contract failed and why. For the separate second criterion, blocking conditions are appropriate when continuing could create invalid infrastructure; a check block typically reports a warning and lets operations proceed; this behavior should be assessed against the concrete need to tell users which contract failed and why and stop a deployment when a required assumption fails; this fulfills the need to stop a deployment when a required assumption fails. Together they cover the independent tasks of tell users which contract failed and why and stop a deployment when a required assumption fails without exchanging the responsibilities of these features.
Incorrect Answers
B:The first 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 tell users which contract failed and why and stop a deployment when a required assumption fails. The second measure is intended to monitor an infrastructure invariant and report failed checks without blocking the whole operation: 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 tell users which contract failed and why and stop a deployment when a required assumption fails. Neither is the directly designated method for the separate goals of tell users which contract failed and why and stop a deployment when a required assumption fails in this review.
C:The second measure does meet the stop a deployment when a required assumption fails requirement, but the first is designed for another concern: 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 tell users which contract failed and why and stop a deployment when a required assumption fails. That first component is designed to ensure a module only exposes results that satisfy a contract, which does not accomplish the requested task to tell users which contract failed and why, even though the other measure satisfies stop a deployment when a required assumption fails.
D:The second measure does meet the stop a deployment when a required assumption fails requirement, but the first is designed for another concern: 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 tell users which contract failed and why and stop a deployment when a required assumption fails. That first component is designed to reject malformed or disallowed input before resource creation, which does not accomplish the requested task to tell users which contract failed and why, even though the other measure satisfies stop a deployment when a required assumption fails.
E:The first measure meets the requirement to tell users which contract failed and why, but its partner serves a different role: A lifecycle postcondition checks an expected guarantee and can prevent dependent operations when it fails; it differs from a pre-operation assumption; this behavior should be assessed against the concrete need to tell users which contract failed and why and stop a deployment when a required assumption fails. That second component is designed to verify a property after the relevant resource or data evaluation, so the still-missing criterion is to stop a deployment when a required assumption fails, while the first criterion remains tell users which contract failed and why.
Question 396
A Terraform review separates 2 requirements: (1) restrict display of secret input values in hosted runs; (2) choose secrecy controls based on persistence as well as output redaction. Identify the two features that each directly handle one of those requirements. Choose TWO.
- Mark a secret root output
sensitive = true
- Avoid committing secret
.tfvars values
- Distinguish
ephemeral from sensitive
- Use HCP Terraform sensitive workspace variables
- Use Vault to centralize secret access
Explanation
Correct Answers
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 restrict display of secret input values in hosted runs and choose secrecy controls based on persistence as well as output redaction. This matches the distinct objective to choose secrecy controls based on persistence as well as output redaction; the remaining chosen features address restrict display of secret input values in hosted runs.
D:HCP Terraform offers marked-sensitive variables for workspace runs; their handling is a platform feature, not evidence that every resulting resource attribute is absent from state; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs and choose secrecy controls based on persistence as well as output redaction. This matches the distinct objective to restrict display of secret input values in hosted runs; the remaining chosen features address choose secrecy controls based on persistence as well as output redaction.
Incorrect Answers
A:Output sensitivity masks typical CLI views; authorized state readers and certain machine-readable commands may still reveal the value; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs and choose secrecy controls based on persistence as well as output redaction. Its main application is to avoid normal display of an output carrying sensitive data; the checklist instead asks for restrict display of secret input values in hosted runs; and choose secrecy controls based on persistence as well as output redaction. None of those distinct criteria specifically calls for this alternative.
B:Input files can contain plaintext and are often copied to laptops and CI systems; store sensitive values in a managed secret store or protected execution environment instead; this behavior should be assessed against the concrete need to restrict display of secret input values in hosted runs and choose secrecy controls based on persistence as well as output redaction. Its main application is to prevent credentials from entering source history; the checklist instead asks for restrict display of secret input values in hosted runs; and choose secrecy controls based on persistence as well as output redaction. None of those distinct criteria specifically calls for this alternative.
E: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 restrict display of secret input values in hosted runs and choose secrecy controls based on persistence as well as output redaction. Its main application is to retrieve or distribute sensitive credentials under explicit access policy; the checklist instead asks for restrict display of secret input values in hosted runs; and choose secrecy controls based on persistence as well as output redaction. None of those distinct criteria specifically calls for this alternative.
Question 397
The immediate Terraform task is to avoid mistaking two views of one API object for independent resources. Which method handles that task most directly?
- Select
resource instead of data when deletion must be managed
- Recognize
terraform_data as a built-in managed resource
- Understand data source failure on a missing object
- Keep a data lookup separate from a same-object managed declaration
Explanation
Correct Answer
D:A data source can read attributes but does not change who owns the underlying object; managing and reading one object need careful dependency design to avoid deferred or inconsistent reads; this behavior should be assessed against the concrete need to avoid mistaking two views of one API object for independent resources. This directly supports the task to avoid mistaking two views of one API object for independent resources during a configuration change.
Incorrect Answers
A: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 avoid mistaking two views of one API object for independent resources. The stated requirement is to avoid mistaking two views of one API object for independent resources, not to make intentional destruction part of Terraform's lifecycle model; this alternative addresses a different control or phase.
B: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 avoid mistaking two views of one API object for independent resources. That can be useful when the aim is to store arbitrary values or trigger replacements without a third-party resource API, but it does not directly deliver the requested ability to avoid mistaking two views of one API object for independent resources.
C: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 avoid mistaking two views of one API object for independent resources. The distinction matters here: using that mechanism to distinguish a failed lookup from a request to create the missing object would still leave the objective to avoid mistaking two views of one API object for independent resources unmet.
Question 398
In an automated release, the requested result is to identify the zero-based index of the current instance. What should the engineer select?
- Use
resource_type.name.attribute
- Use
local.prefix
- Use direct attribute references to create implicit dependencies
- Use
count.index inside counted blocks
Explanation
Correct Answer
D:A count meta-argument creates numerically indexed instances. count.index is available in blocks that use count, not as a global value; this behavior should be assessed against the concrete need to identify the zero-based index of the current instance. This directly supports the task to identify the zero-based index of the current instance during a module implementation.
Incorrect Answers
A:The expression resolves through the address and provider schema; terraform sees the dependency and can wait for an unknown computed value until apply; this behavior should be assessed against the concrete need to identify the zero-based index of the current instance. It may support a related workflow, but the question specifically requires the mechanism for identify the zero-based index of the current instance rather than read a named attribute from a managed resource.
B:Local expressions help avoid repeating calculations; each module has its own local namespace; callers cannot directly inspect a child's locals; this behavior should be assessed against the concrete need to identify the zero-based index of the current instance. The stated requirement is to identify the zero-based index of the current instance, not to reference a computed local value in the same module; this alternative addresses a different control or phase.
C:A resource that consumes another's attribute implicitly depends on it; explicit depends_on is unnecessary when the reference already captures the ordering need; this behavior should be assessed against the concrete need to identify the zero-based index of the current instance. That can be useful when the aim is to let Terraform infer safe operation order through data flow, but it does not directly deliver the requested ability to identify the zero-based index of the current instance.
Question 399
An engineer needs to make callers supply a necessary input during planning or applying as part of an automated release. Which option is the best fit?
- Omit
default to require a variable value
- Use
validation inside a variable block
- Define
output for a root result
- Pass values through
-var='name=value'
Explanation
Correct Answer
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 make callers supply a necessary input during planning or applying. This directly supports the task to make callers supply a necessary input during planning or applying during an infrastructure audit.
Incorrect Answers
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 make callers supply a necessary input during planning or applying. It may support a related workflow, but the question specifically requires the mechanism for make callers supply a necessary input during planning or applying rather than reject caller inputs that violate a Boolean rule.
C: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 make callers supply a necessary input during planning or applying. The stated requirement is to make callers supply a necessary input during planning or applying, not to expose a selected computed value after provisioning; this alternative addresses a different control or phase.
D: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. That can be useful when the aim is to set a variable for one CLI operation, but it does not directly deliver the requested ability to make callers supply a necessary input during planning or applying.
Question 400
A configuration review examines list, map, object, tuple, and set semantics. The requirement is to convert a compatible value into a homogeneous keyed collection. Which Terraform mechanism directly meets this requirement?
- Use
tomap(...) to make a map
- Use
tuple([string, number])
- Use
type = any sparingly
- Use
optional(...) in object attributes
Explanation
Correct Answer
A: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 convert a compatible value into a homogeneous keyed collection. This directly supports the task to convert a compatible value into a homogeneous keyed collection during a planned migration.
Incorrect Answers
B:Tuples have a declared type for each position; a list(string) would not preserve the intended mixed-element contract; this behavior should be assessed against the concrete need to convert a compatible value into a homogeneous keyed collection. The distinction matters here: using that mechanism to define a fixed-position sequence with different element types would still leave the objective to convert a compatible value into a homogeneous keyed collection unmet.
C: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 convert a compatible value into a homogeneous keyed collection. It may support a related workflow, but the question specifically requires the mechanism for convert a compatible value into a homogeneous keyed collection rather than permit values of varying shapes where a strict contract is impractical.
D: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 convert a compatible value into a homogeneous keyed collection. The stated requirement is to convert a compatible value into a homogeneous keyed collection, not to allow an object field to be omitted from a typed input; this alternative addresses a different control or phase.