terraform/website/docs/cli/commands/refresh.mdx

69 lines
2.7 KiB
Plaintext
Raw Normal View History

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: |-
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
> **Hands-on:** Try the [Use Refresh-Only Mode to Sync Terraform State](https://learn.hashicorp.com/tutorials/terraform/refresh) tutorial on HashiCorp Learn.
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
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
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
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)
and
2021-12-15 03:41:17 +01:00
[`terraform apply`](/cli/commands/apply)
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
## Usage
Usage: `terraform refresh [options]`
2017-04-04 19:48:59 +02:00
This command is effectively an alias for the following command:
2017-04-04 19:48:59 +02:00
```
terraform apply -refresh-only -auto-approve
```
2017-04-04 19:48: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
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
Automatically applying the effect of a refresh is risky. If you have
misconfigured credentials for one or more providers, Terraform may
be misled into thinking that all of the managed objects have been deleted,
causing it to remove all of the tracked objects without any confirmation prompt.
Instead, we recommend using the following command in order to get the same
effect but with the opportunity to review the changes that Terraform has
detected before committing them to the state:
2015-03-27 23:24:15 +01:00
```
terraform apply -refresh-only
```
2014-07-24 18:02:10 +02:00
This alternative command will present an interactive prompt for you to confirm
the detected changes.
command: Reorganize docs of the local backend's legacy CLI options We have these funny extra options that date back to before Terraform even had remote state, which we've preserved along the way by most recently incorporating them as special-case overrides for the local backend. The documentation we had for these has grown less accurate over time as the details have shifted, and was in many cases missing the requisite caveats that they are only for the local backend and that backend configuration is the modern, preferred way to deal with the use-cases they were intended for. We always have a bit of a tension with this sort of legacy option because we want to keep them documented just enough to be useful to someone who finds an existing script/etc using them and wants to know what they do, but not to take up so much space that they might distract users from finding the modern alternative they should consider instead. As a compromise in that vein here I've created a new section about these options under the local backend documentation, which then gives us the space to go into some detail about the various behaviors and interactions and also to discuss their history and our recommended alternatives. I then simplified all of the other mentions of these in command documentation to just link to or refer to the local backend documentation. My hope then is that folks who need to know what these do can still find the docs, but that information can be kept out of the direct path of new users so they can focus on learning about remote backends instead. This is certainly not the most ideal thing ever, but it seemed like the best compromise between the competing priorities I described above.
2021-03-25 00:17:03 +01:00
The `-refresh-only` option for `terraform plan` and `terraform apply` was
introduced in Terraform v0.15.4. 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.