2016-03-25 18:26:30 +01:00
|
|
|
---
|
2020-10-27 01:58:30 +01:00
|
|
|
layout: "docs"
|
2016-03-25 18:26:30 +01:00
|
|
|
page_title: "Command: state show"
|
2018-12-21 03:18:13 +01:00
|
|
|
sidebar_current: "docs-commands-state-sub-show"
|
2016-03-25 18:26:30 +01:00
|
|
|
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
|
2021-01-15 23:13:53 +01:00
|
|
|
[Terraform state](/docs/language/state/index.html).
|
2016-03-25 18:26:30 +01:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2016-03-25 22:33:31 +01:00
|
|
|
Usage: `terraform state show [options] ADDRESS`
|
2016-03-25 18:26:30 +01:00
|
|
|
|
|
|
|
The command will show the attributes of a single resource in the
|
2016-03-25 22:33:31 +01:00
|
|
|
state file that matches the given address.
|
2016-03-25 18:26:30 +01:00
|
|
|
|
2019-03-21 22:05:41 +01:00
|
|
|
This command requires an address that points to a single resource in the
|
2016-03-25 22:33:31 +01:00
|
|
|
state. Addresses are
|
2016-03-25 18:26:30 +01:00
|
|
|
in [resource addressing format](/docs/commands/state/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".
|
2021-01-15 23:13:53 +01:00
|
|
|
Ignored when [remote state](/docs/language/state/remote.html) is used.
|
2016-03-25 18:26:30 +01:00
|
|
|
|
2020-01-07 00:44:30 +01:00
|
|
|
The output of `terraform state show` is intended for human consumption, not
|
|
|
|
programmatic consumption. To extract state data for use in other software, use
|
2021-01-19 22:43:01 +01:00
|
|
|
[`terraform show -json`](/docs/cli/commands/show.html#json-output) and decode the result
|
2020-01-07 00:44:30 +01:00
|
|
|
using the documented structure.
|
|
|
|
|
2016-03-25 18:26:30 +01:00
|
|
|
## Example: Show a Resource
|
|
|
|
|
2019-08-03 01:36:24 +02:00
|
|
|
The example below shows a `packet_device` resource named `worker`:
|
2016-03-25 18:26:30 +01:00
|
|
|
|
|
|
|
```
|
2019-08-03 01:36:24 +02:00
|
|
|
$ terraform state show 'packet_device.worker'
|
2020-07-20 15:15:47 +02:00
|
|
|
# packet_device.worker:
|
|
|
|
resource "packet_device" "worker" {
|
|
|
|
billing_cycle = "hourly"
|
|
|
|
created = "2015-12-17T00:06:56Z"
|
|
|
|
facility = "ewr1"
|
|
|
|
hostname = "prod-xyz01"
|
|
|
|
id = "6015bg2b-b8c4-4925-aad2-f0671d5d3b13"
|
|
|
|
locked = false
|
|
|
|
}
|
2016-03-25 18:26:30 +01:00
|
|
|
```
|
2019-08-03 01:36:24 +02:00
|
|
|
|
|
|
|
## Example: Show a Module Resource
|
|
|
|
|
|
|
|
The example below shows a `packet_device` resource named `worker` inside a module named `foo`:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ terraform state show 'module.foo.packet_device.worker'
|
|
|
|
```
|
|
|
|
|
2019-08-06 03:50:17 +02:00
|
|
|
## Example: Show a Resource configured with count
|
2019-08-03 01:36:24 +02:00
|
|
|
|
2019-08-06 03:50:17 +02:00
|
|
|
The example below shows the first instance of a `packet_device` resource named `worker` configured with
|
2021-01-15 23:13:53 +01:00
|
|
|
[`count`](/docs/language/meta-arguments/count.html):
|
2019-08-03 01:36:24 +02:00
|
|
|
|
|
|
|
```shell
|
|
|
|
$ terraform state show 'packet_device.worker[0]'
|
|
|
|
```
|
|
|
|
|
2019-08-06 03:50:17 +02:00
|
|
|
## Example: Show a Resource configured with for_each
|
2019-08-03 01:36:24 +02:00
|
|
|
|
2019-08-06 03:50:17 +02:00
|
|
|
The example below shows the `"example"` instance of a `packet_device` resource named `worker` configured with
|
2021-01-15 23:13:53 +01:00
|
|
|
[`for_each`](/docs/language/meta-arguments/for_each.html):
|
2019-08-03 01:36:24 +02:00
|
|
|
|
|
|
|
Linux, Mac OS, and UNIX:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ terraform state show 'packet_device.worker["example"]'
|
|
|
|
```
|
|
|
|
|
|
|
|
PowerShell:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ terraform state show 'packet_device.worker[\"example\"]'
|
|
|
|
```
|
|
|
|
|
|
|
|
Windows `cmd.exe`:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ terraform state show packet_device.worker[\"example\"]
|
|
|
|
```
|