2014-07-24 18:02:10 +02:00
---
2021-12-15 03:41:17 +01:00
page_title: 'Command: refresh'
2014-10-22 05:21:56 +02:00
description: |-
2021-04-07 21:25:59 +02:00
The `terraform refresh` command reads the current settings from all managed
remote objects and updates the Terraform state to match.
2014-07-24 18:02:10 +02:00
---
# Command: refresh
2021-07-06 21:52:16 +02:00
> **Hands-on:** Try the [Use Refresh-Only Mode to Sync Terraform State](https://learn.hashicorp.com/tutorials/terraform/refresh) tutorial on HashiCorp Learn.
2021-04-07 21:25:59 +02:00
The `terraform refresh` command reads the current settings from all managed
remote objects and updates the Terraform state to match.
2014-07-24 18:02:10 +02:00
2021-12-15 03:41:17 +01:00
~> _Warning:_ This command is deprecated, because its default behavior is
2021-04-07 21:25:59 +02:00
unsafe if you have misconfigured credentials for any of your providers.
See below for more information and recommended alternatives.
2014-07-24 18:02:10 +02:00
2021-04-07 21:25:59 +02:00
This won't modify your real remote objects, but it will modify the
2021-12-15 03:41:17 +01:00
[Terraform state](/language/state).
2014-07-24 18:02:10 +02:00
2021-04-07 21:25:59 +02:00
You shouldn't typically need to use this command, because Terraform
automatically performs the same refreshing actions as a part of creating
a plan in both the
2021-12-15 03:41:17 +01:00
[`terraform plan`](/cli/commands/plan)
2021-04-07 21:25:59 +02:00
and
2021-12-15 03:41:17 +01:00
[`terraform apply`](/cli/commands/apply)
2021-04-07 21:25:59 +02:00
commands. This command is here primarily for backward compatibility, but
we don't recommend using it because it provides no opportunity to review
the effects of the operation before updating the state.
2014-07-24 18:02:10 +02:00
2021-04-07 21:25:59 +02:00
## Usage
2019-12-10 20:06:06 +01:00
2021-04-07 21:25:59 +02:00
Usage: `terraform refresh [options]`
2017-04-04 19:48:59 +02:00
2021-04-07 21:25:59 +02:00
This command is effectively an alias for the following command:
2017-04-04 19:48:59 +02:00
2021-04-07 21:25:59 +02:00
```
terraform apply -refresh-only -auto-approve
```
2017-04-04 19:48:59 +02:00
2021-04-07 21:25:59 +02:00
Consequently, it supports all of the same options as
2021-12-15 03:41:17 +01:00
[`terraform apply`](/cli/commands/apply) except that it does not accept a saved
2021-04-07 21:25:59 +02:00
plan file, it doesn't allow selecting a planning mode other than "refresh only",
and `-auto-approve` is always enabled.
2017-04-04 19:48:59 +02:00
2022-03-14 17:18:45 +01:00
Automatically applying the effect of a refresh is risky. If you have
2022-01-03 02:56:48 +01:00
misconfigured credentials for one or more providers then Terraform may
2021-04-07 21:25:59 +02:00
be misled into thinking that all of the managed objects have been deleted,
2022-03-14 17:18:50 +01:00
causing it to remove all of the tracked objects without any confirmation prompt.
2019-03-06 15:25:36 +01:00
2021-04-07 21:25:59 +02:00
Instead, we recommend using the following command in order to get the same
2021-07-28 15:40:07 +02:00
effect but with the opportunity to review the changes that Terraform has
2021-04-07 21:25:59 +02:00
detected before committing them to the state:
2015-03-27 23:24:15 +01:00
2021-04-07 21:25:59 +02:00
```
terraform apply -refresh-only
```
2014-07-24 18:02:10 +02:00
2021-04-07 21:25:59 +02:00
This alternative command will present an interactive prompt for you to confirm
the detected changes.
2021-03-25 00:17:03 +01:00
2021-04-07 21:25:59 +02:00
The `-refresh-only` option for `terraform plan` and `terraform apply` was
2021-05-26 18:09:39 +02:00
introduced in Terraform v0.15.4. For prior versions you must use
2021-04-07 21:25:59 +02:00
`terraform refresh` directly if you need this behavior, while taking into
account the warnings above. Wherever possible, avoid using `terraform refresh`
explicitly and instead rely on Terraform's behavior of automatically refreshing
existing objects as part of creating a normal plan.