Skip to content

How to Refresh State in Terraform

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
Code language: Bash (bash)

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
Code language: Bash (bash)

And auto-approve as follows:

terraform apply -refresh-only -var-file ./path/to/dev.tfvars --auto-approve
Code language: Bash (bash)

See also  How to add Account Condition to AWS Lambda Permissions in Terraform
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x