Practice Exams:

HashiCorp Terraform Associate 004 Dumps

EXAM: HashiCorp Certified: Terraform Associate (004)
Verified By Experts
Premium Bundle
$40.00
$59.97 $99.97

Terraform Associate 004 Premium Bundle


  • Premium File 167 Questions & Answers
  • Training Course 118 Lectures
  • Study Guide 285 Pages

HashiCorp Terraform Associate 004 Practice Test 39

Question 380

A university Terraform module needs to filter supported availability zones from an input collection before creating test subnets. Which combined implementation and verification plan is the best match for this workload?

  1. Implement: Use supported for expressions, conditionals and built-in functions to derive tags or normalized lists from validated inputs without shell scripting. Verify: Create three disposable labeled resources keyed by region, delete one key and inspect that the other keys retain their state addresses.
  2. Implement: Define a variable validation rule for acceptable input values and use resource preconditions for assumptions that must hold before an operation proceeds. Verify: Try an invalid CIDR or disallowed environment in an isolated plan and verify the custom error blocks the operation before creating resources.
  3. Implement: Create repeated similar resources with for_each over a known map or set and refer to each.key and each.value in the declared resource. Verify: Supply a synthetic map of environment labels, inspect the planned lowercased or merged values, and confirm the same inputs yield the same output.
  4. Implement: Use supported for expressions, conditionals and built-in functions to derive tags or normalized lists from validated inputs without shell scripting. Verify: Supply a synthetic map of environment labels, inspect the planned lowercased or merged values, and confirm the same inputs yield the same output.

Answer & Explanations

Correct answer: D

A.

The question is set in this situation: A university Terraform module needs to filter supported availability zones from an input collection before creating test subnets. The action is applicable: Use supported for expressions, conditionals and built-in functions to derive tags or normalized lists from validated inputs without shell scripting. But its proposed test—Create three disposable labeled resources keyed by region, delete one key and inspect that the other keys retain their state addresses.—addresses “Use for_each keyed maps for stable resource identities”. This requirement is confirmed instead by: Supply a synthetic map of environment labels, inspect the planned lowercased or merged values, and confirm the same inputs yield the same output.

B.

This action/test pair addresses “Validate inputs using variable validation and lifecycle preconditions”. Define a variable validation rule for acceptable input values and use resource preconditions for assumptions that must hold before an operation proceeds. Try an invalid CIDR or disallowed environment in an isolated plan and verify the custom error blocks the operation before creating resources. The case instead calls for: Use supported for expressions, conditionals and built-in functions to derive tags or normalized lists from validated inputs without shell scripting.

C.

The question is set in this situation: A university Terraform module needs to filter supported availability zones from an input collection before creating test subnets. The test would be relevant: Supply a synthetic map of environment labels, inspect the planned lowercased or merged values, and confirm the same inputs yield the same output. But the offered implementation—Create repeated similar resources with for_each over a known map or set and refer to each.key and each.value in the declared resource.—addresses “Use for_each keyed maps for stable resource identities”. The action needed here is: Use supported for expressions, conditionals and built-in functions to derive tags or normalized lists from validated inputs without shell scripting.

D.

The question is set in this situation: A university Terraform module needs to filter supported availability zones from an input collection before creating test subnets. Use supported for expressions, conditionals and built-in functions to derive tags or normalized lists from validated inputs without shell scripting. Confirm it through this test: Supply a synthetic map of environment labels, inspect the planned lowercased or merged values, and confirm the same inputs yield the same output. Terraform evaluates expressions within the dependency graph and computes derived values from input collections, reducing duplicated literal configuration.

Question 381

A database module must finish an independently declared permissions change before a dependent service attempts its first connection. Which HashiCorp Terraform infrastructure implementation best satisfies this requirement?

  1. Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.
  2. Use indexed addresses for count-created instances and key-based addresses for for_each-created instances when referencing individual resource attributes.
  3. Declare Terraform resource blocks for objects the configuration owns and data blocks to query existing objects the configuration should not create or delete.
  4. Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters.

Answer & Explanations

Correct answer: A

A.

Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative. Verify the result with this test: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

B.

Use indexed addresses for count-created instances and key-based addresses for for_each-created instances when referencing individual resource attributes. This addresses “Address resources correctly when count and for_each are used”, where the governing principle is: Resource instance addresses encode either numeric instance positions or stable collection keys; confusing them causes invalid references or churn. The stated case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

C.

Declare Terraform resource blocks for objects the configuration owns and data blocks to query existing objects the configuration should not create or delete. This addresses “Use resource blocks to manage objects and data blocks to read them”, where the governing principle is: Managed resources have Terraform-controlled lifecycle and state bindings, whereas data sources read existing objects supplied by external systems or other owners. The stated case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

D.

Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters. This addresses “Use create_before_destroy only when replacement sequencing is feasible”, where the governing principle is: Terraform may create a replacement before removing the old object, but a uniqueness constraint or shared name can prevent the two instances from coexisting. The stated case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

Question 382

A database module must finish an independently declared permissions change before a dependent service attempts its first connection. The infrastructure engineer proposes this change: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Which mechanism explains why it works?

  1. Managed resources have Terraform-controlled lifecycle and state bindings, whereas data sources read existing objects supplied by external systems or other owners.
  2. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.
  3. Terraform may create a replacement before removing the old object, but a uniqueness constraint or shared name can prevent the two instances from coexisting.
  4. Resource instance addresses encode either numeric instance positions or stable collection keys; confusing them causes invalid references or churn.

Answer & Explanations

Correct answer: B

A.

Managed resources have Terraform-controlled lifecycle and state bindings, whereas data sources read existing objects supplied by external systems or other owners. That explains “Use resource blocks to manage objects and data blocks to read them”, not the mechanism behind the described change. The relevant principle is: Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

B.

Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative. The corresponding implementation is: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

C.

Terraform may create a replacement before removing the old object, but a uniqueness constraint or shared name can prevent the two instances from coexisting. That explains “Use create_before_destroy only when replacement sequencing is feasible”, not the mechanism behind the described change. The relevant principle is: Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

D.

Resource instance addresses encode either numeric instance positions or stable collection keys; confusing them causes invalid references or churn. That explains “Address resources correctly when count and for_each are used”, not the mechanism behind the described change. The relevant principle is: Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

Question 383

A database module must finish an independently declared permissions change before a dependent service attempts its first connection. After implementing this change—Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.—which test most directly validates its intended outcome?

  1. Plan a disposable managed bucket alongside a data lookup of an approved existing network and inspect which objects would be created.
  2. Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly.
  3. Create an isolated test resource for each environment key, inspect terraform state list and prove the intended key selects only its matching resource.
  4. Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

Answer & Explanations

Correct answer: D

A.

Plan a disposable managed bucket alongside a data lookup of an approved existing network and inspect which objects would be created. That would help test “Use resource blocks to manage objects and data blocks to read them”, not the outcome required in this scenario. The relevant acceptance check is: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

B.

Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly. That would help test “Use create_before_destroy only when replacement sequencing is feasible”, not the outcome required in this scenario. The relevant acceptance check is: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

C.

Create an isolated test resource for each environment key, inspect terraform state list and prove the intended key selects only its matching resource. That would help test “Address resources correctly when count and for_each are used”, not the outcome required in this scenario. The relevant acceptance check is: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

D.

Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible. This check is decisive because terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

Question 384

A database module must finish an independently declared permissions change before a dependent service attempts its first connection. Which proposed shortcut most directly risks unnecessary serialization and conservative unknown values that complicate plans and should therefore be rejected?

  1. Enable create_before_destroy on a globally unique fixed-name object without checking whether a second object can exist simultaneously.
  2. Refer to a for_each-created resource as a singleton name with no index or key and expect Terraform to select one arbitrary instance.
  3. Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.
  4. Define an existing production network as a new managed resource and assume Terraform will automatically adopt it without import or conflict.

Answer & Explanations

Correct answer: C

A.

Enable create_before_destroy on a globally unique fixed-name object without checking whether a second object can exist simultaneously. That shortcut risks failed replacement or deployment outage caused by an impossible coexistence assumption. Here the specific shortcut is: Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.

B.

Refer to a for_each-created resource as a singleton name with no index or key and expect Terraform to select one arbitrary instance. That shortcut risks invalid references and accidental resource changes caused by incorrect addresses. Here the specific shortcut is: Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.

C.

Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free. The foreseeable failure is unnecessary serialization and conservative unknown values that complicate plans. The safer response is: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

D.

Define an existing production network as a new managed resource and assume Terraform will automatically adopt it without import or conflict. That shortcut risks duplicate creation attempts and unintended ownership of resources managed elsewhere. Here the specific shortcut is: Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.

Question 385

A database module must finish an independently declared permissions change before a dependent service attempts its first connection. Which combined implementation and verification plan is the best match for this workload?

  1. Implement: Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters. Verify: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.
  2. Implement: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Verify: Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly.
  3. Implement: Declare Terraform resource blocks for objects the configuration owns and data blocks to query existing objects the configuration should not create or delete. Verify: Plan a disposable managed bucket alongside a data lookup of an approved existing network and inspect which objects would be created.
  4. Implement: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Verify: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

Answer & Explanations

Correct answer: D

A.

The test would be relevant: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible. But the offered implementation—Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters.—addresses “Use create_before_destroy only when replacement sequencing is feasible”. The action needed here is: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

B.

The action is applicable: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. But its proposed test—Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly.—addresses “Use create_before_destroy only when replacement sequencing is feasible”. This requirement is confirmed instead by: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

C.

This action/test pair addresses “Use resource blocks to manage objects and data blocks to read them”. Declare Terraform resource blocks for objects the configuration owns and data blocks to query existing objects the configuration should not create or delete. Plan a disposable managed bucket alongside a data lookup of an approved existing network and inspect which objects would be created. The case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

D.

Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Confirm it through this test: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

Question 386

A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Which HashiCorp Terraform infrastructure implementation best satisfies this requirement?

  1. Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.
  2. Create repeated similar resources with for_each over a known map or set and refer to each.key and each.value in the declared resource.
  3. Use indexed addresses for count-created instances and key-based addresses for for_each-created instances when referencing individual resource attributes.
  4. Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters.

Answer & Explanations

Correct answer: A

A.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative. Verify the result with this test: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

B.

Create repeated similar resources with for_each over a known map or set and refer to each.key and each.value in the declared resource. This addresses “Use for_each keyed maps for stable resource identities”, where the governing principle is: Stable keyed addresses let Terraform maintain resource identity when unrelated collection entries are added or removed, unlike numeric position shifts. The stated case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

C.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Use indexed addresses for count-created instances and key-based addresses for for_each-created instances when referencing individual resource attributes. This addresses “Address resources correctly when count and for_each are used”, where the governing principle is: Resource instance addresses encode either numeric instance positions or stable collection keys; confusing them causes invalid references or churn. The stated case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

D.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters. This addresses “Use create_before_destroy only when replacement sequencing is feasible”, where the governing principle is: Terraform may create a replacement before removing the old object, but a uniqueness constraint or shared name can prevent the two instances from coexisting. The stated case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

Question 387

A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. The infrastructure engineer proposes this change: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Which mechanism explains why it works?

  1. Stable keyed addresses let Terraform maintain resource identity when unrelated collection entries are added or removed, unlike numeric position shifts.
  2. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.
  3. Resource instance addresses encode either numeric instance positions or stable collection keys; confusing them causes invalid references or churn.
  4. Terraform may create a replacement before removing the old object, but a uniqueness constraint or shared name can prevent the two instances from coexisting.

Answer & Explanations

Correct answer: B

A.

Stable keyed addresses let Terraform maintain resource identity when unrelated collection entries are added or removed, unlike numeric position shifts. That explains “Use for_each keyed maps for stable resource identities”, not the mechanism behind the described change. The relevant principle is: Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

B.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative. The corresponding implementation is: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

C.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Resource instance addresses encode either numeric instance positions or stable collection keys; confusing them causes invalid references or churn. That explains “Address resources correctly when count and for_each are used”, not the mechanism behind the described change. The relevant principle is: Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

D.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Terraform may create a replacement before removing the old object, but a uniqueness constraint or shared name can prevent the two instances from coexisting. That explains “Use create_before_destroy only when replacement sequencing is feasible”, not the mechanism behind the described change. The relevant principle is: Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

Question 388

A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. After implementing this change—Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.—which test most directly validates its intended outcome?

  1. Create an isolated test resource for each environment key, inspect terraform state list and prove the intended key selects only its matching resource.
  2. Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly.
  3. Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.
  4. Create three disposable labeled resources keyed by region, delete one key and inspect that the other keys retain their state addresses.

Answer & Explanations

Correct answer: C

A.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Create an isolated test resource for each environment key, inspect terraform state list and prove the intended key selects only its matching resource. That would help test “Address resources correctly when count and for_each are used”, not the outcome required in this scenario. The relevant acceptance check is: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

B.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly. That would help test “Use create_before_destroy only when replacement sequencing is feasible”, not the outcome required in this scenario. The relevant acceptance check is: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

C.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible. This check is decisive because terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

D.

Create three disposable labeled resources keyed by region, delete one key and inspect that the other keys retain their state addresses. That would help test “Use for_each keyed maps for stable resource identities”, not the outcome required in this scenario. The relevant acceptance check is: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

Question 389

A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Which proposed shortcut most directly risks unnecessary serialization and conservative unknown values that complicate plans and should therefore be rejected?

  1. Use count over an alphabetically reordered list and assume existing resources cannot be reassigned when a new item is inserted near the beginning.
  2. Refer to a for_each-created resource as a singleton name with no index or key and expect Terraform to select one arbitrary instance.
  3. Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.
  4. Enable create_before_destroy on a globally unique fixed-name object without checking whether a second object can exist simultaneously.

Answer & Explanations

Correct answer: C

A.

Use count over an alphabetically reordered list and assume existing resources cannot be reassigned when a new item is inserted near the beginning. That shortcut risks unnecessary replacement or misassignment of resources after list reordering. Here the specific shortcut is: Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.

B.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Refer to a for_each-created resource as a singleton name with no index or key and expect Terraform to select one arbitrary instance. That shortcut risks invalid references and accidental resource changes caused by incorrect addresses. Here the specific shortcut is: Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.

C.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free. The foreseeable failure is unnecessary serialization and conservative unknown values that complicate plans. The safer response is: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

D.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Enable create_before_destroy on a globally unique fixed-name object without checking whether a second object can exist simultaneously. That shortcut risks failed replacement or deployment outage caused by an impossible coexistence assumption. Here the specific shortcut is: Insert depends_on on every module in a workspace without analysis, expecting this to make plans faster and change-free.

Question 390

A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Which combined implementation and verification plan is the best match for this workload?

  1. Implement: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Verify: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.
  2. Implement: Use indexed addresses for count-created instances and key-based addresses for for_each-created instances when referencing individual resource attributes. Verify: Create an isolated test resource for each environment key, inspect terraform state list and prove the intended key selects only its matching resource.
  3. Implement: Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters. Verify: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.
  4. Implement: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Verify: Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly.

Answer & Explanations

Correct answer: A

A.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. Confirm it through this test: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible. Terraform already infers dependencies from expression references; explicit dependencies are for hidden ordering constraints and can make plans more conservative.

B.

This action/test pair addresses “Address resources correctly when count and for_each are used”. Use indexed addresses for count-created instances and key-based addresses for for_each-created instances when referencing individual resource attributes. Create an isolated test resource for each environment key, inspect terraform state list and prove the intended key selects only its matching resource. The case instead calls for: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

C.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. The test would be relevant: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible. But the offered implementation—Apply lifecycle create_before_destroy for a replaceable resource when temporary coexistence is supported, identifiers are unique and downtime reduction matters.—addresses “Use create_before_destroy only when replacement sequencing is feasible”. The action needed here is: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference.

D.

The question is set in this situation: A regional operations team is deciding whether to add an explicit dependency between a monitoring setup and an application rollout without attribute references. The action is applicable: Add explicit depends_on on a resource or module only when the downstream operation relies on an upstream side effect not represented by a direct attribute reference. But its proposed test—Replace a disposable uniquely named resource and inspect the plan order while verifying the remote service allows both versions briefly.—addresses “Use create_before_destroy only when replacement sequencing is feasible”. This requirement is confirmed instead by: Create a test dependency without a data reference, inspect graph ordering, and remove the explicit dependency to show why a direct reference would be preferable when possible.

HashiCorp Certified: Terraform Associate (004) (Terraform Associate 004) Practice Tests