What is the best practice to reflect infrastructure changes in Terraform after manually destroying resources?

Prepare for your Terraform Associate Exam with our engaging quiz. Test your knowledge with multiple choice questions and receive detailed explanations to enhance your understanding. Ace your exam with confidence!

The best practice to reflect infrastructure changes in Terraform after manually destroying resources is to use 'terraform refresh'. This command updates the Terraform state file with the current state of the real infrastructure. When resources are destroyed manually outside of Terraform's management (such as through a cloud provider's dashboard), the local state maintained by Terraform becomes out of sync with the actual infrastructure.

Running 'terraform refresh' allows Terraform to reconcile its state with the actual infrastructure, ensuring that any changes—such as the deletion of resources—are accurately recorded in the state file. By updating the state without making changes to the infrastructure, this command helps maintain an accurate and current representation of the environment.

The other choices involve different functionalities of Terraform that don't specifically address the issue of syncing state after manual changes. For instance, using 'terraform apply' would attempt to create or update resources as defined in the configuration files, which may lead to conflicts or undesired changes. 'terraform destroy' would attempt to remove all resources defined in the configuration, which is not suitable when the intention is only to update the state file. Finally, 'terraform plan' shows a preview of changes that would occur but does not update the state file itself, making it an inappropriate choice for this scenario.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy