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

Question 200

A pull request contains inconsistent Terraform formatting. A reviewer must determine how to detect files whose formatting differs from Terraform conventions. Which action is the appropriate choice?

  1. Avoid treating formatting as infrastructure planning
  2. Separate fmt from provider installation
  3. Run terraform fmt -check in CI
  4. Apply style checks to module directories

Explanation

Correct Answer

C:

Check mode reports whether formatting changes are needed and can fail a pipeline; it does not itself rewrite source files; this behavior should be assessed against the concrete need to detect files whose formatting differs from Terraform conventions. This directly supports the task to detect files whose formatting differs from Terraform conventions during a staged rollout.

Incorrect Answers

A:

A formatted file must still be evaluated by terraform plan to reveal resource changes; formatting commands do not contact APIs to execute changes; this behavior should be assessed against the concrete need to detect files whose formatting differs from Terraform conventions. It may support a related workflow, but the question specifically requires the mechanism for detect files whose formatting differs from Terraform conventions rather than recognize that whitespace changes are not a plan for cloud operations.

B:

Formatting reads local HCL and does not initialize backends or download provider packages; dependency preparation remains the role of init; this behavior should be assessed against the concrete need to detect files whose formatting differs from Terraform conventions. The stated requirement is to detect files whose formatting differs from Terraform conventions, not to avoid expecting style normalization to fetch plugin binaries; this alternative addresses a different control or phase.

D:

Module source code is Terraform configuration and can be formatted with the same tool; formatting never pins which module release is used; this behavior should be assessed against the concrete need to detect files whose formatting differs from Terraform conventions. The distinction matters here: using that mechanism to enforce a consistent codebase without changing module behavior would still leave the objective to detect files whose formatting differs from Terraform conventions unmet.

Question 201

A new engineer is learning the operational workflow. A reviewer must determine how to execute the actions Terraform has selected for managed infrastructure. Which action is the appropriate choice?

  1. Review results with a follow-up plan
  2. Apply reviewed changes with terraform apply
  3. Use version control alongside the workflow
  4. Preview changes with terraform plan
  5. Write the desired configuration first
  6. Validate configuration before requesting a plan

Explanation

Correct Answer

B:

Apply coordinates provider operations and updates state after effects are known; it needs valid authentication and can still fail if the API rejects an operation; this behavior should be assessed against the concrete need to execute the actions Terraform has selected for managed infrastructure. This directly supports the task to execute the actions Terraform has selected for managed infrastructure during a cross-team handoff.

Incorrect Answers

A:

When inputs and real infrastructure are unchanged, a later normal plan generally shows no changes; a follow-up plan can also detect external drift; this behavior should be assessed against the concrete need to execute the actions Terraform has selected for managed infrastructure. The distinction matters here: using that mechanism to verify convergence after a completed deployment would still leave the objective to execute the actions Terraform has selected for managed infrastructure unmet.

C:

Git captures code changes and supports peer review; Terraform state and provider API results remain separate operational concerns; this behavior should be assessed against the concrete need to execute the actions Terraform has selected for managed infrastructure. The stated requirement is to execute the actions Terraform has selected for managed infrastructure, not to make infrastructure edits traceable and reviewable; this alternative addresses a different control or phase.

D:

Planning compares desired configuration with current state and provider observations; no planned infrastructure actions are applied by the plan command; this behavior should be assessed against the concrete need to execute the actions Terraform has selected for managed infrastructure. That can be useful when the aim is to inspect intended create, change, and delete actions before execution, but it does not directly deliver the requested ability to execute the actions Terraform has selected for managed infrastructure.

E:

Resource blocks, variables, and modules define the target arrangement; running the CLI without an intended configuration cannot infer a team's architecture goals; this behavior should be assessed against the concrete need to execute the actions Terraform has selected for managed infrastructure. The distinction matters here: using that mechanism to establish the intended infrastructure before Terraform evaluates changes would still leave the objective to execute the actions Terraform has selected for managed infrastructure unmet.

F:

Validation checks the HCL configuration against available schemas; it is useful in CI but cannot replace a plan based on actual state and provider data; this behavior should be assessed against the concrete need to execute the actions Terraform has selected for managed infrastructure. It may support a related workflow, but the question specifically requires the mechanism for execute the actions Terraform has selected for managed infrastructure rather than identify structural issues early in a workflow.

Question 202

A reviewer has to approve a two-part design: disallow interactive answers during initialization; additionally, enforce a committed provider selection without lockfile edits. Which option pairs the correct mechanisms?

  1. Use terraform init -input=false in automation + Use terraform init -reconfigure
  2. Use terraform init -input=false in automation + Use terraform init -lockfile=readonly
  3. Use terraform init -backend=false cautiously + Reinitialize after changing provider requirements
  4. Use terraform init -get=false + Use terraform init -lockfile=readonly

Explanation

Correct Answer

B:

For the first criterion, noninteractive jobs fail instead of waiting for a prompt when required values cannot be supplied; this supports predictable CI behavior; this behavior should be assessed against the concrete need to disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits; this directly addresses the need to disallow interactive answers during initialization. For the separate second criterion, read-only dependency locking catches selection drift in automated builds; the lock file applies to providers rather than pinning arbitrary local module directories; this behavior should be assessed against the concrete need to disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits; this fulfills the need to enforce a committed provider selection without lockfile edits. Together they cover the independent tasks of disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits without exchanging the responsibilities of these features.

Incorrect Answers

A:

The first measure meets the requirement to disallow interactive answers during initialization, but its partner serves a different role: Reconfiguration initializes the directory against the new backend settings; it is not a replacement for migrating state that must be preserved; this behavior should be assessed against the concrete need to disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits. That second component is designed to discard the previously remembered backend configuration without migrating state, so the still-missing criterion is to enforce a committed provider selection without lockfile edits, while the first criterion remains disallow interactive answers during initialization.

C:

The first measure is intended to skip backend initialization for a specific preparation task: Disabling backend setup avoids configuring remote state, but some later operations require an initialized backend; it does not create a temporary safe state automatically; this behavior should be assessed against the concrete need to disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits. The second measure is intended to pick up new dependencies and version constraints: Init reconciles the plugin installation and lock selections after changes in required_providers; running only fmt cannot install a newly required plugin; this behavior should be assessed against the concrete need to disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits. Neither is the directly designated method for the separate goals of disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits in this review.

D:

The second measure does meet the enforce a committed provider selection without lockfile edits requirement, but the first is designed for another concern: This option avoids module download/update during initialization; it is appropriate only when required modules are already available; this behavior should be assessed against the concrete need to disallow interactive answers during initialization and enforce a committed provider selection without lockfile edits. That first component is designed to skip installing child modules in a prepared directory, which does not accomplish the requested task to disallow interactive answers during initialization, even though the other measure satisfies enforce a committed provider selection without lockfile edits.

Question 203

During an infrastructure audit, the team must accomplish all of these distinct aims: (1) enforce environment-specific prerequisites that static validation cannot prove; (2) avoid inferring a successful future apply from successful static checks. Select exactly the two relevant mechanisms. Choose TWO.

  1. Use terraform fmt -check for formatting enforcement
  2. Check expression references for validity
  3. Use preconditions for runtime assumptions
  4. Recognize provider schema validation
  5. Use variable validation for input contracts
  6. Interpret a clean validate as limited assurance

Explanation

Correct Answers

C:

A lifecycle precondition can validate context-dependent values before acting on a resource; a general syntax check alone cannot confirm runtime facts; this behavior should be assessed against the concrete need to enforce environment-specific prerequisites that static validation cannot prove and avoid inferring a successful future apply from successful static checks. This matches the distinct objective to enforce environment-specific prerequisites that static validation cannot prove; the remaining chosen features address avoid inferring a successful future apply from successful static checks.

F:

Provider API authorization, remote conflicts, and real infrastructure drift can still produce failures; validation checks supported configuration structure rather than deployment success; this behavior should be assessed against the concrete need to enforce environment-specific prerequisites that static validation cannot prove and avoid inferring a successful future apply from successful static checks. This matches the distinct objective to avoid inferring a successful future apply from successful static checks; the remaining chosen features address enforce environment-specific prerequisites that static validation cannot prove.

Incorrect Answers

A:

fmt -check exits nonzero when files need canonical formatting; it is a style check, not a replacement for Terraform semantic validation; this behavior should be assessed against the concrete need to enforce environment-specific prerequisites that static validation cannot prove and avoid inferring a successful future apply from successful static checks. Its main application is to detect code style deviations without rewriting files; the checklist instead asks for enforce environment-specific prerequisites that static validation cannot prove; and avoid inferring a successful future apply from successful static checks. None of those distinct criteria specifically calls for this alternative.

B:

Terraform validates the structure of expressions against known configuration objects; values only resolved by providers may remain unknown until later phases; this behavior should be assessed against the concrete need to enforce environment-specific prerequisites that static validation cannot prove and avoid inferring a successful future apply from successful static checks. Its main application is to catch references to undeclared blocks and invalid attributes where detectable; the checklist instead asks for enforce environment-specific prerequisites that static validation cannot prove; and avoid inferring a successful future apply from successful static checks. None of those distinct criteria specifically calls for this alternative.

D:

Provider plugins supply schemas used for structural checking; passing validation does not mean the remote API will accept every eventual requested operation; this behavior should be assessed against the concrete need to enforce environment-specific prerequisites that static validation cannot prove and avoid inferring a successful future apply from successful static checks. Its main application is to detect unsupported resource arguments or incorrect types; the checklist instead asks for enforce environment-specific prerequisites that static validation cannot prove; and avoid inferring a successful future apply from successful static checks. None of those distinct criteria specifically calls for this alternative.

E:

The validation rule belongs to the variable declaration and returns a Boolean; it is distinct from the CLI's whole-configuration validation subcommand; this behavior should be assessed against the concrete need to enforce environment-specific prerequisites that static validation cannot prove and avoid inferring a successful future apply from successful static checks. Its main application is to reject invalid user-supplied values with a targeted message; the checklist instead asks for enforce environment-specific prerequisites that static validation cannot prove; and avoid inferring a successful future apply from successful static checks. None of those distinct criteria specifically calls for this alternative.

Question 204

An engineer needs to preview the actions needed to reconcile the declared configuration as part of a planned migration. Which option is the best fit?

  1. Read ~ as in-place update intent
  2. Use terraform show -json tfplan
  3. Run terraform plan without applying
  4. Use terraform plan -replace=ADDRESS

Explanation

Correct Answer

C:

Plan evaluates dependencies and current state and reports create/update/replace/delete intentions; it normally performs no desired resource changes; this behavior should be assessed against the concrete need to preview the actions needed to reconcile the declared configuration. This directly supports the task to preview the actions needed to reconcile the declared configuration during a maintenance request.

Incorrect Answers

A:

The plan symbol indicates updating a tracked resource without replacing its identity; whether a particular field supports this depends on the provider; this behavior should be assessed against the concrete need to preview the actions needed to reconcile the declared configuration. It may support a related workflow, but the question specifically requires the mechanism for preview the actions needed to reconcile the declared configuration rather than distinguish modification of an existing object from creation or destruction.

B:

JSON output exposes structured planned values and actions; the output can contain sensitive values even when terminal formatting hides them; this behavior should be assessed against the concrete need to preview the actions needed to reconcile the declared configuration. The stated requirement is to preview the actions needed to reconcile the declared configuration, not to export machine-readable plan details for a policy tool; this alternative addresses a different control or phase.

D:

