Which action is the primary way to incorporate existing resources into Terraform's state?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

Which action is the primary way to incorporate existing resources into Terraform's state?

Explanation:
Bringing resources that were created outside Terraform under Terraform’s management is done with the import operation. Terraform keeps a state file that maps your configuration to real-world resources. If something already exists, Terraform doesn’t know about it until you tell it to track that resource. Importing creates that mapping by taking the resource’s address in your configuration and the provider’s unique ID for the existing resource, then updating the state accordingly. Once imported, you can use plan and apply to make changes to that resource as defined in your configuration, and Terraform will manage it going forward. Destroy would remove the resource, which isn’t about incorporating it into state. In practice, you define the resource in code, run the import command with the real ID, then run a plan to verify the state matches and apply to enact any needed changes.

Bringing resources that were created outside Terraform under Terraform’s management is done with the import operation. Terraform keeps a state file that maps your configuration to real-world resources. If something already exists, Terraform doesn’t know about it until you tell it to track that resource. Importing creates that mapping by taking the resource’s address in your configuration and the provider’s unique ID for the existing resource, then updating the state accordingly. Once imported, you can use plan and apply to make changes to that resource as defined in your configuration, and Terraform will manage it going forward. Destroy would remove the resource, which isn’t about incorporating it into state. In practice, you define the resource in code, run the import command with the real ID, then run a plan to verify the state matches and apply to enact any needed changes.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy