Sensitive value redaction in Terraform JSON output: unresolved behavior
0 reputation · 18 Aug 2020, 04:32 UTC
0 reputation · 18 Aug 2020, 04:32 UTC
The objective is to prevent secrets from leaking when consuming a Terraform plan via terraform show -json, while preserving the ability for automated tools to parse the full plan.
Terraform’s sensitive = true attribute only suppresses values in the default text output. The JSON representation, which is essential for CI/CD pipelines and third‑party tooling, still contains plaintext values. Existing automation expects the JSON to be fully populated, so any change to redact values would break downstream consumers.
It is unclear whether Terraform should offer an opt‑in mechanism to redact sensitive fields in JSON, or whether the design decision to leave them exposed should remain. The trade‑off between security and usability is still debated within the community.
terraform show -json?35275 reputation · 18 Aug 2020, 09:48 UTC
As of current Terraform releases, terraform show -json does not redact sensitive values, and there is no built-in flag to make it do so. The sensitive = true marking only suppresses values in the human-readable text output. In the JSON plan, each attribute carries a sensitive boolean in its metadata, but the corresponding value field remains plaintext. This is a deliberate design decision: the JSON output is a machine-readable contract, and silently altering values would break the many tools that parse it. Whether HashiCorp should add an opt-in redaction flag is an open community question, but you should not wait for it — the practical answer today is a post-processing step you control.
Confirmed: the JSON schema exposes sensitivity as metadata (sensitive_values trees and per-attribute flags) rather than by masking values. Likely rationale (not officially stated as a single decision): redaction is lossy and irreversible, so Terraform leaves the policy choice to the consumer. Treat any claim about an upcoming native --redact flag as unverified until you check the changelog for your version.
Because the JSON already tells you which nodes are sensitive, you can walk the tree and replace only those values with a placeholder, preserving structure for downstream parsers:
terraform show -json planfile \
| jq 'walk(if type=="object" and .sensitive==true then .value="<REDACTED>" else . end)' \
> plan.redacted.json
For plans, also check the top-level sensitive_values tree, which mirrors the shape of planned_values with booleans marking sensitive leaves — a more thorough redactor uses it as a mask against the corresponding value tree rather than relying solely on inline flags.
<REDACTED> so downstream schema validation still sees a string where it expects one; placeholders of the wrong type are the most common cause of consumer breakage.sensitive flags — tools use them for their own policy decisions.terraform show -json and confirm the plaintext value appears alongside sensitive: true.Values not marked sensitive — including computed attributes a provider failed to flag — remain exposed, so audit provider schemas for your resources. Also note the state file itself stores secrets in plaintext regardless; redacting plan output does not change that. Exact JSON schema details vary by Terraform version, so validate the redactor against the version you run.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.