2014-07-24 18:02:10 +02:00
---
2021-11-23 00:57:25 +01:00
layout: "docs"
page_title: "Command: refresh"
sidebar_current: "docs-commands-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-11-23 00:57:25 +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-11-23 00:57:25 +01:00
[Terraform state ](/docs/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-11-23 00:57:25 +01:00
[`terraform plan` ](./plan.html )
2021-04-07 21:25:59 +02:00
and
2021-11-23 00:57:25 +01:00
[`terraform apply` ](./apply.html )
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-11-23 00:57:25 +01:00
[`terraform apply` ](./apply.html ) 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
2021-04-07 21:25:59 +02:00
Automatically applying the effect of a refresh is risky, because if you have
misconfigured credentials for one or more providers then the provider may
be misled into thinking that all of the managed objects have been deleted,
and thus 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.