The flag adds a replacement instruction to planning for an addressed resource; it is preferable to legacy manual taint workflows for deliberate replacement; this behavior should be assessed against the concrete need to preview the actions needed to reconcile the declared configuration. The distinction matters here: using that mechanism to request replacement of a particular managed instance would still leave the objective to preview the actions needed to reconcile the declared configuration unmet.

Question 205

A deployment script must avoid unintended interactive prompts. The requirement is to execute the exact plan artifact rather than replan with new input values. Which Terraform mechanism directly meets this requirement?

  1. Run terraform apply to execute current configuration
  2. Keep sensitive saved plans secure
  3. Run terraform apply tfplan for an approved saved plan
  4. Use terraform apply -input=false in unattended execution

Explanation

Correct Answer

C:

Applying a saved plan uses its captured decisions and state assumptions; a changed state can invalidate it instead of silently applying a different plan; this behavior should be assessed against the concrete need to execute the exact plan artifact rather than replan with new input values. This directly supports the task to execute the exact plan artifact rather than replan with new input values during an automated release.

Incorrect Answers

A:

Without a saved plan argument, apply creates a plan and normally requests approval before performing it; provider APIs then implement the proposed operations; this behavior should be assessed against the concrete need to execute the exact plan artifact rather than replan with new input values. The distinction matters here: using that mechanism to generate and carry out the necessary actions for managed infrastructure would still leave the objective to execute the exact plan artifact rather than replan with new input values unmet.

B:

Plan files are not sanitized public reports; their embedded values and backend details require protective storage and restricted access; this behavior should be assessed against the concrete need to execute the exact plan artifact rather than replan with new input values. It may support a related workflow, but the question specifically requires the mechanism for execute the exact plan artifact rather than replan with new input values rather than avoid leaking provider settings and input values through artifacts.

D:

The run fails if required input cannot be obtained in noninteractive mode; this avoids jobs hanging on missing variables; this behavior should be assessed against the concrete need to execute the exact plan artifact rather than replan with new input values. That can be useful when the aim is to prevent the run from waiting for interactive variable input, but it does not directly deliver the requested ability to execute the exact plan artifact rather than replan with new input values.

Question 206

A retired lab environment must be removed. A reviewer must determine how to recognize a guard against destructive changes while the resource block remains configured. Which action is the appropriate choice?

  1. Remove a resource from state without destroying it
  2. Preserve required records before teardown
  3. Understand prevent_destroy during planned deletion
  4. Inspect dependencies during teardown

Explanation

Correct Answer

C:

The lifecycle setting can make a normal destroy plan fail for a protected block; removing the block altogether removes the guard from evaluation; this behavior should be assessed against the concrete need to recognize a guard against destructive changes while the resource block remains configured. This directly supports the task to recognize a guard against destructive changes while the resource block remains configured during a staged rollout.

Incorrect Answers

A:

terraform state rm or a supported removed block can forget an object; it is different from instructing a provider to delete infrastructure; this behavior should be assessed against the concrete need to recognize a guard against destructive changes while the resource block remains configured. That can be useful when the aim is to stop Terraform management while leaving a real object intact, but it does not directly deliver the requested ability to recognize a guard against destructive changes while the resource block remains configured.

B:

State is a management map, not a full backup of application data or cloud resources; deletion may be irreversible without separate backups; this behavior should be assessed against the concrete need to recognize a guard against destructive changes while the resource block remains configured. The distinction matters here: using that mechanism to avoid assuming Terraform can restore deleted provider objects from state alone would still leave the objective to recognize a guard against destructive changes while the resource block remains configured unmet.

D:

Terraform reverses dependency relationships where necessary to delete objects safely; explicit and implicit graph edges influence safe order; this behavior should be assessed against the concrete need to recognize a guard against destructive changes while the resource block remains configured. The stated requirement is to recognize a guard against destructive changes while the resource block remains configured, not to understand why child objects may be destroyed before prerequisites; this alternative addresses a different control or phase.

Question 207

The immediate Terraform task is to display the textual adjustments a formatter would make. Which method handles that task most directly?

  1. Avoid treating formatting as infrastructure planning
  2. Run terraform fmt -diff
  3. Run terraform fmt in the working directory
  4. Use standard indentation and alignment from fmt

Explanation

Correct Answer

B:

Diff mode shows the before-and-after formatting changes; it cannot indicate whether a proposed resource change is safe; this behavior should be assessed against the concrete need to display the textual adjustments a formatter would make. This directly supports the task to display the textual adjustments a formatter would make during a configuration change.

Incorrect Answers

A:

A formatted file must still be evaluated by terraform plan to reveal resource changes; formatting commands do not contact APIs to execute changes; this behavior should be assessed against the concrete need to display the textual adjustments a formatter would make. The stated requirement is to display the textual adjustments a formatter would make, not to recognize that whitespace changes are not a plan for cloud operations; this alternative addresses a different control or phase.

C:

The formatter adjusts layout and spacing according to Terraform conventions; it does not modify remote infrastructure or update state; this behavior should be assessed against the concrete need to display the textual adjustments a formatter would make. The distinction matters here: using that mechanism to rewrite Terraform files into canonical HCL style would still leave the objective to display the textual adjustments a formatter would make unmet.

D:

Canonical layout gives team members predictable formatting; hand-crafted alignment rules are not necessary to make Terraform parse HCL correctly; this behavior should be assessed against the concrete need to display the textual adjustments a formatter would make. It may support a related workflow, but the question specifically requires the mechanism for display the textual adjustments a formatter would make rather than reduce noisy diff conflicts across contributors.

Question 208

The immediate Terraform task is to make infrastructure edits traceable and reviewable. Which method handles that task most directly?

  1. Use version control alongside the workflow
  2. Avoid applying an outdated reviewed plan
  3. Review results with a follow-up plan
  4. Write the desired configuration first
  5. Validate configuration before requesting a plan

Explanation

Correct Answer

A:

Git captures code changes and supports peer review; Terraform state and provider API results remain separate operational concerns; this behavior should be assessed against the concrete need to make infrastructure edits traceable and reviewable. This directly supports the task to make infrastructure edits traceable and reviewable during a platform review.

Incorrect Answers

B:

Saved plans encode assumptions about the state snapshot and inputs; if the state changes, applying a stale plan may be rejected rather than silently reinterpreted; this behavior should be assessed against the concrete need to make infrastructure edits traceable and reviewable. The stated requirement is to make infrastructure edits traceable and reviewable, not to ensure the approved actions still correspond to current state; this alternative addresses a different control or phase.

C:

When inputs and real infrastructure are unchanged, a later normal plan generally shows no changes; a follow-up plan can also detect external drift; this behavior should be assessed against the concrete need to make infrastructure edits traceable and reviewable. That can be useful when the aim is to verify convergence after a completed deployment, but it does not directly deliver the requested ability to make infrastructure edits traceable and reviewable.

D:

Resource blocks, variables, and modules define the target arrangement; running the CLI without an intended configuration cannot infer a team's architecture goals; this behavior should be assessed against the concrete need to make infrastructure edits traceable and reviewable. The distinction matters here: using that mechanism to establish the intended infrastructure before Terraform evaluates changes would still leave the objective to make infrastructure edits traceable and reviewable unmet.

E:

Validation checks the HCL configuration against available schemas; it is useful in CI but cannot replace a plan based on actual state and provider data; this behavior should be assessed against the concrete need to make infrastructure edits traceable and reviewable. It may support a related workflow, but the question specifically requires the mechanism for make infrastructure edits traceable and reviewable rather than identify structural issues early in a workflow.

Question 209

During an infrastructure audit, the team must accomplish all of these distinct aims: (1) copy existing state when changing storage backends; (2) reselect newer eligible provider and module packages. Select exactly the two relevant mechanisms. Choose TWO.

  1. Use terraform init -lockfile=readonly
  2. Use terraform init -backend-config=FILE
  3. Use terraform init -upgrade
  4. Use terraform init -migrate-state
  5. Use terraform init -get=false

Explanation

Correct Answers

C:

Upgrade requests reconsideration of versions within declared constraints; it changes dependency selections, not infrastructure objects by itself; this behavior should be assessed against the concrete need to copy existing state when changing storage backends and reselect newer eligible provider and module packages. This matches the distinct objective to reselect newer eligible provider and module packages; the remaining chosen features address copy existing state when changing storage backends.

D:

Migration attempts to move state into the newly configured backend; backups and confirmation are important before switching active state locations; this behavior should be assessed against the concrete need to copy existing state when changing storage backends and reselect newer eligible provider and module packages. This matches the distinct objective to copy existing state when changing storage backends; the remaining chosen features address reselect newer eligible provider and module packages.

Incorrect Answers

A:

Read-only dependency locking catches selection drift in automated builds; the lock file applies to providers rather than pinning arbitrary local module directories; this behavior should be assessed against the concrete need to copy existing state when changing storage backends and reselect newer eligible provider and module packages. Its main application is to enforce a committed provider selection without lockfile edits; the checklist instead asks for copy existing state when changing storage backends; and reselect newer eligible provider and module packages. None of those distinct criteria specifically calls for this alternative.

B:

Partial backend configuration can be completed from a separate file; values supplied this way may still be recorded in local Terraform metadata or saved plans; this behavior should be assessed against the concrete need to copy existing state when changing storage backends and reselect newer eligible provider and module packages. Its main application is to supply missing backend settings during initialization; the checklist instead asks for copy existing state when changing storage backends; and reselect newer eligible provider and module packages. None of those distinct criteria specifically calls for this alternative.

E:

This option avoids module download/update during initialization; it is appropriate only when required modules are already available; this behavior should be assessed against the concrete need to copy existing state when changing storage backends and reselect newer eligible provider and module packages. Its main application is to skip installing child modules in a prepared directory; the checklist instead asks for copy existing state when changing storage backends; and reselect newer eligible provider and module packages. None of those distinct criteria specifically calls for this alternative.

Question 210

An engineer needs to avoid inferring a successful future apply from successful static checks as part of a planned migration. Which option is the best fit?

  1. Use terraform fmt -check for formatting enforcement
  2. Recognize provider schema validation
  3. Interpret a clean validate as limited assurance
  4. Check for missing required variable values at planning time

Explanation

Correct Answer

C:

Provider API authorization, remote conflicts, and real infrastructure drift can still produce failures; validation checks supported configuration structure rather than deployment success; this behavior should be assessed against the concrete need to avoid inferring a successful future apply from successful static checks. This directly supports the task to avoid inferring a successful future apply from successful static checks during a maintenance request.

Incorrect Answers

A:

fmt -check exits nonzero when files need canonical formatting; it is a style check, not a replacement for Terraform semantic validation; this behavior should be assessed against the concrete need to avoid inferring a successful future apply from successful static checks. That can be useful when the aim is to detect code style deviations without rewriting files, but it does not directly deliver the requested ability to avoid inferring a successful future apply from successful static checks.

B:

Provider plugins supply schemas used for structural checking; passing validation does not mean the remote API will accept every eventual requested operation; this behavior should be assessed against the concrete need to avoid inferring a successful future apply from successful static checks. The distinction matters here: using that mechanism to detect unsupported resource arguments or incorrect types would still leave the objective to avoid inferring a successful future apply from successful static checks unmet.

D:

A variable declaration may be structurally valid even though a specific run has not supplied its required input; planning or applying requests those values when needed; this behavior should be assessed against the concrete need to avoid inferring a successful future apply from successful static checks. The stated requirement is to avoid inferring a successful future apply from successful static checks, not to understand why validation alone may pass with no values supplied; this alternative addresses a different control or phase.

HashiCorp Certified: Terraform Associate (Terraform Associate) Practice Tests