mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
@@ -1,13 +1,16 @@
|
||||
---
|
||||
page_title: 'Command: state'
|
||||
description: The `terraform state` command is used for advanced state management.
|
||||
layout: "docs"
|
||||
page_title: "Command: state"
|
||||
sidebar_current: "docs-commands-state-index"
|
||||
description: |-
|
||||
The `terraform state` command is used for advanced state management.
|
||||
---
|
||||
|
||||
# State Command
|
||||
|
||||
The `terraform state` command is used for advanced state management.
|
||||
As your Terraform usage becomes more advanced, there are some cases where
|
||||
you may need to modify the [Terraform state](/language/state/).
|
||||
you may need to modify the [Terraform state](/docs/language/state/index.html).
|
||||
Rather than modify the state directly, the `terraform state` commands can
|
||||
be used in many cases instead.
|
||||
|
||||
@@ -32,7 +35,7 @@ written to disk and the CLI usage is the same as if it were local state.
|
||||
All `terraform state` subcommands that modify the state write backup
|
||||
files. The path of these backup file can be controlled with `-backup`.
|
||||
|
||||
Subcommands that are read-only (such as [list](/cli/commands/state/list))
|
||||
Subcommands that are read-only (such as [list](/docs/cli/commands/state/list.html))
|
||||
do not write any backup files since they aren't modifying the state.
|
||||
|
||||
Note that backups for state modification _can not be disabled_. Due to
|
||||
@@ -1,14 +1,15 @@
|
||||
---
|
||||
page_title: 'Command: state list'
|
||||
description: >-
|
||||
The terraform state list command is used to list resources within a Terraform
|
||||
state.
|
||||
layout: "docs"
|
||||
page_title: "Command: state list"
|
||||
sidebar_current: "docs-commands-state-sub-list"
|
||||
description: |-
|
||||
The terraform state list command is used to list resources within a Terraform state.
|
||||
---
|
||||
|
||||
# Command: state list
|
||||
|
||||
The `terraform state list` command is used to list resources within a
|
||||
[Terraform state](/language/state/).
|
||||
[Terraform state](/docs/language/state/index.html).
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -24,12 +25,12 @@ within modules are listed last.
|
||||
|
||||
For complex infrastructures, the state can contain thousands of resources.
|
||||
To filter these, provide one or more patterns to the command. Patterns are
|
||||
in [resource addressing format](/cli/state/resource-addressing).
|
||||
in [resource addressing format](/docs/cli/state/resource-addressing.html).
|
||||
|
||||
The command-line flags are all optional. The list of available flags are:
|
||||
|
||||
* `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
|
||||
Ignored when [remote state](/language/state/remote) is used.
|
||||
Ignored when [remote state](/docs/language/state/remote.html) is used.
|
||||
* `-id=id` - ID of resources to show. Ignored when unset.
|
||||
|
||||
## Example: All Resources
|
||||
@@ -1,13 +1,14 @@
|
||||
---
|
||||
page_title: 'Command: state mv'
|
||||
description: >-
|
||||
The `terraform state mv` command changes bindings in Terraform state,
|
||||
associating existing remote objects with new resource instances.
|
||||
layout: "docs"
|
||||
page_title: "Command: state mv"
|
||||
sidebar_current: "docs-commands-state-sub-mv"
|
||||
description: |-
|
||||
The `terraform state mv` command changes bindings in Terraform state, associating existing remote objects with new resource instances.
|
||||
---
|
||||
|
||||
# Command: state mv
|
||||
|
||||
The main function of [Terraform state](/language/state/) is
|
||||
The main function of [Terraform state](/docs/language/state/index.html) is
|
||||
to track the bindings between resource instance addresses in your configuration
|
||||
and the remote objects they represent. Normally Terraform automatically
|
||||
updates the state in response to actions taken when applying a plan, such as
|
||||
@@ -28,7 +29,7 @@ remote objects currently associated with the source to be tracked instead
|
||||
by the destination.
|
||||
|
||||
Both the source and destination addresses must use
|
||||
[resource address syntax](/cli/state/resource-addressing), and
|
||||
[resource address syntax](/docs/cli/state/resource-addressing.html), and
|
||||
they must both refer to the same kind of object: you can only move a resource
|
||||
instance to another resource instance, a whole module instance to another
|
||||
whole module instance, etc. Furthermore, if you are moving a resource or
|
||||
@@ -44,7 +45,7 @@ object and create a new object at the new address, and so `terraform state mv`
|
||||
allows you to override that interpretation by pre-emptively attaching the
|
||||
existing object to the new address in Terraform.
|
||||
|
||||
~> _Warning:_ If you are using Terraform in a collaborative environment, you
|
||||
~> *Warning:* If you are using Terraform in a collaborative environment, you
|
||||
must ensure that when you are using `terraform state mv` for a code refactoring
|
||||
purpose you communicate carefully with your coworkers to ensure that nobody
|
||||
makes any other changes between your configuration change and your
|
||||
@@ -58,8 +59,8 @@ This command also accepts the following options:
|
||||
address without actually "forgetting" any of them.
|
||||
|
||||
* `-lock=false` - Don't hold a state lock during the operation. This is
|
||||
dangerous if others might concurrently run commands against the same
|
||||
workspace.
|
||||
dangerous if others might concurrently run commands against the same
|
||||
workspace.
|
||||
|
||||
* `-lock-timeout=DURATION` - Unless locking is disabled with `-lock=false`,
|
||||
instructs Terraform to retry acquiring a lock for a period of time before
|
||||
@@ -67,22 +68,23 @@ This command also accepts the following options:
|
||||
unit letter, such as "3s" for three seconds.
|
||||
|
||||
For configurations using
|
||||
[the `remote` backend](/language/settings/backends/remote)
|
||||
[the `remote` backend](/docs/language/settings/backends/remote.html)
|
||||
only, `terraform state mv`
|
||||
also accepts the option
|
||||
[`-ignore-remote-version`](/language/settings/backends/remote#command-line-arguments).
|
||||
[`-ignore-remote-version`](/docs/language/settings/backends/remote.html#command-line-arguments).
|
||||
|
||||
The legacy options [`-backup` and `-backup-out`](/language/settings/backends/local#command-line-arguments)
|
||||
The legacy options [`-backup` and `-backup-out`](/docs/language/settings/backends/local.html#command-line-arguments)
|
||||
operate on a local state file only. Configurations using
|
||||
[the `remote` backend](/language/settings/backends/remote)
|
||||
must specify a local state file with the [`-state`](/language/settings/backends/local#command-line-arguments)
|
||||
option in order to use the [`-backup` and `-backup-out`](/language/settings/backends/local#command-line-arguments)
|
||||
[the `remote` backend](/docs/language/settings/backends/remote.html)
|
||||
must specify a local state file with the [`-state`](/docs/language/settings/backends/local.html#command-line-arguments)
|
||||
option in order to use the [`-backup` and `-backup-out`](/docs/language/settings/backends/local.html#command-line-arguments)
|
||||
options.
|
||||
|
||||
|
||||
For configurations using
|
||||
[the `local` state mv](/language/settings/backends/local) only,
|
||||
[the `local` state mv](/docs/language/settings/backends/local.html) only,
|
||||
`terraform state mv` also accepts the legacy options
|
||||
[`-state`, `-state-out`, `-backup`, and `-backup-out`](/language/settings/backends/local#command-line-arguments).
|
||||
[`-state`, `-state-out`, `-backup`, and `-backup-out`](/docs/language/settings/backends/local.html#command-line-arguments).
|
||||
|
||||
## Example: Rename a Resource
|
||||
|
||||
@@ -134,7 +136,7 @@ terraform state mv module.app module.parent.module.app
|
||||
|
||||
## Example: Move a Particular Instance of a Resource using `count`
|
||||
|
||||
A resource defined with [the `count` meta-argument](/language/meta-arguments/count)
|
||||
A resource defined with [the `count` meta-argument](/docs/language/meta-arguments/count.html)
|
||||
has multiple instances that are each identified by an integer. You can
|
||||
select a particular instance by including an explicit index in your given
|
||||
address:
|
||||
@@ -159,7 +161,7 @@ The above examples show the typical quoting syntax for Unix-style shells.
|
||||
|
||||
## Example: Move a Resource configured with for_each
|
||||
|
||||
A resource defined with [the `for_each` meta-argument](/language/meta-arguments/for_each)
|
||||
A resource defined with [the `for_each` meta-argument](/docs/language/meta-arguments/for_each.html)
|
||||
has multiple instances that are each identified by an string. You can
|
||||
select a particular instance by including an explicit key in your given
|
||||
address.
|
||||
@@ -1,14 +1,15 @@
|
||||
---
|
||||
page_title: 'Command: state pull'
|
||||
description: >-
|
||||
The `terraform state pull` command is used to manually download and output the
|
||||
state from remote state.
|
||||
layout: "docs"
|
||||
page_title: "Command: state pull"
|
||||
sidebar_current: "docs-commands-state-sub-pull"
|
||||
description: |-
|
||||
The `terraform state pull` command is used to manually download and output the state from remote state.
|
||||
---
|
||||
|
||||
# Command: state pull
|
||||
|
||||
The `terraform state pull` command is used to manually download and output
|
||||
the state from [remote state](/language/state/remote). This command also
|
||||
the state from [remote state](/docs/language/state/remote.html). This command also
|
||||
works with local state.
|
||||
|
||||
## Usage
|
||||
50
website/docs/cli/commands/state/push.html.md
Normal file
50
website/docs/cli/commands/state/push.html.md
Normal file
@@ -0,0 +1,50 @@
|
||||
---
|
||||
layout: "docs"
|
||||
page_title: "Command: state push"
|
||||
sidebar_current: "docs-commands-state-sub-push"
|
||||
description: |-
|
||||
The `terraform state push` command pushes items to the Terraform state.
|
||||
---
|
||||
|
||||
# Command: state push
|
||||
|
||||
The `terraform state push` command is used to manually upload a local
|
||||
state file to [remote state](/docs/language/state/remote.html). This command also
|
||||
works with local state.
|
||||
|
||||
This command should rarely be used. It is meant only as a utility in case
|
||||
manual intervention is necessary with the remote state.
|
||||
|
||||
## Usage
|
||||
|
||||
Usage: `terraform state push [options] PATH`
|
||||
|
||||
This command will push the state specified by PATH to the currently
|
||||
configured [backend](/docs/language/settings/backends/index.html).
|
||||
|
||||
If PATH is "-" then the state data to push is read from stdin. This data
|
||||
is loaded completely into memory and verified prior to being written to
|
||||
the destination state.
|
||||
|
||||
Terraform will perform a number of safety checks to prevent you from
|
||||
making changes that appear to be unsafe:
|
||||
|
||||
* **Differing lineage**: If the "lineage" value in the state differs,
|
||||
Terraform will not allow you to push the state. A differing lineage
|
||||
suggests that the states are completely different and you may lose
|
||||
data.
|
||||
|
||||
* **Higher remote serial**: If the "serial" value in the destination state
|
||||
is higher than the state being pushed, Terraform will prevent the push.
|
||||
A higher serial suggests that data is in the destination state that isn't
|
||||
accounted for in the local state being pushed.
|
||||
|
||||
Both of these safety checks can be disabled with the `-force` flag.
|
||||
**This is not recommended.** If you disable the safety checks and are
|
||||
pushing state, the destination state will be overwritten.
|
||||
|
||||
For configurations using
|
||||
[the `remote` backend](/docs/language/settings/backends/remote.html)
|
||||
only, `terraform state push`
|
||||
also accepts the option
|
||||
[`-ignore-remote-version`](/docs/language/settings/backends/remote.html#command-line-arguments).
|
||||
@@ -1,47 +0,0 @@
|
||||
---
|
||||
page_title: 'Command: state push'
|
||||
description: The `terraform state push` command pushes items to the Terraform state.
|
||||
---
|
||||
|
||||
# Command: state push
|
||||
|
||||
The `terraform state push` command is used to manually upload a local
|
||||
state file to [remote state](/language/state/remote). This command also
|
||||
works with local state.
|
||||
|
||||
This command should rarely be used. It is meant only as a utility in case
|
||||
manual intervention is necessary with the remote state.
|
||||
|
||||
## Usage
|
||||
|
||||
Usage: `terraform state push [options] PATH`
|
||||
|
||||
This command will push the state specified by PATH to the currently
|
||||
configured [backend](/language/settings/backends/).
|
||||
|
||||
If PATH is "-" then the state data to push is read from stdin. This data
|
||||
is loaded completely into memory and verified prior to being written to
|
||||
the destination state.
|
||||
|
||||
Terraform will perform a number of safety checks to prevent you from
|
||||
making changes that appear to be unsafe:
|
||||
|
||||
- **Differing lineage**: If the "lineage" value in the state differs,
|
||||
Terraform will not allow you to push the state. A differing lineage
|
||||
suggests that the states are completely different and you may lose
|
||||
data.
|
||||
|
||||
- **Higher remote serial**: If the "serial" value in the destination state
|
||||
is higher than the state being pushed, Terraform will prevent the push.
|
||||
A higher serial suggests that data is in the destination state that isn't
|
||||
accounted for in the local state being pushed.
|
||||
|
||||
Both of these safety checks can be disabled with the `-force` flag.
|
||||
**This is not recommended.** If you disable the safety checks and are
|
||||
pushing state, the destination state will be overwritten.
|
||||
|
||||
For configurations using
|
||||
[the `remote` backend](/language/settings/backends/remote)
|
||||
only, `terraform state push`
|
||||
also accepts the option
|
||||
[`-ignore-remote-version`](/language/settings/backends/remote#command-line-arguments).
|
||||
@@ -1,14 +1,15 @@
|
||||
---
|
||||
page_title: 'Command: state replace-provider'
|
||||
description: >-
|
||||
The `terraform state replace-provider` command replaces the provider for
|
||||
resources in the Terraform state.
|
||||
layout: "docs"
|
||||
page_title: "Command: state replace-provider"
|
||||
sidebar_current: "docs-commands-state-sub-replace-provider"
|
||||
description: |-
|
||||
The `terraform state replace-provider` command replaces the provider for resources in the Terraform state.
|
||||
---
|
||||
|
||||
# Command: state replace-provider
|
||||
|
||||
The `terraform state replace-provider` command is used to replace the provider
|
||||
for resources in a [Terraform state](/language/state/).
|
||||
for resources in a [Terraform state](/docs/language/state/index.html).
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -27,21 +28,22 @@ This command also accepts the following options:
|
||||
* `-auto-approve` - Skip interactive approval.
|
||||
|
||||
* `-lock=false` - Don't hold a state lock during the operation. This is
|
||||
dangerous if others might concurrently run commands against the same
|
||||
workspace.
|
||||
dangerous if others might concurrently run commands against the same
|
||||
workspace.
|
||||
|
||||
* `-lock-timeout=0s` - Duration to retry a state lock.
|
||||
|
||||
For configurations using
|
||||
[the `remote` backend](/language/settings/backends/remote)
|
||||
[the `remote` backend](/docs/language/settings/backends/remote.html)
|
||||
only, `terraform state replace-provider`
|
||||
also accepts the option
|
||||
[`-ignore-remote-version`](/language/settings/backends/remote#command-line-arguments).
|
||||
[`-ignore-remote-version`](/docs/language/settings/backends/remote.html#command-line-arguments).
|
||||
|
||||
For configurations using
|
||||
[the `local` state rm](/language/settings/backends/local) only,
|
||||
[the `local` state rm](/docs/language/settings/backends/local.html) only,
|
||||
`terraform state replace-provider` also accepts the legacy options
|
||||
[`-state`, `-state-out`, and `-backup`](/language/settings/backends/local#command-line-arguments).
|
||||
[`-state`, `-state-out`, and `-backup`](/docs/language/settings/backends/local.html#command-line-arguments).
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
---
|
||||
page_title: 'Command: state rm'
|
||||
description: >-
|
||||
The `terraform state rm` command removes bindings from the Terraform state,
|
||||
causing Terraform to "forget about" existing objects.
|
||||
layout: "docs"
|
||||
page_title: "Command: state rm"
|
||||
sidebar_current: "docs-commands-state-sub-rm"
|
||||
description: |-
|
||||
The `terraform state rm` command removes bindings from the Terraform state, causing Terraform to "forget about" existing objects.
|
||||
---
|
||||
|
||||
# Command: state rm
|
||||
|
||||
The main function of [Terraform state](/language/state/) is
|
||||
The main function of [Terraform state](/docs/language/state/index.html) is
|
||||
to track the bindings between resource instance addresses in your configuration
|
||||
and the remote objects they represent. Normally Terraform automatically
|
||||
updates the state in response to actions taken when applying a plan, such as
|
||||
@@ -23,13 +24,13 @@ to exist in the remote system.
|
||||
Usage: `terraform state rm [options] ADDRESS...`
|
||||
|
||||
Terraform will search the state for any instances matching the given
|
||||
[resource address](/cli/state/resource-addressing), and remove
|
||||
[resource address](/docs/cli/state/resource-addressing.html), and remove
|
||||
the record of each one so that Terraform will no longer be tracking the
|
||||
corresponding remote objects.
|
||||
|
||||
This means that although the objects will still continue to exist in the
|
||||
remote system, a subsequent
|
||||
[`terraform plan`](/cli/commands/plan)
|
||||
[`terraform plan`](../plan.html)
|
||||
will include an action to create a new object for each of the "forgotten"
|
||||
instances. Depending on the constraints imposed by the remote system, creating
|
||||
those objects might fail if their names or other identifiers conflict with
|
||||
@@ -41,8 +42,8 @@ This command also accepts the following options:
|
||||
address without actually "forgetting" any of them.
|
||||
|
||||
* `-lock=false` - Don't hold a state lock during the operation. This is
|
||||
dangerous if others might concurrently run commands against the same
|
||||
workspace.
|
||||
dangerous if others might concurrently run commands against the same
|
||||
workspace.
|
||||
|
||||
* `-lock-timeout=DURATION` - Unless locking is disabled with `-lock=false`,
|
||||
instructs Terraform to retry acquiring a lock for a period of time before
|
||||
@@ -50,15 +51,15 @@ This command also accepts the following options:
|
||||
unit letter, such as "3s" for three seconds.
|
||||
|
||||
For configurations using
|
||||
[the `remote` backend](/language/settings/backends/remote)
|
||||
[the `remote` backend](/docs/language/settings/backends/remote.html)
|
||||
only, `terraform state rm`
|
||||
also accepts the option
|
||||
[`-ignore-remote-version`](/language/settings/backends/remote#command-line-arguments).
|
||||
[`-ignore-remote-version`](/docs/language/settings/backends/remote.html#command-line-arguments).
|
||||
|
||||
For configurations using
|
||||
[the `local` state rm](/language/settings/backends/local) only,
|
||||
[the `local` state rm](/docs/language/settings/backends/local.html) only,
|
||||
`terraform state rm` also accepts the legacy options
|
||||
[`-state`, `-state-out`, and `-backup`](/language/settings/backends/local#command-line-arguments).
|
||||
[`-state`, `-state-out`, and `-backup`](/docs/language/settings/backends/local.html#command-line-arguments).
|
||||
|
||||
## Example: Remove all Instances of a Resource
|
||||
|
||||
@@ -93,7 +94,7 @@ $ terraform state rm 'module.foo'
|
||||
|
||||
## Example: Remove a Particular Instance of a Resource using `count`
|
||||
|
||||
A resource defined with [the `count` meta-argument](/language/meta-arguments/count)
|
||||
A resource defined with [the `count` meta-argument](/docs/language/meta-arguments/count.html)
|
||||
has multiple instances that are each identified by an integer. You can
|
||||
select a particular instance by including an explicit index in your given
|
||||
address:
|
||||
@@ -108,7 +109,7 @@ The above shows the typical quoting syntax for Unix-style shells.
|
||||
|
||||
## Example: Remove a Particular Instance of a Resource using `for_each`
|
||||
|
||||
A resource defined with [the `for_each` meta-argument](/language/meta-arguments/for_each)
|
||||
A resource defined with [the `for_each` meta-argument](/docs/language/meta-arguments/for_each.html)
|
||||
has multiple instances that are each identified by an string. You can
|
||||
select a particular instance by including an explicit key in your given
|
||||
address.
|
||||
@@ -1,15 +1,16 @@
|
||||
---
|
||||
page_title: 'Command: state show'
|
||||
description: >-
|
||||
The `terraform state show` command is used to show the attributes of a single
|
||||
resource in the Terraform state.
|
||||
layout: "docs"
|
||||
page_title: "Command: state show"
|
||||
sidebar_current: "docs-commands-state-sub-show"
|
||||
description: |-
|
||||
The `terraform state show` command is used to show the attributes of a single resource in the Terraform state.
|
||||
---
|
||||
|
||||
# Command: state show
|
||||
|
||||
The `terraform state show` command is used to show the attributes of a
|
||||
single resource in the
|
||||
[Terraform state](/language/state/).
|
||||
[Terraform state](/docs/language/state/index.html).
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -20,16 +21,16 @@ state file that matches the given address.
|
||||
|
||||
This command requires an address that points to a single resource in the
|
||||
state. Addresses are
|
||||
in [resource addressing format](/cli/state/resource-addressing).
|
||||
in [resource addressing format](/docs/cli/state/resource-addressing.html).
|
||||
|
||||
The command-line flags are all optional. The list of available flags are:
|
||||
|
||||
* `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
|
||||
Ignored when [remote state](/language/state/remote) is used.
|
||||
Ignored when [remote state](/docs/language/state/remote.html) is used.
|
||||
|
||||
The output of `terraform state show` is intended for human consumption, not
|
||||
programmatic consumption. To extract state data for use in other software, use
|
||||
[`terraform show -json`](/cli/commands/show#json-output) and decode the result
|
||||
[`terraform show -json`](/docs/cli/commands/show.html#json-output) and decode the result
|
||||
using the documented structure.
|
||||
|
||||
## Example: Show a Resource
|
||||
@@ -60,7 +61,7 @@ $ terraform state show 'module.foo.packet_device.worker'
|
||||
## Example: Show a Resource configured with count
|
||||
|
||||
The example below shows the first instance of a `packet_device` resource named `worker` configured with
|
||||
[`count`](/language/meta-arguments/count):
|
||||
[`count`](/docs/language/meta-arguments/count.html):
|
||||
|
||||
```shell
|
||||
$ terraform state show 'packet_device.worker[0]'
|
||||
@@ -69,7 +70,7 @@ $ terraform state show 'packet_device.worker[0]'
|
||||
## Example: Show a Resource configured with for_each
|
||||
|
||||
The example below shows the `"example"` instance of a `packet_device` resource named `worker` configured with
|
||||
[`for_each`](/language/meta-arguments/for_each):
|
||||
[`for_each`](/docs/language/meta-arguments/for_each.html):
|
||||
|
||||
Linux, Mac OS, and UNIX:
|
||||
|
||||
Reference in New Issue
Block a user