When should you write Terraform configuration files for existing infrastructure that you want to start managing with Terraform?

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

When should you write Terraform configuration files for existing infrastructure that you want to start managing with Terraform?

Explanation:
When bringing existing infrastructure under Terraform management, you should first write the Terraform configuration that defines the resources you intend to manage. The import operation needs a matching resource block in your configuration to map the real-world resource into Terraform’s state. Without that block already present, Terraform has nowhere to attach the imported data, and you’d end up with resources in state without corresponding code to drive them. Terraform does not auto-generate configuration for you; it only populates the state for resources you’ve defined in code and then import. After you’ve defined the resource blocks, you run the import for each one to bring the actual infrastructure into state, then plan and apply to reconcile any differences. So, the best order is to write the configuration first, then import the existing resources.

When bringing existing infrastructure under Terraform management, you should first write the Terraform configuration that defines the resources you intend to manage. The import operation needs a matching resource block in your configuration to map the real-world resource into Terraform’s state. Without that block already present, Terraform has nowhere to attach the imported data, and you’d end up with resources in state without corresponding code to drive them.

Terraform does not auto-generate configuration for you; it only populates the state for resources you’ve defined in code and then import. After you’ve defined the resource blocks, you run the import for each one to bring the actual infrastructure into state, then plan and apply to reconcile any differences.

So, the best order is to write the configuration first, then import the existing resources.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy