Hashicorp Certified Terraform Associate 003 · Free Practice Question Medium

Question 18

You want to start managing resources that were not originally provisioned through infrastructure as code. Before you can import the resource's current state, what must you do before running the terraform import command?

  • A

    run terraform apply -refresh-only to ensure that the state file has the latest information for existing resources.

  • B

    shut down or stop using the resources being imported so no changes are inadvertently missed

  • C

    update the Terraform configuration file to include the new resources that match the resources you want to import

  • D

    modify the Terraform state file to add the new resources so Terraform will have a record of the resources to be managed

Reveal correct answer

Correct answer: C

Explanation

NOTE: HashiCorp has released functionality that automatically generates the Terraform configuration for imported resources. However, please keep in mind that the exam questions are not updated immediately, and therefore, you may find that the exam still expects you to know you should create the configuration yourself.

The current implementation of Terraform import can only import resources into the state. It does not generate a configuration. Because of this, and before running terraform import, it is necessary to manually write a resource configuration block for the resource to which the imported object will be mapped.

First, add the resources to the configuration file:



Then run the following command:

$ terraform import aws_instance.example i-abcd1234


https://developer.hashicorp.com/terraform/cli/commands/import

A. Running terraform apply -refresh-only before importing new resources is not required. The terraform import command is specifically used to import existing resources into Terraform's state, and running a refresh-only apply command is not necessary for this process.

B. Shutting down or stopping the resources being imported is not necessary before running the terraform import command. The import process does not require the resources to be stopped, but rather focuses on bringing their current state into Terraform's management.

C. Before running the terraform import command, you need to update the Terraform configuration file to include the new resources that match the resources you want to import. This step ensures that Terraform is aware of the resources you want to manage and can properly import their current state.

D. Modifying the Terraform state file to add new resources before running the terraform import command is not the correct approach. The state file should be managed by Terraform itself, and manually modifying it can lead to inconsistencies and potential issues with resource management.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need