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

Question 330

A change-control meeting for a root module requires a way to respond to a modified terraform backend block. Which Terraform approach most directly fulfills that request?

  1. terraform init -upgrade for modules
  2. terraform init for a new directory
  3. terraform init -get=false
  4. Re-run init after a backend change

Explanation

Correct Answer

D:

Terraform requires reinitialization to adopt changed backend settings before normal operations continue; this directly meets the requirement to respond to a modified terraform backend block. By comparison, terraform init -get=false is intended to avoid downloading child modules during a narrowly scoped initialization, which is a different task from respond to a modified terraform backend block.

Incorrect Answers

A:

Upgrade tells init to reconsider prior module selections instead of simply reusing previously installed versions; this mechanism is useful when the job is to fetch newer module releases permitted by version constraints, whereas the current scenario requires the engineer to respond to a modified terraform backend block. These operations have different effects in the stated Terraform workflow.

B:

Initialization installs required providers and modules and establishes the working directory's backend configuration; this mechanism is useful when the job is to prepare a folder containing fresh .tf configuration files, whereas the current scenario requires the engineer to respond to a modified terraform backend block. These operations have different effects in the stated Terraform workflow.

C:

The get=false switch skips child module installation, which is generally safe only if module dependencies are already present; this mechanism is useful when the job is to avoid downloading child modules during a narrowly scoped initialization, whereas the current scenario requires the engineer to respond to a modified terraform backend block. These operations have different effects in the stated Terraform workflow.

Question 331

During one infrastructure delivery, the team must satisfy all of the following: (1) report a failed ongoing infrastructure assertion without ordinarily blocking the apply; (2) require a named structure with typed attributes. Select TWO appropriate Terraform approaches. Choose TWO.

  1. terraform validate versus runtime assertions
  2. The check block
  3. tolist conversion
  4. Data source postcondition
  5. An object type

Explanation

Correct Answers

B:

Check assertions evaluate health expectations and normally report warning diagnostics rather than blocking deployment on a false condition; this meets the requirement to report a failed ongoing infrastructure assertion without ordinarily blocking the apply, while the other selected techniques address require a named structure with typed attributes, which require their own distinct Terraform mechanisms.

E:

object({ name = string, size = number }) specifies per-attribute types for a structured input; this meets the requirement to require a named structure with typed attributes, while the other selected techniques address report a failed ongoing infrastructure assertion without ordinarily blocking the apply, which require their own distinct Terraform mechanisms.

Incorrect Answers

A:

Static validate checks structural correctness, while condition expressions may depend on inputs or provider readings evaluated during plan or apply; it addresses distinguish static configuration checks from conditions requiring actual resource values, but this delivery instead requires report a failed ongoing infrastructure assertion without ordinarily blocking the apply and require a named structure with typed attributes. The required combination involves An object type and The check block, not the behavior of terraform validate versus runtime assertions.

C:

tolist converts compatible values to a list, but a source set's original order is not inherently meaningful; it addresses coerce a suitable collection into a list for ordered operations, but this delivery instead requires report a failed ongoing infrastructure assertion without ordinarily blocking the apply and require a named structure with typed attributes. The required combination involves An object type and The check block, not the behavior of tolist conversion.

D:

A postcondition on a data block can validate attributes returned from a provider before downstream resources rely on them; it addresses reject use of queried data when it violates a required invariant, but this delivery instead requires report a failed ongoing infrastructure assertion without ordinarily blocking the apply and require a named structure with typed attributes. The required combination involves An object type and The check block, not the behavior of Data source postcondition.

Question 332

A Terraform runbook prescribes “A pessimistic module version constraint” to control behavioral changes after moving to a new module release, but it does not meet the requirement. What does that step actually accomplish?

  1. A module upgrade can change resource definitions and outputs, so the consumer should inspect the new source and resulting Terraform plan.
  2. A module version ~> 2.1.0 permits 2.1.x releases but excludes 2.2.0 and later.
  3. Provider versions are constrained in required_providers and locked in .terraform.lock.hcl; registry modules use their module block version arguments.
  4. The upgrade mode reselects module versions subject to constraints instead of automatically keeping the previously installed copy.

Explanation

Correct Answer

B:

A pessimistic module version constraint is used when an operator needs to allow compatible patch updates within a module's minor release series. Consequently, this choice cannot meet the separate requirement to control behavioral changes after moving to a new module release. The intended action would instead require Reviewing module upgrade changes.

Incorrect Answers

A:

That outcome belongs to Reviewing module upgrade changes, the mechanism that can control behavioral changes after moving to a new module release. The question concerns the engineer’s actual proposal, A pessimistic module version constraint; it is directed at allow compatible patch updates within a module's minor release series, not that result.

C:

This behavior belongs to Provider and module version separation, which helps engineers avoid confusing provider plugin selection with reusable module source selection rather than satisfying the separate requirement to control behavioral changes after moving to a new module release. The attempted technique was A pessimistic module version constraint; it would instead be used to allow compatible patch updates within a module's minor release series, not to produce the effect associated with Provider and module version separation.

D:

This behavior belongs to Init -upgrade for registry modules, which helps engineers consider newer published module releases already allowed by a version constraint rather than satisfying the separate requirement to control behavioral changes after moving to a new module release. The attempted technique was A pessimistic module version constraint; it would instead be used to allow compatible patch updates within a module's minor release series, not to produce the effect associated with Init -upgrade for registry modules.

Question 333

A build job for a Terraform configuration has a concrete implementation goal: reject a supplied input value that violates a custom validation rule. What is the most appropriate Terraform mechanism?

  1. terraform validate
  2. Validate without live deployment
  3. Variable validation during planning
  4. terraform fmt -check

Explanation

Correct Answer

C:

Variable validation conditions evaluate against actual values when Terraform processes inputs, which is different from only checking syntax; this directly meets the requirement to reject a supplied input value that violates a custom validation rule. By comparison, terraform validate is intended to check that Terraform configuration is structurally valid without planning resource changes, which is a different task from reject a supplied input value that violates a custom validation rule.

Incorrect Answers

A:

The validate command checks syntax and schema consistency in an initialized configuration without obtaining a full execution plan; this mechanism is useful when the job is to check that Terraform configuration is structurally valid without planning resource changes, whereas the current scenario requires the engineer to reject a supplied input value that violates a custom validation rule. These operations have different effects in the stated Terraform workflow.

B:

terraform validate runs offline-oriented configuration checks and does not deploy managed resources; this mechanism is useful when the job is to detect invalid configuration even when no cloud changes should occur, whereas the current scenario requires the engineer to reject a supplied input value that violates a custom validation rule. These operations have different effects in the stated Terraform workflow.

D:

The fmt -check option exits with a failure status when source files would need formatting changes rather than altering them; this mechanism is useful when the job is to verify formatting without rewriting the files in a CI job, whereas the current scenario requires the engineer to reject a supplied input value that violates a custom validation rule. These operations have different effects in the stated Terraform workflow.

Question 334

The team evaluates “terraform plan -replace” for a requirement to force a resource instance to be replaced during planning. Which observed behavior belongs to that mechanism rather than a different Terraform feature?

  1. The -replace=ADDRESS option requests replacement of a particular managed instance even if ordinary change detection would update it in place or do nothing.
  2. In conventional human-readable plans, + signifies that a managed resource is proposed for creation.
  3. Terraform may mark attributes as known after apply because a provider assigns their values only when creating or updating a real object.
  4. The -json flag emits a structured JSON representation suitable for inspection by automation, with careful handling of sensitive output.

Explanation

Correct Answer

A:

The named mechanism is used when the objective is to force a resource instance to be replaced during planning, so it produces the behavior described. In contrast, terraform show -json on a plan serves a different goal: feed a saved plan to a machine-readable analysis tool, not force a resource instance to be replaced during planning.

Incorrect Answers

B:

The description applies to a resource action marked plus when an engineer needs to interpret the leading + symbol in Terraform's plan; the named terraform plan -replace instead handles the requirement to force a resource instance to be replaced during planning, so this behavior does not describe terraform plan -replace in the situation named.

C:

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 -replace instead handles the requirement to force a resource instance to be replaced during planning, so this behavior does not describe terraform plan -replace in the situation named.

D:

The description applies to terraform show -json on a plan when an engineer needs to feed a saved plan to a machine-readable analysis tool; the named terraform plan -replace instead handles the requirement to force a resource instance to be replaced during planning, so this behavior does not describe terraform plan -replace in the situation named.

Question 335

A runbook lists “terraform init -reconfigure” for the task to discard the previously cached backend connection without copying existing state. Which technical effect should its description include?

  1. The backend=false switch suppresses backend setup; commands needing backend access may then be unable to proceed.
  2. Terraform requires reinitialization to adopt changed backend settings before normal operations continue.
  3. Reconfigure tells init to treat the supplied backend configuration as new, rather than performing a state migration.
  4. terraform init is designed to be safely rerun; when requirements are unchanged, it generally keeps existing setup.
  5. Terraform records provider version and checksum selections in its dependency lock file, which teams normally commit to source control.

Explanation

Correct Answer

C:

The named mechanism is used when the objective is to discard the previously cached backend connection without copying existing state, so it produces the behavior described. In contrast, terraform init -backend=false serves a different goal: skip backend initialization during a specialized init operation, not discard the previously cached backend connection without copying existing state.

Incorrect Answers

A:

The description applies to terraform init -backend=false when an engineer needs to skip backend initialization during a specialized init operation; the named terraform init -reconfigure instead handles the requirement to discard the previously cached backend connection without copying existing state, so this behavior does not describe terraform init -reconfigure in the situation named.

B:

The description applies to re-run init after a backend change when an engineer needs to respond to a modified terraform backend block; the named terraform init -reconfigure instead handles the requirement to discard the previously cached backend connection without copying existing state, so this behavior does not describe terraform init -reconfigure in the situation named.

D:

The description applies to repeatable initialization when an engineer needs to run initialization again in an already prepared directory without unnecessary changes; the named terraform init -reconfigure instead handles the requirement to discard the previously cached backend connection without copying existing state, so this behavior does not describe terraform init -reconfigure in the situation named.

E:

The description applies to the .terraform.lock.hcl file when an engineer needs to identify which file should be checked in to preserve selected provider packages; the named terraform init -reconfigure instead handles the requirement to discard the previously cached backend connection without copying existing state, so this behavior does not describe terraform init -reconfigure in the situation named.

Question 336

A platform team separating infrastructure deployments requires a way to use a reviewed configuration revision across separate testing and production states. Which Terraform approach most directly fulfills that request?

  1. A workspace's VCS repository settings
  2. Workspace-specific variables
  3. One state per independently owned system
  4. Environment promotion via workspaces

Explanation

Correct Answer

D:

Workspaces can reference separate branches or release controls while retaining isolated state for each environment; this directly meets the requirement to use a reviewed configuration revision across separate testing and production states. By comparison, a workspace's VCS repository settings is intended to define which configuration branch or directory produces automatic runs, which is a different task from use a reviewed configuration revision across separate testing and production states.

Incorrect Answers

A:

VCS connection details identify the source code changes that should trigger a workspace's Terraform run; this mechanism is useful when the job is to define which configuration branch or directory produces automatic runs, whereas the current scenario requires the engineer to use a reviewed configuration revision across separate testing and production states. These operations have different effects in the stated Terraform workflow.

B:

Workspace settings store variables for that workspace's execution; global sets should not replace environment-specific data blindly; this mechanism is useful when the job is to override or tailor values used by one particular stack, whereas the current scenario requires the engineer to use a reviewed configuration revision across separate testing and production states. These operations have different effects in the stated Terraform workflow.

C:

Separate workspaces allow independent state lifecycles for services that are changed and approved separately; this mechanism is useful when the job is to avoid coupling different teams' deploys into a single state and blast radius, whereas the current scenario requires the engineer to use a reviewed configuration revision across separate testing and production states. These operations have different effects in the stated Terraform workflow.

Question 337

A Terraform reviewer encounters “terraform fmt” while assessing how to apply Terraform's canonical formatting to local .tf source files. Which statement correctly describes its actual behavior?

  1. Applying formatter conventions consistently makes code review focus on meaningful resource and expression edits.
  2. The diff switch displays textual differences between current file formatting and the canonical formatting result.
  3. The fmt command rewrites HCL source according to Terraform's formatting conventions without provisioning resources.
  4. terraform fmt addresses canonical HCL layout while terraform validate checks whether the configuration is structurally acceptable.

Explanation

Correct Answer

C:

The named mechanism is used when the objective is to apply Terraform's canonical formatting to local .tf source files, so it produces the behavior described. In contrast, terraform fmt -diff serves a different goal: show which HCL formatting edits Terraform would make, not apply Terraform's canonical formatting to local .tf source files.

Incorrect Answers

A:

This describes Format before source review and its job to reduce whitespace-only churn in infrastructure pull requests, whereas the question asks about terraform fmt. The latter is the mechanism used to apply Terraform's canonical formatting to local .tf source files; the proposed effect belongs to a different Terraform feature.

B:

The description applies to terraform fmt -diff when an engineer needs to show which HCL formatting edits Terraform would make; the named terraform fmt instead handles the requirement to apply Terraform's canonical formatting to local .tf source files, so this behavior does not describe terraform fmt in the situation named.

D:

The description applies to formatting versus validation when an engineer needs to distinguish style-only issues from Terraform type and schema errors; the named terraform fmt instead handles the requirement to apply Terraform's canonical formatting to local .tf source files, so this behavior does not describe terraform fmt in the situation named.

Question 338

A Terraform change proposal names “Backend state key separation” to store different applications' state snapshots at distinct object paths. Which outcome can reviewers attribute to that particular mechanism?

  1. The terraform cloud block connects configuration to HCP Terraform, and cannot coexist with a standard backend block in the same configuration.
  2. After changing backend configuration, migrate-state attempts to transfer existing state instead of starting with an empty one.
  3. Using distinct backend keys or workspaces creates separate state namespaces instead of letting unrelated root configurations share one snapshot.
  4. The reconfigure flag discards cached previous backend settings and does not copy the prior state snapshot.

Explanation

Correct Answer

C:

The named mechanism is used when the objective is to store different applications' state snapshots at distinct object paths, so it produces the behavior described. In contrast, an HCP Terraform cloud block serves a different goal: integrate Terraform CLI with an HCP organization and workspace, not store different applications' state snapshots at distinct object paths.

Incorrect Answers

A:

The description applies to an HCP Terraform cloud block when an engineer needs to integrate Terraform CLI with an HCP organization and workspace; the named backend state key separation instead handles the requirement to store different applications' state snapshots at distinct object paths, so this behavior does not describe Backend state key separation in the situation named.

B:

The description applies to terraform init -migrate-state when an engineer needs to copy a known working state's snapshot into a new configured backend; the named backend state key separation instead handles the requirement to store different applications' state snapshots at distinct object paths, so this behavior does not describe Backend state key separation in the situation named.

D:

The description applies to terraform init -reconfigure when an engineer needs to switch backend settings without performing automatic state migration; the named backend state key separation instead handles the requirement to store different applications' state snapshots at distinct object paths, so this behavior does not describe Backend state key separation in the situation named.

Question 339

During a design review, the requirement is to document what input callers should supply when using a module. Which option should the engineer select?

  1. The -var option
  2. Passing module inputs explicitly
  3. A variable description
  4. terraform output -json
  5. An auto-loaded .auto.tfvars file
  6. terraform output -raw

Explanation

Correct Answer

C:

Descriptions communicate intended values to users and tooling but do not change evaluation semantics or set defaults; this directly meets the requirement to document what input callers should supply when using a module. By comparison, the -var option is intended to supply a single variable assignment when invoking plan or apply, which is a different task from document what input callers should supply when using a module.

Incorrect Answers

A:

Command-line -var assignments take high precedence and are useful for an explicit run-specific override; this mechanism is useful when the job is to supply a single variable assignment when invoking plan or apply, whereas the current scenario requires the engineer to document what input callers should supply when using a module. These operations have different effects in the stated Terraform workflow.

B:

The module block assigns arguments corresponding to input variables declared in the child; variables are scoped to modules; this mechanism is useful when the job is to configure a child module with parent-provided values, whereas the current scenario requires the engineer to document what input callers should supply when using a module. These operations have different effects in the stated Terraform workflow.

D:

The JSON output mode serializes output values and metadata for automation; it can expose sensitive values and must be protected; this mechanism is useful when the job is to retrieve root outputs for integration with another program, whereas the current scenario requires the engineer to document what input callers should supply when using a module. These operations have different effects in the stated Terraform workflow.

E:

Files ending in .auto.tfvars or .auto.tfvars.json are automatically loaded as root-module input values; this mechanism is useful when the job is to apply extra variable assignments without adding a command-line flag, whereas the current scenario requires the engineer to document what input callers should supply when using a module. These operations have different effects in the stated Terraform workflow.

F:

The -raw output mode prints a single string, number or boolean value in a script-friendly form and may reveal sensitive data; this mechanism is useful when the job is to extract a primitive output without the surrounding formatted representation, whereas the current scenario requires the engineer to document what input callers should supply when using a module. These operations have different effects in the stated Terraform workflow.

Question 340

The team evaluates “Lock release after completion” for a requirement to understand why a normal Terraform operation frees the lock. Which observed behavior belongs to that mechanism rather than a different Terraform feature?

  1. A state backend with locking helps serialize competing changes, complemented by pipeline approval and run coordination.
  2. The -lock=false option bypasses locking safeguards and increases the risk of two runs writing inconsistent state.
  3. A lock may belong to another active run, so check its identity and run status rather than immediately forcing removal.
  4. Terraform obtains and releases supported backend locks around state-sensitive operations; a crash can sometimes leave manual recovery necessary.

Explanation

Correct Answer

D:

The named mechanism is used when the objective is to understand why a normal Terraform operation frees the lock, 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 understand why a normal Terraform operation frees the lock.

Incorrect Answers

A:

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 lock release after completion instead handles the requirement to understand why a normal Terraform operation frees the lock, so this behavior does not describe Lock release after completion in the situation named.

B:

The description applies to not disabling locking for speed when an engineer needs to avoid conflicting state updates during concurrent deployments; the named lock release after completion instead handles the requirement to understand why a normal Terraform operation frees the lock, so this behavior does not describe Lock release after completion in the situation named.

C:

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 lock release after completion instead handles the requirement to understand why a normal Terraform operation frees the lock, so this behavior does not describe Lock release after completion in the situation named.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests