INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

Topic lessonTopic: Terraform: change workflow and sensitive data

Terraform sensitive data: protecting state and saved plans

Marking a value sensitive redacts common displays; it does not guarantee that the value is never stored. Distinguish state, saved plans, explicit value output and CI artifacts. Trace where a value comes from, where it persists and who can read it.

What you will learn

Distinguish redaction from non-persistence, explain protection of state, plans and logs, and recognize conditions for ephemeral values and write-only arguments.

Prerequisite

Understanding Terraform plan, apply and state helps. Values are fictional teaching examples; this page has no input for real secrets, state or plan files.

Redaction and persisted contents are different

HCL counterexample: redaction does not solve persistenceScroll horizontally to read long lines. Use arrow keys in the code area.
variable "report_token" {
  type      = string
  sensitive = true
}

output "token_for_reading_example" {
  value     = var.report_token
  sensitive = true
}

This is not a recommendation to expose secrets as outputs. It demonstrates that marking both an input variable and a root output sensitive still leaves separate display and persistence concerns. Avoid unnecessary outputs and identify where a value is actually needed.

Trace one fictional value across different surfaces
SurfaceInterpretation
Common displayRedaction does not establish that a value is absent.
StateAttributes and outputs can contain secrets; protect access.
Saved planA value hidden on screen can persist in the saved artifact; do not treat it as public.
Explicit output and logsNamed output and -json/-raw can reveal values; avoid copying them into CI logs.

Trace the value and access to its destinations

Secret surfaces: redaction does not protect stored artifacts
Secret surfaces: redaction does not protect stored artifacts1: Value source — Supply — Terraform evaluation. 2: Terraform evaluation — Persistence — State and saved plan. 3: Terraform evaluation — Display — Outputs and CI logs123Value sourceTerraformevaluationState and savedplanOutputs and CI logsSecret surfaces: redaction does not protect stored artifacts1: Value source — Supply — Terraform evaluation. 2: Terraform evaluation — Persistence — State and saved plan. 3: Terraform evaluation — Display — Outputs and CI logs123Value sourceTerraformevaluationState and savedplanOutputs and CIlogs
  1. Value source → Terraform evaluationSupply
  2. Terraform evaluation → State and saved planPersistence
  3. Terraform evaluation → Outputs and CI logsDisplay
Value source
Pass only where needed
Terraform evaluation
Inspect inputs and consumers
State and saved plan
Storage, access, retention
Outputs and CI logs
Redaction exceptions, copies

Remote storage alone does not establish adequate protection. Review encryption, access, concurrency control and retention separately. Backend locking addresses concurrent operations; it is not a substitute for confidentiality.

Ephemeral values address a different concern

HCL reading example without an embedded valueScroll horizontally to read long lines. Use arrow keys in the code area.
variable "session_token" {
  type      = string
  sensitive = true
  ephemeral = true
}
Check versions and valid consumers
CheckCondition
Terraform versionEphemeral variables and child module outputs require 1.10 or later.
Valid consumersReferences are restricted to ephemeral contexts, such as provider configuration; arbitrary persisted attributes are not allowed.
Output boundaryEphemeral child module outputs are supported; root module outputs cannot be ephemeral.
Display handlingConsider sensitive redaction separately from ephemeral persistence behavior.

Adding ephemeral to every variable is not a complete solution. Check whether consumers support the value and whether each reference is allowed. Any separate output or logging path also needs protection.

Write-only arguments belong to supported resource schemas

Both Terraform and provider support matter
ItemWhat to verify
TerraformWrite-only arguments require 1.11 or later.
Resource and providerThe particular argument must be declared write-only by that resource schema.
Value flowCheck for copies into ordinary attributes or outputs.
Update behaviorRead resource-specific behavior, including any required version argument.

Renaming an ordinary argument with an _wo suffix does not make it write-only. Consult the supported resource schema before designing the flow. This lesson neither installs a provider nor creates resources.

Review stored artifacts and their distribution

  1. Limit which processes and people need values; avoid unnecessary outputs or screen copies.
  2. Review state, saved plans and CI artifacts: storage, readers, encryption, retention and deletion.
  3. Consider ephemeral/write-only where versions and providers support them, then inspect actual value flows.
  4. Inspect tracked Git files, history and CI copies; gitignore does not erase existing history.

Check your understanding

Choose an option to see the result and explanation.

If the usual display is redacted, can state be publicly readable?
Read the answer and reason

Answer: No; review persisted contents and readers · State can contain secrets despite redaction, so access protection is necessary.

A review display hides secrets. Can the saved plan be a public CI artifact?
Read the answer and reason

Answer: No; protect it as a potentially sensitive artifact · Screen redaction and saved plan contents are separate boundaries.

A root output is sensitive. Are named output and -json/-raw guaranteed to hide it?
Read the answer and reason

Answer: No; explicit value retrieval can reveal it · Common display redaction does not protect explicit output or its logs.

Can an ephemeral root module output expose an ephemeral value without persistence?
Read the answer and reason

Answer: No; check valid consumers and module boundaries · Support has module and context limits; root outputs are not an unrestricted destination.

On Terraform 1.11+, can any password argument become write-only?
Read the answer and reason

Answer: No; inspect the supported resource argument · Both Terraform version and provider-defined argument support are required.

State was tracked in Git, then added to gitignore. Are past values gone?
Read the answer and reason

Answer: No; tracked contents and history require separate review · Ignore rules do not erase already tracked content or past history.

Check, then explain in your own words

  1. Use the counterexample to distinguish redaction from persistence.
  2. Map storage surfaces, version conditions and valid consumers.
  3. Use the questions and review to explain artifacts and readers that need protection.
Check your understanding: Someone says “it is safe because sensitive is set.” What else should you review?

Review state, saved plans, explicit outputs, CI logs/artifacts and Git copies, plus access and retention. For non-persistence features, verify versions, consumers and provider support.

Display, persistence, copies and readers are distinct protection concerns.

Sources and conditions checked

The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.