Question 1020
A Terraform reviewer encounters “terraform plan -detailed-exitcode” while assessing how to distinguish no changes from proposed changes in automation. Which statement correctly describes its actual behavior?
- Plans show replacement when the provider cannot update a changed property in place; create-before-destroy can change the replacement order.
- Detailed exit codes are 0 for no diff, 2 for a nonempty successful plan and 1 for an error.
- In human-readable plan diffs, ~ indicates that Terraform proposes updating existing resource attributes.
- Terraform may mark attributes as known after apply because a provider assigns their values only when creating or updating a real object.
- Disabling refresh reduces remote reads but can hide drift and produce an inaccurate plan based on stale observations.
Explanation
Correct Answer
B:The named mechanism is used when the objective is to distinguish no changes from proposed changes in automation, so it produces the behavior described. In contrast, a resource action marked tilde serves a different goal: identify an in-place change rather than object recreation, not distinguish no changes from proposed changes in automation.
Incorrect Answers
A:The description applies to a replacement action in the plan when an engineer needs to recognize a destroy-and-create operation for an immutable argument; the named terraform plan -detailed-exitcode instead handles the requirement to distinguish no changes from proposed changes in automation, so this behavior does not describe terraform plan -detailed-exitcode in the situation named.
C:The description applies to a resource action marked tilde when an engineer needs to identify an in-place change rather than object recreation; the named terraform plan -detailed-exitcode instead handles the requirement to distinguish no changes from proposed changes in automation, so this behavior does not describe terraform plan -detailed-exitcode in the situation named.
D:The description applies to an unknown value until apply when an engineer needs to understand why a computed attribute is unavailable in the preview; the named terraform plan -detailed-exitcode instead handles the requirement to distinguish no changes from proposed changes in automation, so this behavior does not describe terraform plan -detailed-exitcode in the situation named.
E:The description applies to terraform plan -refresh=false when an engineer needs to skip routine state refresh for a constrained preview; the named terraform plan -detailed-exitcode instead handles the requirement to distinguish no changes from proposed changes in automation, so this behavior does not describe terraform plan -detailed-exitcode in the situation named.
Question 1021
During one infrastructure delivery, the team must satisfy all of the following: (1) preserve instance identity when a middle collection item is removed; (2) build one delimited string from a list of strings; (3) reject malformed module inputs before provisioning resources. Select THREE appropriate Terraform approaches. Choose THREE.
- A conditional expression
- Avoiding index churn with for_each
- The merge function
- Input variable validation
- Preconditions for external assumptions
- The join function
Explanation
Correct Answers
B:Keyed for_each instances use stable identifiers, whereas count indexes can shift when list elements are deleted; this meets the requirement to preserve instance identity when a middle collection item is removed, while the other selected techniques address build one delimited string from a list of strings and reject malformed module inputs before provisioning resources, which require their own distinct Terraform mechanisms.
D:The validation block uses a condition and a custom error_message to enforce rules on caller-supplied values; this meets the requirement to reject malformed module inputs before provisioning resources, while the other selected techniques address preserve instance identity when a middle collection item is removed and build one delimited string from a list of strings, which require their own distinct Terraform mechanisms.
F:join takes a separator followed by a list and concatenates elements with that separator between them; this meets the requirement to build one delimited string from a list of strings, while the other selected techniques address preserve instance identity when a middle collection item is removed and reject malformed module inputs before provisioning resources, which require their own distinct Terraform mechanisms.
Incorrect Answers
A:Terraform's condition ? true_value : false_value syntax chooses one branch while reconciling compatible result types; it addresses select between two expression results based on a boolean predicate, but this delivery instead requires preserve instance identity when a middle collection item is removed and build one delimited string from a list of strings and reject malformed module inputs before provisioning resources. The required combination involves Avoiding index churn with for_each and The join function and Input variable validation, not the behavior of A conditional expression.
C:merge overlays object or map arguments and chooses the value from the last argument containing a duplicate key; it addresses combine maps with later values overriding earlier keys, but this delivery instead requires preserve instance identity when a middle collection item is removed and build one delimited string from a list of strings and reject malformed module inputs before provisioning resources. The required combination involves Avoiding index churn with for_each and The join function and Input variable validation, not the behavior of The merge function.
E:A precondition can express a domain requirement such as a selected image having an expected property before using it; it addresses guard a resource against prerequisites outside the provider's basic schema, but this delivery instead requires preserve instance identity when a middle collection item is removed and build one delimited string from a list of strings and reject malformed module inputs before provisioning resources. The required combination involves Avoiding index churn with for_each and The join function and Input variable validation, not the behavior of Preconditions for external assumptions.
Question 1022
A provider configuration review requires a way to intentionally reconsider previously locked provider and module selections. Which Terraform approach most directly fulfills that request?
- terraform init -upgrade
- The required_version setting
- A lower-bound provider constraint
- The required_providers block
Explanation
Correct Answer
A:The -upgrade switch permits newer versions that satisfy constraints instead of preserving current installed or locked selections; this directly meets the requirement to intentionally reconsider previously locked provider and module selections. By comparison, the required_providers block is intended to declare where a provider plugin comes from and which versions are acceptable, which is a different task from intentionally reconsider previously locked provider and module selections.
Incorrect Answers
B:The terraform block's required_version expression constrains which Terraform executable can operate on the configuration; this mechanism is useful when the job is to restrict the Terraform CLI version rather than a provider plugin, whereas the current scenario requires the engineer to intentionally reconsider previously locked provider and module selections. These operations have different effects in the stated Terraform workflow.
C:A version requirement such as >= 5.0.0 allows matching later versions but does not cap major-version upgrades; this mechanism is useful when the job is to allow provider releases no older than a tested minimum, whereas the current scenario requires the engineer to intentionally reconsider previously locked provider and module selections. These operations have different effects in the stated Terraform workflow.
D:A required_providers entry maps a local provider name to its source address and version constraint; it does not configure API credentials; this mechanism is useful when the job is to declare where a provider plugin comes from and which versions are acceptable, whereas the current scenario requires the engineer to intentionally reconsider previously locked provider and module selections. These operations have different effects in the stated Terraform workflow.
Question 1023
A root module integrating child modules needs to select a supported module release range from the registry. Which feature or operation is the most direct match?
- A registry module version constraint
- Init after module version change
- A strict registry module pin
- Init -upgrade for registry modules
- Provider and module version separation
Explanation
Correct Answer
A:The module version argument accepts version constraints for registry sources and Terraform resolves compatible published releases during init; this directly meets the requirement to select a supported module release range from the registry. By comparison, provider and module version separation is intended to avoid confusing provider plugin selection with reusable module source selection, which is a different task from select a supported module release range from the registry.
Incorrect Answers
B:Changing a module source or version constraint requires reinitializing to resolve the updated selection; this mechanism is useful when the job is to install a newly allowed child module release after editing its version requirement, whereas the current scenario requires the engineer to select a supported module release range from the registry. These operations have different effects in the stated Terraform workflow.
C:A module version constraint such as = 2.1.3 selects only that published version until the requirement changes; this concerns the task to reproduce a vetted module release without automatically selecting a newer one, not the current need to select a supported module release range from the registry. A A registry module version constraint approach is appropriate here; the substituted A strict registry module pin option does not supply the specified Terraform capability.
D:The upgrade mode reselects module versions subject to constraints instead of automatically keeping the previously installed copy; this mechanism is useful when the job is to consider newer published module releases already allowed by a version constraint, whereas the current scenario requires the engineer to select a supported module release range from the registry. These operations have different effects in the stated Terraform workflow.
E:Provider versions are constrained in required_providers and locked in .terraform.lock.hcl; registry modules use their module block version arguments; this mechanism is useful when the job is to avoid confusing provider plugin selection with reusable module source selection, whereas the current scenario requires the engineer to select a supported module release range from the registry. These operations have different effects in the stated Terraform workflow.
Question 1024
A module author evaluates the expression lookup({dev=2}, "dev", 4) with the literal inputs shown. What is the resulting Terraform value?
- null
- 4
- "dev"
- 2
Explanation
Correct Answer
D:The expression lookup({dev=2}, "dev", 4) evaluates to 2 because the dev key exists, and its value takes precedence over the fallback argument. This is Terraform's direct evaluation of the supplied literal arguments in lookup({dev=2}, "dev", 4), not an external provider lookup.
Incorrect Answers
A:A successful map lookup yields its associated number, not null. In this specific evaluation, the dev key exists, and its value takes precedence over the fallback argument, which rules out the proposed alternative.
B:Fallback values apply only when the requested map key is absent. For lookup({dev=2}, "dev", 4), the dev key exists, and its value takes precedence over the fallback argument; consequently this candidate is not the value Terraform computes.
C:Lookup returns the map value, not the key text. HCL evaluates lookup({dev=2}, "dev", 4) using the supplied arguments: the dev key exists, and its value takes precedence over the fallback argument; the listed result is therefore incorrect.
Question 1025
In a Terraform configuration, what value does the HCL expression format("%s-%02d", "api", 7) evaluate to?
- "7-api"
- "api-07"
- "api-007"
- "api-7"
Explanation
Correct Answer
B:The expression format("%s-%02d", "api", 7) evaluates to "api-07" because the %s placeholder receives api and %02d prints the integer padded to width two with a leading zero. This is Terraform's direct evaluation of the supplied literal arguments in format("%s-%02d", "api", 7), not an external provider lookup.
Incorrect Answers
A:The placeholder order follows the format string from left to right. HCL evaluates format("%s-%02d", "api", 7) using the supplied arguments: the %s placeholder receives api and %02d prints the integer padded to width two with a leading zero; the listed result is therefore incorrect.
C:A width of two calls for a single leading zero, not two. In this specific evaluation, the %s placeholder receives api and %02d prints the integer padded to width two with a leading zero, which rules out the proposed alternative.
D:The zero-pad width of two is not respected here. For format("%s-%02d", "api", 7), the %s placeholder receives api and %02d prints the integer padded to width two with a leading zero; consequently this candidate is not the value Terraform computes.
Question 1026
During a design review, the requirement is to describe the desired infrastructure state instead of scripting every API step. Which option should the engineer select?
- Desired-state reconciliation
- Declarative resource configuration
- State-backed object tracking
- A resource graph
- Version-controlled infrastructure definition
Explanation
Correct Answer
B:Terraform interprets resource declarations, constructs a dependency graph, and asks providers to reconcile real objects with that desired state; this directly meets the requirement to describe the desired infrastructure state instead of scripting every API step. By comparison, desired-state reconciliation is intended to identify changes between the declared configuration and managed infrastructure, which is a different task from describe the desired infrastructure state instead of scripting every API step.
Incorrect Answers
A:Planning compares configuration with state and refreshed remote data to propose actions that reconcile differences; this mechanism is useful when the job is to identify changes between the declared configuration and managed infrastructure, whereas the current scenario requires the engineer to describe the desired infrastructure state instead of scripting every API step. These operations have different effects in the stated Terraform workflow.
C:Terraform state records mappings and attributes needed to compare future plans without rediscovering every object's identity from scratch; this mechanism is useful when the job is to retain the association between a configuration address and its actual managed object, whereas the current scenario requires the engineer to describe the desired infrastructure state instead of scripting every API step. These operations have different effects in the stated Terraform workflow.
D:Terraform derives dependency edges from references, using the graph to order dependent changes and permit safe parallel operations; this mechanism is useful when the job is to determine a safe sequence for creating objects with references between them, whereas the current scenario requires the engineer to describe the desired infrastructure state instead of scripting every API step. These operations have different effects in the stated Terraform workflow.
E:Infrastructure configuration can be committed and reviewed in version control so the intended change is traceable before a Terraform run; this mechanism is useful when the job is to review a proposed infrastructure change before team members deploy it, whereas the current scenario requires the engineer to describe the desired infrastructure state instead of scripting every API step. These operations have different effects in the stated Terraform workflow.
Question 1027
A Terraform reviewer encounters “Not disabling locking for speed” while assessing how to avoid conflicting state updates during concurrent deployments. Which statement correctly describes its actual behavior?
- The -lock=false option bypasses locking safeguards and increases the risk of two runs writing inconsistent state.
- A lock may belong to another active run, so check its identity and run status rather than immediately forcing removal.
- A state backend with locking helps serialize competing changes, complemented by pipeline approval and run coordination.
- The force-unlock command removes a lock by its identifier; using it during an active operation can cause state corruption.
Explanation
Correct Answer
A:The named mechanism is used when the objective is to avoid conflicting state updates during concurrent deployments, so it produces the behavior described. In contrast, lock ownership verification serves a different goal: confirm that a held lock is stale before attempting manual removal, not avoid conflicting state updates during concurrent deployments.
Incorrect Answers
B:The description applies to lock ownership verification when an engineer needs to confirm that a held lock is stale before attempting manual removal; the named not disabling locking for speed instead handles the requirement to avoid conflicting state updates during concurrent deployments, so this behavior does not describe Not disabling locking for speed in the situation named.
C:The description applies to state consistency during CI when an engineer needs to keep two pipelines from changing the same infrastructure state simultaneously; the named not disabling locking for speed instead handles the requirement to avoid conflicting state updates during concurrent deployments, so this behavior does not describe Not disabling locking for speed in the situation named.
D:The description applies to terraform force-unlock when an engineer needs to release a stale lock when the original process is definitively gone; the named not disabling locking for speed instead handles the requirement to avoid conflicting state updates during concurrent deployments, so this behavior does not describe Not disabling locking for speed in the situation named.
Question 1028
A team compares Terraform mechanisms for the goal to make resources use a common account without an explicit provider argument. Which stated consequence belongs specifically to “A default provider configuration”?
- A data block can set provider = aws.secondary to query through an alternate provider configuration.
- An unaliased provider block configures the default instance used by matching resources that do not override provider selection.
- Declare an aliased provider configuration and assign provider = provider_name.alias on resources that need the alternate region.
- Reusable child modules should primarily declare provider requirements and receive configurations from callers rather than embedding fixed credentials.
- The required_providers entry maps the chosen local name to a specific fully qualified provider source address.
Explanation
Correct Answer
B:The named mechanism is used when the objective is to make resources use a common account without an explicit provider argument, so it produces the behavior described. In contrast, explicit provider selection on data blocks serves a different goal: read an object from a secondary account rather than the default account, not make resources use a common account without an explicit provider argument.
Incorrect Answers
A:The description applies to explicit provider selection on data blocks when an engineer needs to read an object from a secondary account rather than the default account; the named a default provider configuration instead handles the requirement to make resources use a common account without an explicit provider argument, so this behavior does not describe A default provider configuration in the situation named.
C:The description applies to an aliased provider instance when an engineer needs to create resources in a second region using the same provider type; the named a default provider configuration instead handles the requirement to make resources use a common account without an explicit provider argument, so this behavior does not describe A default provider configuration in the situation named.
D:The description applies to provider configuration at the root when an engineer needs to supply provider configurations from the root module to reusable child modules; the named a default provider configuration instead handles the requirement to make resources use a common account without an explicit provider argument, so this behavior does not describe A default provider configuration in the situation named.
E:The description applies to provider-local name mapping when an engineer needs to reuse a provider whose source address differs from its short local identifier; the named a default provider configuration instead handles the requirement to make resources use a common account without an explicit provider argument, so this behavior does not describe A default provider configuration in the situation named.
Question 1029
An engineer intends to prevent incompatible provider upgrades from affecting resource handling and is reviewing “Provider version compatibility”. What consequence follows from using it as intended?
- Providers implement resource and data-source schemas plus read, create, update and delete operations for their services.
- A provider's data source reads existing data and exposes attributes without creating or destroying the queried object.
- Version constraints and a shared lock file reduce unintended schema and behavior changes between deployments.
- Terraform Core handles language evaluation, planning and state orchestration while provider plugins execute service-specific operations.
Explanation
Correct Answer
C:The named mechanism is used when the objective is to prevent incompatible provider upgrades from affecting resource handling, so it produces the behavior described. In contrast, provider-defined data sources serves a different goal: read information from an external service without owning its lifecycle, not prevent incompatible provider upgrades from affecting resource handling.
Incorrect Answers
A:The description applies to a provider plugin when an engineer needs to translate Terraform resource operations into calls to the relevant remote API; the named provider version compatibility instead handles the requirement to prevent incompatible provider upgrades from affecting resource handling, so this behavior does not describe Provider version compatibility in the situation named.
B:The description applies to provider-defined data sources when an engineer needs to read information from an external service without owning its lifecycle; the named provider version compatibility instead handles the requirement to prevent incompatible provider upgrades from affecting resource handling, so this behavior does not describe Provider version compatibility in the situation named.
D:The description applies to Terraform Core when an engineer needs to evaluate HCL expressions and calculate a resource dependency graph; the named provider version compatibility instead handles the requirement to prevent incompatible provider upgrades from affecting resource handling, so this behavior does not describe Provider version compatibility in the situation named.
Question 1030
An engineer troubleshooting a .tf configuration needs to retain a remote object but stop Terraform from managing it. Which feature or operation is the most direct match?
- Resource removal without deletion
- A data-source reference
- A resource attribute reference
- Removing a resource declaration
- A data source that depends on a resource
Explanation
Correct Answer
A:A removed block with destroy = false can express a configuration-driven removal from state while leaving the infrastructure object intact; this directly meets the requirement to retain a remote object but stop Terraform from managing it. By comparison, a data source that depends on a resource is intended to delay a lookup until a prerequisite object is available, which is a different task from retain a remote object but stop Terraform from managing it.
Incorrect Answers
B:References to data.TYPE.NAME.attribute retrieve values supplied by a read-only provider data source; this mechanism is useful when the job is to use attributes read from an existing resource when configuring a new managed object, whereas the current scenario requires the engineer to retain a remote object but stop Terraform from managing it. These operations have different effects in the stated Terraform workflow.
C:References like aws_vpc.main.id use a managed resource's attributes and create an implicit dependency; this mechanism is useful when the job is to pass a newly managed object's computed identifier to a dependent resource, whereas the current scenario requires the engineer to retain a remote object but stop Terraform from managing it. These operations have different effects in the stated Terraform workflow.
D:When a managed resource is absent from configuration but still tracked in state, normal planning proposes its destruction; this mechanism is useful when the job is to plan to delete a previously managed object that remains in state, whereas the current scenario requires the engineer to retain a remote object but stop Terraform from managing it. These operations have different effects in the stated Terraform workflow.
E:Data source reads can be deferred during planning when their inputs depend on values not known until apply; this mechanism is useful when the job is to delay a lookup until a prerequisite object is available, whereas the current scenario requires the engineer to retain a remote object but stop Terraform from managing it. These operations have different effects in the stated Terraform workflow.