What does the Terraform command 'terraform apply -refresh-only' do?

Master the HashiCorp Terraform Test with these flashcards and multiple choice questions. Each question includes hints and explanations to prepare you effectively. Set yourself up for success!

The command 'terraform apply -refresh-only' specifically performs the action of refreshing the Terraform state file with the current infrastructure state without applying any changes to the resources defined in the configuration. This command is useful for ensuring that the Terraform state accurately reflects the actual state of the resources in the cloud or wherever the infrastructure is deployed.

When you run this command, Terraform reads the existing resources from the provider (like AWS, Azure, etc.) and updates the state file accordingly. However, because the flag indicates a refresh-only operation, it deliberately avoids making any modifications to the actual infrastructure. This means that even if the current state of the resources differs from what is defined in the Terraform configuration files, no changes will be applied.

This function is critical in scenarios where you want to synchronize the Terraform state with the real-world state of resources without triggering any updates or modifications, which can be particularly beneficial for auditing purposes or troubleshooting discrepancies between the planned and actual states.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy