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

Question 660

The team evaluates “Avoid direct state JSON editing” for a requirement to make state changes through supported Terraform commands and declarative refactors. Which observed behavior belongs to that mechanism rather than a different Terraform feature?

  1. The state rm command removes the association so the remote object remains but is no longer tracked by that state.
  2. If a provider reports a tracked object no longer exists, a normal plan generally proposes recreating it when its resource block remains.
  3. Manual state-file changes can break address mappings or serial consistency; commands such as state mv and moved blocks are safer.
  4. The state pull command retrieves state from the configured backend and prints a snapshot that may contain secrets.

Explanation

Correct Answer

C:

The named mechanism is used when the objective is to make state changes through supported Terraform commands and declarative refactors, so it produces the behavior described. In contrast, terraform state rm serves a different goal: forget a managed object without destroying the corresponding real infrastructure, not make state changes through supported Terraform commands and declarative refactors.

Incorrect Answers

A:

The description applies to terraform state rm when an engineer needs to forget a managed object without destroying the corresponding real infrastructure; the named avoid direct state JSON editing instead handles the requirement to make state changes through supported Terraform commands and declarative refactors, so this behavior does not describe Avoid direct state JSON editing in the situation named.

B:

The description applies to a refreshed missing resource when an engineer needs to understand why Terraform proposes creating a managed object deleted outside the workflow; the named avoid direct state JSON editing instead handles the requirement to make state changes through supported Terraform commands and declarative refactors, so this behavior does not describe Avoid direct state JSON editing in the situation named.

D:

The description applies to terraform state pull when an engineer needs to obtain the current state snapshot for inspection or controlled backup; the named avoid direct state JSON editing instead handles the requirement to make state changes through supported Terraform commands and declarative refactors, so this behavior does not describe Avoid direct state JSON editing in the situation named.

Question 661

A declarative resource and expression design has a concrete implementation goal: accept an ordered collection of same-type string values. What is the most appropriate Terraform mechanism?

  1. A list of strings type
  2. A conditional expression
  3. tomap conversion
  4. Avoiding index churn with for_each
  5. The null value

Explanation

Correct Answer

A:

The type constraint list(string) represents ordered string elements and supports numeric indexing, preserving element order; this directly meets the requirement to accept an ordered collection of same-type string values. By comparison, the null value is intended to represent the absence of an optional argument value, which is a different task from accept an ordered collection of same-type string values.

Incorrect Answers

B:

Terraform's condition ? true_value : false_value syntax chooses one branch while reconciling compatible result types; this mechanism is useful when the job is to select between two expression results based on a boolean predicate, whereas the current scenario requires the engineer to accept an ordered collection of same-type string values. These operations have different effects in the stated Terraform workflow.

C:

tomap attempts to convert an input value into a map whose values share a compatible element type; this mechanism is useful when the job is to turn a compatible collection into a uniform-keyed map, whereas the current scenario requires the engineer to accept an ordered collection of same-type string values. These operations have different effects in the stated Terraform workflow.

D:

Keyed for_each instances use stable identifiers, whereas count indexes can shift when list elements are deleted; this mechanism is useful when the job is to preserve instance identity when a middle collection item is removed, whereas the current scenario requires the engineer to accept an ordered collection of same-type string values. These operations have different effects in the stated Terraform workflow.

E:

In supported contexts, setting an optional resource argument to null behaves like leaving that argument unset; this mechanism is useful when the job is to represent the absence of an optional argument value, whereas the current scenario requires the engineer to accept an ordered collection of same-type string values. These operations have different effects in the stated Terraform workflow.

Question 662

A change request asks an engineer to check whether a collection contains a specific element. Which choice best implements the requested behavior?

  1. The contains function
  2. The ternary conditional operator
  3. The jsonencode function
  4. The replace function
  5. The upper function

Explanation

Correct Answer

A:

contains(collection, value) evaluates membership and returns a boolean; this directly meets the requirement to check whether a collection contains a specific element. By comparison, the ternary conditional operator is intended to set a resource argument according to a boolean expression, which is a different task from check whether a collection contains a specific element.

Incorrect Answers

B:

The condition ? value_a : value_b expression chooses a suitable branch without creating duplicate resource blocks; this mechanism is useful when the job is to set a resource argument according to a boolean expression, whereas the current scenario requires the engineer to check whether a collection contains a specific element. These operations have different effects in the stated Terraform workflow.

C:

jsonencode converts Terraform values into JSON representation suitable for API fields expecting JSON text; this mechanism is useful when the job is to serialize a Terraform value into a valid JSON string, whereas the current scenario requires the engineer to check whether a collection contains a specific element. These operations have different effects in the stated Terraform workflow.

D:

replace searches a string for a matching substring or pattern and replaces matches with a new string; this mechanism is useful when the job is to substitute matching substrings within a value, whereas the current scenario requires the engineer to check whether a collection contains a specific element. These operations have different effects in the stated Terraform workflow.

E:

upper transforms the letters of a string into uppercase without changing its underlying Terraform type; this mechanism is useful when the job is to convert an environment label to uppercase, whereas the current scenario requires the engineer to check whether a collection contains a specific element. These operations have different effects in the stated Terraform workflow.

Question 663

A module author evaluates the expression sort(["z", "a", "m"]) with the literal inputs shown. What is the resulting Terraform value?

  1. ["z", "a", "m"]
  2. ["a", "m", "z"]
  3. ["a", "z", "m"]
  4. ["z", "m", "a"]

Explanation

Correct Answer

B:

The expression sort(["z", "a", "m"]) evaluates to ["a", "m", "z"] because sort orders string elements lexicographically in ascending order. This is Terraform's direct evaluation of the supplied literal arguments in sort(["z", "a", "m"]), not an external provider lookup.

Incorrect Answers

A:

The unsorted original list is not the function result. For sort(["z", "a", "m"]), sort orders string elements lexicographically in ascending order; consequently this candidate is not the value Terraform computes.

C:

The m belongs before z in the sorted sequence. HCL evaluates sort(["z", "a", "m"]) using the supplied arguments: sort orders string elements lexicographically in ascending order; the listed result is therefore incorrect.

D:

This is descending rather than ascending lexical order. In this specific evaluation, sort orders string elements lexicographically in ascending order, which rules out the proposed alternative.

Question 664

A runbook lists “terraform init -upgrade” for the task to intentionally reconsider previously locked provider and module selections. Which technical effect should its description include?

  1. The providers lock subcommand updates dependency lock information, including hashes for specified target operating-system platforms.
  2. Terraform uses provider source metadata and its configured installation methods to find and install the appropriate plugin binary.
  3. The -upgrade switch permits newer versions that satisfy constraints instead of preserving current installed or locked selections.
  4. The terraform block's required_version expression constrains which Terraform executable can operate on the configuration.

Explanation

Correct Answer

C:

The named mechanism is used when the objective is to intentionally reconsider previously locked provider and module selections, so it produces the behavior described. In contrast, the required_version setting serves a different goal: restrict the Terraform CLI version rather than a provider plugin, not intentionally reconsider previously locked provider and module selections.

Incorrect Answers

A:

The description applies to terraform providers lock when an engineer needs to populate provider package checksums for selected platforms; the named terraform init -upgrade instead handles the requirement to intentionally reconsider previously locked provider and module selections, so this behavior does not describe terraform init -upgrade in the situation named.

B:

The description applies to provider registry installation when an engineer needs to retrieve a published plugin from its declared registry source; the named terraform init -upgrade instead handles the requirement to intentionally reconsider previously locked provider and module selections, so this behavior does not describe terraform init -upgrade in the situation named.

D:

The description applies to the required_version setting when an engineer needs to restrict the Terraform CLI version rather than a provider plugin; the named terraform init -upgrade instead handles the requirement to intentionally reconsider previously locked provider and module selections, so this behavior does not describe terraform init -upgrade in the situation named.

Question 665

During a design review, the requirement is to combine small modules into a root configuration without producing one giant module. Which option should the engineer select?

  1. Module-level depends_on
  2. A module with count
  3. Avoiding hard-coded child credentials
  4. Module composition

Explanation

Correct Answer

D:

Parent configurations can pass one child module's outputs into another child's inputs to compose larger infrastructure systems; this directly meets the requirement to combine small modules into a root configuration without producing one giant module. By comparison, a module with count is intended to instantiate a fixed number of child module copies, which is a different task from combine small modules into a root configuration without producing one giant module.

Incorrect Answers

A:

depends_on on a module call affects all resources and data sources inside that module and can constrain concurrency; this mechanism is useful when the job is to create an explicit ordering edge for module resources that have a real hidden dependency, whereas the current scenario requires the engineer to combine small modules into a root configuration without producing one giant module. These operations have different effects in the stated Terraform workflow.

B:

The count meta-argument creates numerically indexed module instances such as module.worker[0]; this mechanism is useful when the job is to instantiate a fixed number of child module copies, whereas the current scenario requires the engineer to combine small modules into a root configuration without producing one giant module. These operations have different effects in the stated Terraform workflow.

C:

Reusable modules normally declare provider requirements while callers supply provider configurations and credentials; this mechanism is useful when the job is to keep authentication and deployment-specific region choices outside a reusable child module, whereas the current scenario requires the engineer to combine small modules into a root configuration without producing one giant module. These operations have different effects in the stated Terraform workflow.

Question 666

A Terraform reviewer encounters “terraform state rm” while assessing how to stop tracking a resource without telling its provider to delete the remote object. Which statement correctly describes its actual behavior?

  1. Replace-provider rewrites provider source references in state and creates a backup before the edit.
  2. State show presents one resource's stored attributes in human-readable form and may reveal secret values.
  3. Workspace selection changes which workspace state namespace the root configuration uses; it does not select a cloud account automatically.
  4. State rm deletes the state association, not the object in the external system.
  5. The state list subcommand prints stored addresses without changing infrastructure or state content.

Explanation

Correct Answer

D:

The named mechanism is used when the objective is to stop tracking a resource without telling its provider to delete the remote object, so it produces the behavior described. In contrast, terraform workspace select serves a different goal: switch the currently selected Terraform CLI workspace, not stop tracking a resource without telling its provider to delete the remote object.

Incorrect Answers

A:

The description applies to terraform state replace-provider when an engineer needs to update the provider source address recorded for affected state resources; the named terraform state rm instead handles the requirement to stop tracking a resource without telling its provider to delete the remote object, so this behavior does not describe terraform state rm in the situation named.

B:

The description applies to terraform state show ADDRESS when an engineer needs to view attributes for a specified state-tracked resource instance; the named terraform state rm instead handles the requirement to stop tracking a resource without telling its provider to delete the remote object, so this behavior does not describe terraform state rm in the situation named.

C:

The description applies to terraform workspace select when an engineer needs to switch the currently selected Terraform CLI workspace; the named terraform state rm instead handles the requirement to stop tracking a resource without telling its provider to delete the remote object, so this behavior does not describe terraform state rm in the situation named.

E:

The description applies to terraform state list when an engineer needs to enumerate managed resource instance addresses in the current state; the named terraform state rm instead handles the requirement to stop tracking a resource without telling its provider to delete the remote object, so this behavior does not describe terraform state rm in the situation named.

Question 667

A runbook lists “Input validation versus check blocks” for the task to choose a blocking input constraint rather than a monitoring-style assertion. Which technical effect should its description include?

  1. A precondition inside lifecycle requires a true predicate before Terraform can continue the relevant resource operation.
  2. Terraform may defer condition evaluation to apply when required expression values are unknown during planning.
  3. Variable validation rejects unacceptable values, whereas failed check assertions are intended for diagnostic warnings.
  4. Postconditions validate resultant resource or data-source attributes and prevent dependents from relying on invalid results.

Explanation

Correct Answer

C:

The named mechanism is used when the objective is to choose a blocking input constraint rather than a monitoring-style assertion, so it produces the behavior described. In contrast, custom conditions with unknown values serves a different goal: understand when a validation cannot yet be decided at planning time, not choose a blocking input constraint rather than a monitoring-style assertion.

Incorrect Answers

A:

The description applies to resource precondition when an engineer needs to fail a plan or apply when a prerequisite property is unacceptable; the named input validation versus check blocks instead handles the requirement to choose a blocking input constraint rather than a monitoring-style assertion, so this behavior does not describe Input validation versus check blocks in the situation named.

B:

The description applies to custom conditions with unknown values when an engineer needs to understand when a validation cannot yet be decided at planning time; the named input validation versus check blocks instead handles the requirement to choose a blocking input constraint rather than a monitoring-style assertion, so this behavior does not describe Input validation versus check blocks in the situation named.

D:

The description applies to postconditions for exported IDs when an engineer needs to guard a dependent consumer against a provider result that violates an invariant; the named input validation versus check blocks instead handles the requirement to choose a blocking input constraint rather than a monitoring-style assertion, so this behavior does not describe Input validation versus check blocks in the situation named.

Question 668

A Terraform module author has a concrete implementation goal: ensure a dependent resource waits for the object whose ID it needs. What is the most appropriate Terraform mechanism?

  1. An implicit attribute dependency
  2. A module output reference
  3. Explicit depends_on
  4. each.key

Explanation

Correct Answer

A:

Referencing another managed resource's attribute creates an implicit dependency in Terraform's graph; this directly meets the requirement to ensure a dependent resource waits for the object whose ID it needs. By comparison, a module output reference is intended to use a child module's published value in a parent resource, which is a different task from ensure a dependent resource waits for the object whose ID it needs.

Incorrect Answers

B:

Parent configurations access child outputs using module.CHILD.OUTPUT; private child resource addresses are not automatically exported; this mechanism is useful when the job is to use a child module's published value in a parent resource, whereas the current scenario requires the engineer to ensure a dependent resource waits for the object whose ID it needs. These operations have different effects in the stated Terraform workflow.

C:

The depends_on meta-argument adds dependency edges for a known relationship that Terraform cannot otherwise infer; this mechanism is useful when the job is to order resources when there is a dependency not expressed by attribute references, whereas the current scenario requires the engineer to ensure a dependent resource waits for the object whose ID it needs. These operations have different effects in the stated Terraform workflow.

D:

In a for_each resource block, each.key identifies the current map key or set element for that instance; this mechanism is useful when the job is to refer to the stable key of a for_each resource instance, whereas the current scenario requires the engineer to ensure a dependent resource waits for the object whose ID it needs. These operations have different effects in the stated Terraform workflow.

Question 669

A module author evaluates the expression range(3) with the literal inputs shown. What is the resulting Terraform value?

  1. [1, 2, 3]
  2. [3]
  3. [0, 1, 2, 3]
  4. [0, 1, 2]

Explanation

Correct Answer

D:

The expression range(3) evaluates to [0, 1, 2] because range with one positive argument generates integers beginning at zero up to but excluding three. This is Terraform's direct evaluation of the supplied literal arguments in range(3), not an external provider lookup.

Incorrect Answers

A:

A single-argument range starts at zero, not one. For range(3), range with one positive argument generates integers beginning at zero up to but excluding three; consequently this candidate is not the value Terraform computes.

B:

The argument specifies the end of a sequence, not a singleton value. HCL evaluates range(3) using the supplied arguments: range with one positive argument generates integers beginning at zero up to but excluding three; the listed result is therefore incorrect.

C:

The end value is excluded rather than included. In this specific evaluation, range with one positive argument generates integers beginning at zero up to but excluding three, which rules out the proposed alternative.

Question 670

During an infrastructure design review about how to consider newer published module releases already allowed by a version constraint, a maintainer asks what “Init -upgrade for registry modules” does. Which description is accurate?

  1. The upgrade mode reselects module versions subject to constraints instead of automatically keeping the previously installed copy.
  2. A module upgrade can change resource definitions and outputs, so the consumer should inspect the new source and resulting Terraform plan.
  3. The module version argument accepts version constraints for registry sources and Terraform resolves compatible published releases during init.
  4. A module version constraint such as = 2.1.3 selects only that published version until the requirement changes.
  5. A Git module's ?ref= tag or commit selects a repository revision instead of a registry module version constraint.

Explanation

Correct Answer

A:

The named mechanism is used when the objective is to consider newer published module releases already allowed by a version constraint, so it produces the behavior described. In contrast, a registry module version constraint serves a different goal: select a supported module release range from the registry, not consider newer published module releases already allowed by a version constraint.

Incorrect Answers

B:

The description applies to reviewing module upgrade changes when an engineer needs to control behavioral changes after moving to a new module release; the named init -upgrade for registry modules instead handles the requirement to consider newer published module releases already allowed by a version constraint, so this behavior does not describe Init -upgrade for registry modules in the situation named.

C:

The description applies to a registry module version constraint when an engineer needs to select a supported module release range from the registry; the named init -upgrade for registry modules instead handles the requirement to consider newer published module releases already allowed by a version constraint, so this behavior does not describe Init -upgrade for registry modules in the situation named.

D:

The description applies to a strict registry module pin when an engineer needs to reproduce a vetted module release without automatically selecting a newer one; the named init -upgrade for registry modules instead handles the requirement to consider newer published module releases already allowed by a version constraint, so this behavior does not describe Init -upgrade for registry modules in the situation named.

E:

The description applies to a Git tag pin for a module when an engineer needs to select a specific VCS module release without using a registry version argument; the named init -upgrade for registry modules instead handles the requirement to consider newer published module releases already allowed by a version constraint, so this behavior does not describe Init -upgrade for registry modules in the situation named.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests