How to Refresh State in Terraform

0 min read 106 words

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
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags