Which Terraform command brings existing infrastructure into Terraform state?

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

Which Terraform command brings existing infrastructure into Terraform state?

Explanation:
Bringing existing infrastructure under Terraform management is done by attaching real resources to Terraform’s state. The import command is built for this purpose. You first write a resource block in your configuration that matches the resource you want to manage, then run the import command with the resource’s address in your configuration and the provider’s ID of the existing resource. For example, importing an existing cloud instance attaches that real instance to the Terraform state under the address you defined. After the import, running a plan shows whether your configuration aligns with what’s actually deployed; if there are mismatches, you can adjust the code and re-run plan or import as needed. Importing updates the state file to reflect the known resources; it does not create or modify the real resource by itself. The other commands serve different purposes: initializing sets up the working directory and providers, fetching modules, while refreshing updates the state to match current infrastructure but does not discover new resources to import.

Bringing existing infrastructure under Terraform management is done by attaching real resources to Terraform’s state. The import command is built for this purpose. You first write a resource block in your configuration that matches the resource you want to manage, then run the import command with the resource’s address in your configuration and the provider’s ID of the existing resource. For example, importing an existing cloud instance attaches that real instance to the Terraform state under the address you defined. After the import, running a plan shows whether your configuration aligns with what’s actually deployed; if there are mismatches, you can adjust the code and re-run plan or import as needed. Importing updates the state file to reflect the known resources; it does not create or modify the real resource by itself. The other commands serve different purposes: initializing sets up the working directory and providers, fetching modules, while refreshing updates the state to match current infrastructure but does not discover new resources to import.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy