Synopsis
List the identities of resources in the stateUsage
Description
Theterraform state identities command lists the JSON format of the identities of resources in the Terraform state. Resource identities provide additional metadata about resources beyond their standard attributes.
This command outputs the identity information for resource instances in JSON format. You can optionally filter the results by providing resource or module addresses. If no addresses are provided, identities for all resource instances in the state are listed.
Positional Arguments
address...- Optional resource or module addresses to filter results. Multiple addresses can be specified.
Options
Produce JSON output. This flag is required for the command to execute.Default:
falsePath to a Terraform state file to use to look up Terraform-managed resources. By default, Terraform will consult the state of the currently-selected workspace.Example:
-state=terraform.tfstateFilters the results to include only instances whose resource types have an attribute named “id” whose value equals the given id string.Example:
-id=i-1234567890abcdef0Address Formats
The addresses must be either module addresses or absolute resource addresses:aws_instance.example- A specific resourcemodule.example- All resources in a modulemodule.example.module.child- All resources in a nested modulemodule.example.aws_instance.example- A specific resource in a module
Behavior
- If a resource exists but has no identity JSON, it will be skipped (identities are optional)
- An error will be returned if any specified filter addresses do not exist in the state
- If the state file is not found, an error is returned
- This is a read-only command that does not modify state
Exit Codes
- 0 - Success
- 1 - Error occurred (missing
-jsonflag, state loading errors, parsing errors, or invalid addresses)
Examples
List all resource identities
List identities for a specific resource
List identities for all resources in a module
vpc module.
Filter by resource ID
Use a specific state file
prod.tfstate file instead of the current workspace state.
List identities for multiple resources
Error when -json flag is missing
Notes
- This command ignores remote version conflicts since it is read-only
- Empty output (
{}) indicates no resources have identity information or no resources matched the filter criteria - Resource identities are provider-specific and may not be present for all resource types