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: |-
The `terraform refresh` command is used to reconcile the state Terraform knows about (via its state file) with the real-world infrastructure. This can be used to detect any drift from the last-known state, and to update the state file.
2014-07-24 18:02:10 +02:00
---
# Command: refresh
The `terraform refresh` command is used to reconcile the state Terraform
2014-07-28 22:09:32 +02:00
knows about (via its state file) with the real-world infrastructure.
2014-10-16 18:16:52 +02:00
This can be used to detect any drift from the last-known state, and to
2014-07-24 18:02:10 +02:00
update the state file.
This does not modify infrastructure, but does modify the state file.
If the state is changed, this may cause changes to occur during the next
plan or apply.
## Usage
main: new global option -chdir
This new option is intended to address the previous inconsistencies where
some older subcommands supported partially changing the target directory
(where Terraform would use the new directory inconsistently) where newer
commands did not support that override at all.
Instead, now Terraform will accept a -chdir command at the start of the
command line (before the subcommand) and will interpret it as a request
to direct all actions that would normally be taken in the current working
directory into the target directory instead. This is similar to options
offered by some other similar tools, such as the -C option in "make".
The new option is only accepted at the start of the command line (before
the subcommand) as a way to reflect that it is a global command (not
specific to a particular subcommand) and that it takes effect _before_
executing the subcommand. This also means it'll be forced to appear before
any other command-specific arguments that take file paths, which hopefully
communicates that those other arguments are interpreted relative to the
overridden path.
As a measure of pragmatism for existing uses, the path.cwd object in
the Terraform language will continue to return the _original_ working
directory (ignoring -chdir), in case that is important in some exceptional
workflows. The path.root object gives the root module directory, which
will always match the overriden working directory unless the user
simultaneously uses one of the legacy directory override arguments, which
is not a pattern we intend to support in the long run.
As a first step down the deprecation path, this commit adjusts the
documentation to de-emphasize the inconsistent old command line arguments,
including specific guidance on what to use instead for the main three
workflow commands, but all of those options remain supported in the same
way as they were before. In a later commit we'll make those arguments
produce a visible deprecation warning in Terraform's output, and then
in an even later commit we'll remove them entirely so that -chdir is the
single supported way to run Terraform from a directory other than the
one containing the root module configuration.
2020-09-02 00:45:12 +02:00
Usage: `terraform refresh [options]`
2014-07-24 18:02:10 +02:00
main: new global option -chdir
This new option is intended to address the previous inconsistencies where
some older subcommands supported partially changing the target directory
(where Terraform would use the new directory inconsistently) where newer
commands did not support that override at all.
Instead, now Terraform will accept a -chdir command at the start of the
command line (before the subcommand) and will interpret it as a request
to direct all actions that would normally be taken in the current working
directory into the target directory instead. This is similar to options
offered by some other similar tools, such as the -C option in "make".
The new option is only accepted at the start of the command line (before
the subcommand) as a way to reflect that it is a global command (not
specific to a particular subcommand) and that it takes effect _before_
executing the subcommand. This also means it'll be forced to appear before
any other command-specific arguments that take file paths, which hopefully
communicates that those other arguments are interpreted relative to the
overridden path.
As a measure of pragmatism for existing uses, the path.cwd object in
the Terraform language will continue to return the _original_ working
directory (ignoring -chdir), in case that is important in some exceptional
workflows. The path.root object gives the root module directory, which
will always match the overriden working directory unless the user
simultaneously uses one of the legacy directory override arguments, which
is not a pattern we intend to support in the long run.
As a first step down the deprecation path, this commit adjusts the
documentation to de-emphasize the inconsistent old command line arguments,
including specific guidance on what to use instead for the main three
workflow commands, but all of those options remain supported in the same
way as they were before. In a later commit we'll make those arguments
produce a visible deprecation warning in Terraform's output, and then
in an even later commit we'll remove them entirely so that -chdir is the
single supported way to run Terraform from a directory other than the
one containing the root module configuration.
2020-09-02 00:45:12 +02:00
The `terraform refresh` command accepts the following options:
2014-07-24 18:02:10 +02:00
2014-07-28 05:40:18 +02:00
* `-backup=path` - Path to the backup file. Defaults to `-state-out` with
2014-08-07 09:19:56 +02:00
the ".backup" extension. Disabled by setting to "-".
2014-07-28 05:40:18 +02:00
2019-12-10 20:06:06 +01:00
* `-compact-warnings` - If Terraform produces any warnings that are not
accompanied by errors, show them in a more compact form that includes only
the summary messages.
2017-04-04 19:48:59 +02:00
* `-input=true` - Ask for input for variables if not directly set.
* `-lock=true` - Lock the state file when locking is supported.
* `-lock-timeout=0s` - Duration to retry a state lock.
* `-no-color` - If specified, output won't contain any color.
2019-03-06 15:25:36 +01:00
* `-parallelism=n` - Limit the number of concurrent operation as Terraform
[walks the graph ](/docs/internals/graph.html#walking-the-graph ). Defaults
to 10.
2014-07-24 18:02:10 +02:00
* `-state=path` - Path to read and write the state file to. Defaults to "terraform.tfstate".
2021-01-15 23:13:53 +01:00
Ignored when [remote state ](/docs/language/state/remote.html ) is used.
2014-07-24 18:02:10 +02:00
* `-state-out=path` - Path to write updated state file. By default, the
2016-08-08 02:59:28 +02:00
`-state` path will be used. Ignored when
2021-01-15 23:13:53 +01:00
[remote state ](/docs/language/state/remote.html ) is used.
2014-07-24 18:02:10 +02:00
2015-04-01 01:48:54 +02:00
* `-target=resource` - A [Resource
2021-01-19 22:43:01 +01:00
Address](/docs/cli/state/resource-addressing.html) to target. Operation will
2015-04-01 01:48:54 +02:00
be limited to this resource and its dependencies. This flag can be used
multiple times.
2015-03-27 23:24:15 +01:00
2016-07-12 00:37:51 +02:00
* `-var 'foo=bar'` - Set a variable in the Terraform configuration. This flag
can be set multiple times. Variable values are interpreted as
2021-01-15 23:13:53 +01:00
[literal expressions ](/docs/language/expressions/types.html ) in the
2020-12-17 00:10:49 +01:00
Terraform language, so list and map values can be specified via this flag.
2014-07-24 18:02:10 +02:00
* `-var-file=foo` - Set variables in the Terraform configuration from
2021-01-15 23:13:53 +01:00
a [variable file ](/docs/language/values/variables.html#variable-definitions-tfvars-files ). If
2017-06-22 03:22:07 +02:00
a `terraform.tfvars` or any `.auto.tfvars` files are present in the current
directory, they will be automatically loaded. `terraform.tfvars` is loaded
first and the `.auto.tfvars` files after in alphabetical order. Any files
specified by `-var-file` override any values set automatically from files in
the working directory. This flag can be used multiple times.