Courseiva
Understand Terraform's purposemediumMultiple ChoiceObjective-mapped

TF-004 Understand Terraform's purpose Practice Question

A team wants to use Terraform to manage their AWS infrastructure. They have existing resources created manually. What is the recommended approach to bring these resources under Terraform management?

⚠ Common exam trap

A common misconception is that `terraform plan` can discover and adopt existing resources, but in reality, `plan` only compares state to configuration and cannot detect resources outside of state.

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

Use terraform import to bring each resource into state.

`terraform import` is the recommended approach to bring existing manually created resources under Terraform management. It maps the real-world resource ID into your Terraform state file, allowing Terraform to track and manage it without deleting or recreating it. This preserves the existing infrastructure while enabling future updates via configuration.

Answer analysis

Option-by-option breakdown

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

  • Delete the existing resources and recreate them using Terraform configuration.

    Why it's wrong here

    Deleting existing resources and then recreating them using Terraform configuration is a highly disruptive and risky approach, particularly for production environments. This method would inevitably lead to service downtime, potential data loss, and significant operational interruptions for any applications or services dependent on those resources. It completely bypasses the goal of adopting existing infrastructure, instead opting for a destructive replacement strategy that is rarely acceptable.

  • Use terraform plan to detect existing resources and automatically adopt them.

    Why it's wrong here

    The `terraform plan` command is designed to preview the changes Terraform intends to make to align the infrastructure with the defined configuration, comparing it against the current state file and remote resources. It does not possess any inherent capability to discover unmanaged existing resources within a cloud provider and automatically incorporate them into the Terraform state. Its function is strictly for drift detection and change visualization, not for resource discovery and adoption.

  • Write Terraform configuration that matches existing resources and run terraform apply.

    Why it's wrong here

    If Terraform configuration is written to match existing resources without first importing them, running `terraform apply` would instruct Terraform to create *new* resources based on that configuration. Since resources with identical identifiers (e.g., specific S3 bucket names, unique EC2 instance IDs) already exist in the cloud provider, this operation would fail due to naming conflicts or attempt to create duplicates. This leads to errors and an inconsistent state, as Terraform's default behavior is to provision, not adopt, when a resource is defined in configuration but absent from the state.

  • Use terraform import to bring each resource into state.

    Why this is correct

    The `terraform import` command is the correct and intended workflow for bringing existing infrastructure under Terraform's management. It reads the current state and attributes of a specified remote resource and then records this information within the Terraform state file, associating it with a corresponding resource block in the local configuration. This crucial step allows Terraform to recognize and manage the resource's lifecycle, enabling subsequent `plan` and `apply` operations to detect drift and make controlled modifications without recreating the resource.

About these practice questions

This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.