Sometimes your infrastructure may be out of sync with your Terraform state because resources may have been amended or deleted manually.
For this you can refresh
the Terraform state.
Using the refresh
command
terraform refresh [options]
Why this command may appear strange at first, not that it is merely an alias for:
terraform apply -refresh-only -auto-approve
If you don’t want to auto-approve
the transaction, then you can perform a refresh as follows:
terraform apply -refresh-only
If you use a var-file
to specify environment specific configuration, then you can do the following:
terraform apply -refresh-only -var-file ./path/to/dev.tfvars
And auto-approve
as follows:
terraform apply -refresh-only -var-file ./path/to/dev.tfvars --auto-approve