Courseiva
Use Terraform outside the core workflowmediumMultiple SelectObjective-mapped

TF-004 Use Terraform outside the core workflow Practice Question

Which TWO are valid methods to import existing infrastructure into Terraform?

⚠ Common exam trap

Candidates often mistakenly believe that `terraform import` automatically generates configuration code, but it only updates the state file. You must manually write the resource block before running import.

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

Run 'terraform import' with the resource address and ID.

`terraform import` is the primary command for bringing existing infrastructure under Terraform management. It requires both the resource address (as defined in your configuration) and the provider-specific ID of the real-world object. This command maps the existing resource into the Terraform state, enabling subsequent `apply` operations to manage it.

Answer analysis

Option-by-option breakdown

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

  • Use 'terraform state rm' to remove existing state before running apply.

    Why it's wrong here

    Using 'terraform state rm' is incorrect because this command is designed to remove a resource's entry from the Terraform state file, effectively telling Terraform to stop managing it without destroying the actual infrastructure. It does not facilitate the discovery or onboarding of existing, unmanaged infrastructure into Terraform's state. Running 'apply' after 'state rm' would typically attempt to recreate the resource if it's still defined in configuration, not import it.

  • Run 'terraform import' with the resource address and ID.

    Why this is correct

    Running 'terraform import' with the resource address and ID is a correct and fundamental method for bringing existing infrastructure under Terraform's management. This command explicitly takes a pre-existing cloud resource, identified by its unique cloud provider ID, and associates it with a corresponding resource block defined in the Terraform configuration. This action adds the resource's details to the state file, allowing Terraform to manage its lifecycle going forward.

  • Use 'terraform console' to inspect and import.

    Why it's wrong here

    Using 'terraform console' to inspect and import is incorrect because 'terraform console' provides an interactive command-line interface primarily for evaluating expressions, inspecting the current state, and testing interpolation functions. While useful for debugging and understanding state data, it lacks any built-in functionality or commands to directly import external infrastructure resources into the Terraform state file or configuration. Its purpose is purely for interactive evaluation, not state manipulation or resource onboarding.

  • Add resource blocks manually and run 'terraform import' for each resource.

    Why this is correct

    Adding resource blocks manually and then running 'terraform import' for each resource is a correct and common two-step process for importing existing infrastructure. First, you define the corresponding resource block(s) in your Terraform configuration files (.tf) to accurately represent the existing infrastructure. Subsequently, the 'terraform import' command is executed for each specific resource, linking the manually defined configuration block to its pre-existing cloud instance using its unique identifier, thereby bringing it under Terraform's management.

  • Use 'terraform init -migrate-state' to import from another backend.

    Why it's wrong here

    Using 'terraform init -migrate-state' to import from another backend is incorrect because this command is specifically designed to move the *entire* Terraform state file from one configured backend to another (e.g., from local storage to a remote object storage service). It does not import new or unmanaged infrastructure resources into the existing state. Its function is solely to relocate the current state, ensuring continuity of management, rather than discovering and adding external resources.

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.