---
description: >-
  The `tofu state show` command is used to show the attributes of a single
  resource in the OpenTofu state.
---

# Command: state show

The `tofu state show` command is used to show the attributes of a
single resource in the
[OpenTofu state](../../../language/state/index.mdx).

## Usage

Usage: `tofu state show [options] ADDRESS`

The command will show the attributes of a single resource in the
state file that matches the given address.

This command requires an address that points to a single resource in the
state. Addresses are
in [resource addressing format](../../../cli/state/resource-addressing.mdx).

:::note
Use of variables in [module sources](../../../language/modules/sources.mdx#support-for-variable-and-local-evaluation),
[backend configuration](../../../language/settings/backends/configuration.mdx#variables-and-locals),
or [encryption block](../../../language/state/encryption.mdx#configuration)
requires [assigning values to root module variables](../../../language/values/variables.mdx#assigning-values-to-root-module-variables)
when running `tofu show`.
:::

The command-line flags are all optional. The following flags are available:

* `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
  Ignored when [remote state](../../../language/state/remote.mdx) is used.

* `-var 'NAME=VALUE'` - Sets a value for a single
  [input variable](../../../language/values/variables.mdx) declared in the
  root module of the configuration. Use this option multiple times to set
  more than one variable. Refer to
  [Input Variables on the Command Line](../plan.mdx#input-variables-on-the-command-line) for more information.

* `-var-file=FILENAME` - Sets values for potentially many
  [input variables](../../../language/values/variables.mdx) declared in the
  root module of the configuration, using definitions from a
  ["tfvars" file](../../../language/values/variables.mdx#variable-definitions-tfvars-files).
  Use this option multiple times to include values from more than one file.

There are several other ways to set values for input variables in the root
module, aside from the `-var` and `-var-file` options. Refer to
[Assigning Values to Root Module Variables](../../../language/values/variables.mdx#assigning-values-to-root-module-variables) for more information.

The output of `tofu state show` is intended for human consumption, not
programmatic consumption. To extract state data for use in other software, use
[`tofu show -json`](../../../cli/commands/show.mdx#json-output) and decode the result
using the documented structure.

## Example: Show a Resource

The example below shows a `packet_device` resource named `worker`:

```
$ tofu state show 'packet_device.worker'
# 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
}
```

## Example: Show a Module Resource

The example below shows a `packet_device` resource named `worker` inside a module named `foo`:

```shell
$ tofu state show 'module.foo.packet_device.worker'
```

## Example: Show a Resource configured with count

The example below shows the first instance of a `packet_device` resource named `worker` configured with
[`count`](../../../language/meta-arguments/count.mdx):

```shell
$ tofu state show 'packet_device.worker[0]'
```

## Example: Show a Resource configured with for_each

The following example shows the `"example"` instance of a `packet_device` resource named `worker` configured with the [`for_each`](../../../language/meta-arguments/for_each.mdx) meta-argument. You must place the resource name in single quotes when it contains special characters like double quotes.

Linux, Mac OS, and UNIX:

```shell
$ tofu state show 'packet_device.worker["example"]'
```

PowerShell:

```shell
$ tofu state show 'packet_device.worker[\"example\"]'
```

Windows `cmd.exe`:

```shell
$ tofu state show packet_device.worker[\"example\"]
```
