Inspect state without exposing secrets
Choose the smallest useful inspection
State can include credentials, private endpoints, identifiers and business data, including values not marked sensitive. Start by confirming the authorized directory, backend and workspace; even read operations may contact a remote backend. For this lesson use only the disposable local inspection fixture. terraform state list inventories addresses; terraform state show ADDRESS inspects one instance; terraform show displays the current snapshot (or a supplied state or plan); terraform output reads root outputs. These commands do not independently prove live service health.
Inspect a synthetic output safely
This configuration has a public status and a deliberately fake private demonstration string. No credentials should be substituted.
resource "terraform_data" "report" { input = "catalog-ready"}
output "public_status" { value = terraform_data.report.output}
output "private_demo" { value = "SYNTHETIC-DEMO-NOT-A-CREDENTIAL" sensitive = true}After applying the local fixture, inspect only the public status:
terraform state listterraform output public_statusExpected address: terraform_data.report. Expected label: catalog-ready. Running terraform output without a name normally hides the value of the marked output in the listing. The state still stores it. A named sensitive output, raw or JSON output can disclose it. Do not run these disclosure commands on real environments just to see what happens.
Understand machine-readable output
For automation, terraform show -json provides a documented JSON representation of state or a saved plan. It can expose sensitive values in plaintext, including values in nested structures. terraform output -json and -raw also expose sensitive outputs. Never pipe full state into shared logs or paste it into a support chat. For the inherited provisional 1.14.8 teaching pin, avoid terraform state show -json: current documentation identifies that option as available from 1.16. Use a reviewed allowlist of public fields, not a denylist that assumes every secret has an obvious name.
Share only a deliberately reduced summary
Example of a hand-created summary for a fictional support request, not the output format of any Terraform command:
{ "instance_count": 1, "public_status": "catalog-ready", "private_values_included": false}An actual reviewer must check whether even names, counts or public-looking values are safe to share. Do not rely on a boolean flag to perform redaction. Avoid copying raw state, plan files, backup files or hidden working-directory metadata into the report. Protect authorized stored artifacts with access control, encryption and retention policies suitable for the backend. A local backup needs the same care as the primary state.
Respond to unexpected exposure
If a real secret has already been shared, restrict access, notify the responsible security owner, rotate or revoke the affected credential as appropriate and review exposure in logs, backups and repository history. Removing one copy may not remove all copies. Prevent future disclosure using least privilege and version/provider-supported ephemeral or write-only features where suitable; these have separate constraints. Do not assume a sensitive flag encrypts data or prevents persistence. Do not run a state mutation as a response to an exposure without a reviewed recovery plan.
Practice choosing the right command
Use the synthetic summary cases in the worksheet. If asked only how many instances are managed, start with an authorized address inventory. If asked for a particular resource attribute, scope the inspection to that instance, then manually prepare the minimum safe report. If asked whether the application is currently healthy, explain that authorized runtime observations are required. No command was executed by the author; all outputs are predictions.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inspect state without exposing secrets — knowledge check
Review state ownership and safe inspection.
Which command lists managed addresses?
Which command inspects one exact instance in state?
Does sensitive = true guarantee that an output is absent from state?
Which is a risk of terraform show -json?
Which evidence best supports a claim that a real service is currently healthy?