Skip to main content
0 reactions

How to Use tofu show to Read OpenTofu State and Plans

A Terminal window running tofu show, which prints the local_file.note resource with its content Open every day, its checksums, its permissions and the filename note.txt.
tofu show prints what OpenTofu recorded about each resource.

tofu show prints what OpenTofu® knows, in a form you can read: the resources it manages and their recorded values, or the changes in a saved plan file.

Syntax

Plain text
tofu show [options]
tofu show -plan=<file> [options]
  • With no target, tofu show prints the latest state: every resource OpenTofu manages.
  • -plan=<file>: prints a saved plan file instead.
  • [options]: for example -json for machine-readable output, or -no-color.

All the options are in Command: show (opens in a new tab) in the OpenTofu docs.

This guide shows the state of one small file, then a saved plan that changes it.

Prerequisites

Step 1: Create a Resource

Create main.tf:

Plain text
resource "local_file" "note" {
  filename = "note.txt"
  content  = "Open every day"
}

Run tofu init, then tofu apply and type yes:

Bash
tofu init
tofu apply
Plain text
local_file.note: Creating...
local_file.note: Creation complete after 0s [id=c8871ea4eef30f5a5100f9e72c565dfd2bcce951]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Step 2: Show the State

Bash
tofu show
Plain text
# local_file.note:
resource "local_file" "note" {
    content              = "Open every day"
    content_base64sha256 = "+0oZ/4dmEBGXsb2EkY07j0vtsjlaWDI8eN1XY4SmPn0="
    content_base64sha512 = "hCkYy6RlZxoGR1X8S+x3FpGPsEudJzrHlJ+cXk9CpPA2KMKrSPAmk/OPkq9CT7EeV0FaX+tG+WRYhQ3d53gR5w=="
    content_md5          = "7e0b709263d36e3a080cf5aee1944a22"
    content_sha1         = "c8871ea4eef30f5a5100f9e72c565dfd2bcce951"
    content_sha256       = "fb4a19ff8766101197b1bd84918d3b8f4bedb2395a58323c78dd576384a63e7d"
    content_sha512       = "842918cba465671a064755fc4bec7716918fb04b9d273ac7949f9c5e4f42a4f03628c2ab48f02693f38f92af424fb11e57415a5feb46f96458850ddde77811e7"
    directory_permission = "0777"
    file_permission      = "0777"
    filename             = "note.txt"
    id                   = "c8871ea4eef30f5a5100f9e72c565dfd2bcce951"
}
A Terminal window running tofu show, which prints the local_file.note resource with its content Open every day, its checksums, its permissions and the filename note.txt.
tofu show prints what OpenTofu recorded about each resource.

Each resource appears under its address, here # local_file.note:, with every value OpenTofu recorded, including the ones the provider worked out, such as the checksums. tofu state list gives only the addresses.

Step 3: Show a Saved Plan

Change the content to "Open every day, 9 to 5" and save a plan to a file:

Bash
tofu plan -out=change.tfplan

Then show the saved plan:

Bash
tofu show -plan=change.tfplan
Plain text
OpenTofu used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
-/+ destroy and then create replacement

OpenTofu will perform the following actions:

  # local_file.note must be replaced
-/+ resource "local_file" "note" {
      ~ content              = "Open every day" -> "Open every day, 9 to 5" # forces replacement
      ~ content_base64sha256 = "+0oZ/4dmEBGXsb2EkY07j0vtsjlaWDI8eN1XY4SmPn0=" -> (known after apply)
      ~ content_base64sha512 = "hCkYy6RlZxoGR1X8S+x3FpGPsEudJzrHlJ+cXk9CpPA2KMKrSPAmk/OPkq9CT7EeV0FaX+tG+WRYhQ3d53gR5w==" -> (known after apply)
      ~ content_md5          = "7e0b709263d36e3a080cf5aee1944a22" -> (known after apply)
      ~ content_sha1         = "c8871ea4eef30f5a5100f9e72c565dfd2bcce951" -> (known after apply)
      ~ content_sha256       = "fb4a19ff8766101197b1bd84918d3b8f4bedb2395a58323c78dd576384a63e7d" -> (known after apply)
      ~ content_sha512       = "842918cba465671a064755fc4bec7716918fb04b9d273ac7949f9c5e4f42a4f03628c2ab48f02693f38f92af424fb11e57415a5feb46f96458850ddde77811e7" -> (known after apply)
      ~ id                   = "c8871ea4eef30f5a5100f9e72c565dfd2bcce951" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

It’s the plan tofu apply change.tfplan would carry out. Showing it is a good way to check a saved plan before you apply it, or to let someone else review it.

Warning: With -json, tofu show prints sensitive values, such as passwords, in plain text. Don’t share its JSON output.

Clean Up

Run tofu destroy and type yes, then delete the folder, including change.tfplan.

Bash
tofu destroy

FAQ

Does tofu show change anything?

No. It only reads the state or the plan file.

Why does tofu show say the state file is empty?

It prints The state file is empty. No resources are represented. when nothing has been applied in that folder yet. Run it after tofu apply, in the same folder.

Conclusion

tofu show prints the state, and tofu show -plan=<file> prints a saved plan. Both are easy to read, so you can check what OpenTofu manages and what it’s about to do.

Additional Resources

OpenTofu® is a registered trademark of LF Projects, LLC. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by the OpenTofu project.

0 comments