Files
opentf/website/source/docs/commands/state/list.html.md
Mitchell Hashimoto 473a58a672 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:49:14 -04:00

1.7 KiB

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
commands-state Command: state list docs-state-sub-list 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.

Usage

Usage: terraform state list [options] [address...]

The command will list all resources in the state file matching the given addresses (if any). If no addresses are given, all resources are listed.

The resources listed are sorted according to module depth order followed by alphabetical. This means that resources that are in your immediate configuration are listed first, and resources that are more deeply nested 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.

The command-line flags are all optional. The list of available flags are:

  • -state=path - Path to the state file. Defaults to "terraform.tfstate".

Example: All Resources

This example will list all resources, including modules:

$ terraform state list
aws_instance.foo
aws_instance.bar[0]
aws_instance.bar[1]
module.elb.aws_elb.main

Example: Filtering by Resource

This example will only list resources for the given name:

$ terraform state list aws_instance.bar
aws_instance.bar[0]
aws_instance.bar[1]

Example: Filtering by Module

This example will only list resources in the given module:

$ terraform state list module.elb
module.elb.aws_elb.main