2016-03-22 18:41:02 +01:00
|
|
|
---
|
2020-10-27 01:58:30 +01:00
|
|
|
layout: "docs"
|
2016-03-22 18:41:02 +01:00
|
|
|
page_title: "Command: state list"
|
2018-12-21 03:18:13 +01:00
|
|
|
sidebar_current: "docs-commands-state-sub-list"
|
2016-03-22 18:41:02 +01:00
|
|
|
description: |-
|
2016-03-25 18:26:30 +01:00
|
|
|
The terraform state list command is used to list resources within a Terraform state.
|
2016-03-22 18:41:02 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# Command: state list
|
|
|
|
|
|
|
|
The `terraform state list` command is used to list resources within a
|
2021-01-15 23:13:53 +01:00
|
|
|
[Terraform state](/docs/language/state/index.html).
|
2016-03-22 18:41:02 +01:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2016-03-25 22:33:31 +01:00
|
|
|
Usage: `terraform state list [options] [address...]`
|
2016-03-22 18:41:02 +01:00
|
|
|
|
|
|
|
The command will list all resources in the state file matching the given
|
2016-03-25 22:33:31 +01:00
|
|
|
addresses (if any). If no addresses are given, all resources are listed.
|
2016-03-22 18:41:02 +01:00
|
|
|
|
|
|
|
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.
|
2016-03-22 18:41:02 +01:00
|
|
|
To filter these, provide one or more patterns to the command. Patterns are
|
2021-01-19 23:51:44 +01:00
|
|
|
in [resource addressing format](/docs/cli/state/resource-addressing.html).
|
2016-03-22 18:41:02 +01:00
|
|
|
|
|
|
|
The command-line flags are all optional. The list of available flags are:
|
|
|
|
|
|
|
|
* `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
|
2021-01-15 23:13:53 +01:00
|
|
|
Ignored when [remote state](/docs/language/state/remote.html) is used.
|
2018-02-26 19:54:48 +01:00
|
|
|
* `-id=id` - ID of resources to show. Ignored when unset.
|
2016-03-22 18:41:02 +01:00
|
|
|
|
|
|
|
## 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
|
|
|
|
|
2020-12-14 17:07:15 +01:00
|
|
|
This example will list resources in the given module and any submodules:
|
2016-03-22 18:41:02 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
$ terraform state list module.elb
|
|
|
|
module.elb.aws_elb.main
|
2020-12-14 17:07:15 +01:00
|
|
|
module.elb.module.secgroups.aws_security_group.sg
|
2016-03-22 18:41:02 +01:00
|
|
|
```
|
2018-02-26 19:54:48 +01:00
|
|
|
|
|
|
|
## Example: Filtering by ID
|
|
|
|
|
|
|
|
This example will only list the resource whose ID is specified on the
|
|
|
|
command line. This is useful to find where in your configuration a
|
|
|
|
specific resource is located.
|
|
|
|
|
|
|
|
```
|
|
|
|
$ terraform state list -id=sg-1234abcd
|
|
|
|
module.elb.aws_security_group.sg
|
|
|
|
```
|