When importing existing infrastructure into Terraform, should Terraform configuration be written before performing the import?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

When importing existing infrastructure into Terraform, should Terraform configuration be written before performing the import?

Explanation:
Before importing, have Terraform configuration written that describes the resources you intend to manage. Importing updates Terraform’s state to reflect existing real resources, but it does not generate or modify your code. Without a matching resource block in the configuration, there’s nothing for Terraform to attach the imported resource to, leaving state entries that you cannot manage with code. By defining the resource blocks first, you ensure that the import maps the actual infrastructure to the correct pieces of your configuration, so you can plan, adjust attributes, and apply changes to bring the real resources in line with your desired state. For example, define the resource for the AWS resource you’re bringing in, then run the import command to connect the existing resource to that block. After import, you can refine the configuration (tags, settings) and run plan and apply to lock in the intended configuration.

Before importing, have Terraform configuration written that describes the resources you intend to manage. Importing updates Terraform’s state to reflect existing real resources, but it does not generate or modify your code. Without a matching resource block in the configuration, there’s nothing for Terraform to attach the imported resource to, leaving state entries that you cannot manage with code. By defining the resource blocks first, you ensure that the import maps the actual infrastructure to the correct pieces of your configuration, so you can plan, adjust attributes, and apply changes to bring the real resources in line with your desired state. For example, define the resource for the AWS resource you’re bringing in, then run the import command to connect the existing resource to that block. After import, you can refine the configuration (tags, settings) and run plan and apply to lock in the intended configuration.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy