Files
opentf/website/source/docs/commands/state/index.html.md
Mitchell Hashimoto d1b46e99bd Add terraform state list command
This introduces the terraform state list command to list the resources
within a state. This is the first of many state management commands to
come into 0.7.

This is the first command of many to come that is considered a
"plumbing" command within Terraform (see "plumbing vs porcelain":
http://git.661346.n2.nabble.com/what-are-plumbing-and-porcelain-td2190639.html).
As such, this PR also introduces a bunch of groundwork to support
plumbing commands.

The main changes:

- Main command output is changed to split "common" and "uncommon"
  commands.

- mitchellh/cli is updated to support nested subcommands, since
  terraform state list is a nested subcommand.

- terraform.StateFilter is introduced as a way in core to filter/search
  the state files. This is very basic currently but I expect to make it
  more advanced as time goes on.

- terraform state list command is introduced to list resources in a
  state. This can take a series of arguments to filter this down.

Known issues, or things that aren't done in this PR on purpose:

- Unit tests for terraform state list are on the way. Unit tests for the
  core changes are all there.
2016-05-10 14:14:47 -04:00

2.0 KiB

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
commands-state Command: state docs-state-index 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. Rather than modify the state directly, the terraform state commands can be used in many cases instead.

This command is a nested subcommand, meaning that it has further subcommands. These subcommands are listed to the left.

Usage

Usage: terraform state <subcommand> [options] [args]

Please click a subcommand to the left for more information.

Remote State

The Terraform state subcommands all work with remote state just as if it was local state. Reads and writes may take longer than normal as each read and each write do a full network roundtrip. Otherwise, backups are still written to disk and the CLI usage is the same as if it were local state.

Backups

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) 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 the sensitivity of the state file, Terraform forces every state modification command to write a backup file. You'll have to remove these files manually if you don't want to keep them around.

Command-Line Friendly

The output and command-line structure of the state subcommands is designed to be easy to use with Unix command-line tools such as grep, awk, etc. Consequently, the output is also friendly to the equivalent PowerShell commands within Windows.

For advanced filtering and modification, we recommend piping Terraform state subcommands together with other command line tools.