2014-07-24 18:02:10 +02: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-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-04-07 21:25:59 +02:00
|
|
|
~> *Warning:* This command is deprecated, because its default behavior is
|
|
|
|
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
|
|
|
|
[the 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
|
|
|
|
[`terraform plan`](./plan.html)
|
|
|
|
and
|
|
|
|
[`terraform apply`](./apply.html)
|
|
|
|
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
|
|
|
|
[`terraform apply`](./apply.html) except that it does not accept a saved
|
|
|
|
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
|
|
|
|
effect but with the opportunity to review the the changes that Terraform has
|
|
|
|
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
|
|
|
|
introduced in Terraform v1.0. For prior versions you must use
|
|
|
|
`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.
|