terraform state show command
The terraform state show command shows the attributes of a
single resource in the
Terraform state.
Usage
Usage: terraform 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. The command-line flags are all optional. The following flags are available:
-state=path- Path to the state file. Defaults to "terraform.tfstate". Legacy option for the local backend only.-json- Displays the resource in machine-readable output
JSON output via the -json option requires Terraform v1.16 or later.
JSON Output
Add the -json command-line flag to generate machine-readable output.
For Terraform state files, including when no path is provided, terraform state
show -json shows a JSON representation of the requested resource.
If you updated providers that contain new schema versions since the state
was written, upgrade the state before so that Terraform can display it with
show -json. If you are viewing a state file, run terraform refresh
first.
The general output format for this command is:
{
"format_version": "1.0", // the json format version
"resource": { }, // the resource requested
"diagnostics": [] // any diagnostics
}
The resource output format is covered in detail in JSON Output Format.
Example: Show a Resource
The example below shows a packet_device resource named worker:
$ terraform 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 Resource with JSON output
The example below shows a packet_device resource named worker in the json output format:
$ terraform state show 'packet_device.worker' -json
{
"format_version": "1.0",
"resource": {
"address": "packet_device.worker",
"mode": "managed",
"type": "device",
"name": "worker",
"provider_name": "registry.terraform.io/hashicorp/packet",
"schema_version": 0,
"values": {
"billing_cycle": "hourly",
"created": "2015-12-17T00:06:56Z",
"facility": "ewr1",
"hostname": "prod-xyz01",
"id": "6015bg2b-b8c4-4925-aad2-f0671d5d3b13",
"locked": "false"
},
"sensitive_values": {}
},
"diagnostics": []
}
Example: Show a Module Resource
The example below shows a packet_device resource named worker inside a module named foo:
$ terraform 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:
$ terraform 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 meta-argument. You must place the resource name in single quotes when it contains special characters like double quotes.
Linux, Mac OS, and UNIX:
$ terraform state show 'packet_device.worker["example"]'
PowerShell:
$ terraform state show 'packet_device.worker[\"example\"]'
Windows cmd.exe:
$ terraform state show packet_device.worker[\"example\"]