Courseiva
Interact with Terraform modulesmediumMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

A root module uses a module that creates an AWS EC2 instance. The module outputs the instance ID. The root module then uses this output in a null_resource provisioner. After modifying the module, terraform plan shows that the EC2 instance will be destroyed and recreated. What is the impact on the null_resource?

⚠ Common exam trap

Watch out — candidates often assume null_resource is immutable or independent because it is a HashiCorp-specific resource with no real infrastructure, but Terraform treats any change in its triggers as a recreation signal, making it tightly coupled to upstream dependencies.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The null_resource will be destroyed and recreated alongside the EC2 instance.

The null_resource's triggers typically depend on the module's output (the instance ID). When the EC2 instance is destroyed and recreated, its ID changes, which updates the trigger value. Terraform interprets this change as a need to destroy and recreate the null_resource along with its provisioner, ensuring the provisioner runs again with the new instance ID.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The null_resource prompts the user to confirm before any changes.

    Why it's wrong here

    Terraform's `null_resource` is a provider resource designed to execute provisioners or manage dependencies, not to prompt users for input. During a `terraform plan`, it will display its intended actions (creation, destruction, or replacement) like any other resource. User confirmation for applying changes occurs at the `terraform apply` stage, after the plan has been reviewed, and is a function of the Terraform CLI, not an individual resource type or the `null_resource` itself.

  • The null_resource will remain unchanged because it is not directly attached to the module.

    Why it's wrong here

    This statement is incorrect because Terraform automatically builds a comprehensive dependency graph based on all resource references within the configuration. Even if the `null_resource` is not directly nested within the module, its `triggers` argument almost certainly references an output from the module that creates the EC2 instance. When that module's output value changes due to the EC2 instance being recreated, the `null_resource` detects this change in its `triggers` and schedules itself for recreation.

  • The null_resource will fail to run because the output is temporarily unavailable during destroy.

    Why it's wrong here

    Terraform manages resource lifecycle events in a specific, ordered manner, especially during a replacement operation where an existing resource is destroyed and a new one created. When an EC2 instance is replaced, Terraform typically creates the new instance first, then updates any dependent outputs, and only then destroys the old instance. The `null_resource`'s `triggers` are evaluated based on the *current* state and the *planned* state, ensuring it will be recreated *after* the new EC2 instance is provisioned and its output is available, preventing any failure due to temporary unavailability.

  • The null_resource will be destroyed and recreated alongside the EC2 instance.

    Why this is correct

    The `null_resource` is specifically designed to execute its `provisioners` whenever a value within its `triggers` map changes. Since the `null_resource` depends on an output from the module that creates the EC2 instance, any recreation or significant modification to that EC2 instance will alter the associated module output. This detected change in the output value will then cause the `null_resource` to be marked for destruction and subsequent recreation, ensuring its provisioners run again with the updated context of the new instance.

About these practice questions

Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.