github.com/hugorut/terraform@v1.1.3/website/docs/cli/commands/state/list.mdx (about)

     1  ---
     2  page_title: 'Command: state list'
     3  description: >-
     4    The terraform state list command is used to list resources within a Terraform
     5    state.
     6  ---
     7  
     8  # Command: state list
     9  
    10  The `terraform state list` command is used to list resources within a
    11  [Terraform state](/language/state).
    12  
    13  ## Usage
    14  
    15  Usage: `terraform state list [options] [address...]`
    16  
    17  The command will list all resources in the state file matching the given
    18  addresses (if any). If no addresses are given, all resources are listed.
    19  
    20  The resources listed are sorted according to module depth order followed
    21  by alphabetical. This means that resources that are in your immediate
    22  configuration are listed first, and resources that are more deeply nested
    23  within modules are listed last.
    24  
    25  For complex infrastructures, the state can contain thousands of resources.
    26  To filter these, provide one or more patterns to the command. Patterns are
    27  in [resource addressing format](/cli/state/resource-addressing).
    28  
    29  The command-line flags are all optional. The list of available flags are:
    30  
    31  * `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
    32    Ignored when [remote state](/language/state/remote) is used.
    33  * `-id=id` - ID of resources to show. Ignored when unset.
    34  
    35  ## Example: All Resources
    36  
    37  This example will list all resources, including modules:
    38  
    39  ```
    40  $ terraform state list
    41  aws_instance.foo
    42  aws_instance.bar[0]
    43  aws_instance.bar[1]
    44  module.elb.aws_elb.main
    45  ```
    46  
    47  ## Example: Filtering by Resource
    48  
    49  This example will only list resources for the given name:
    50  
    51  ```
    52  $ terraform state list aws_instance.bar
    53  aws_instance.bar[0]
    54  aws_instance.bar[1]
    55  ```
    56  
    57  ## Example: Filtering by Module
    58  
    59  This example will list resources in the given module and any submodules:
    60  
    61  ```
    62  $ terraform state list module.elb
    63  module.elb.aws_elb.main
    64  module.elb.module.secgroups.aws_security_group.sg
    65  ```
    66  
    67  ## Example: Filtering by ID
    68  
    69  This example will only list the resource whose ID is specified on the
    70  command line. This is useful to find where in your configuration a
    71  specific resource is located.
    72  
    73  ```
    74  $ terraform state list -id=sg-1234abcd
    75  module.elb.aws_security_group.sg
    76  ```