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.
Distinguish redaction from non-persistence, explain protection of state, plans and logs, and recognize conditions for ephemeral values and write-only arguments.
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
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.
| Surface | Interpretation |
|---|---|
| Common display | Redaction does not establish that a value is absent. |
| State | Attributes and outputs can contain secrets; protect access. |
| Saved plan | A value hidden on screen can persist in the saved artifact; do not treat it as public. |
| Explicit output and logs | Named output and -json/-raw can reveal values; avoid copying them into CI logs. |
Trace the value and access to its destinations
- Value source → Terraform evaluationSupply
- Terraform evaluation → State and saved planPersistence
- 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
variable "session_token" {
type = string
sensitive = true
ephemeral = true
}| Check | Condition |
|---|---|
| Terraform version | Ephemeral variables and child module outputs require 1.10 or later. |
| Valid consumers | References are restricted to ephemeral contexts, such as provider configuration; arbitrary persisted attributes are not allowed. |
| Output boundary | Ephemeral child module outputs are supported; root module outputs cannot be ephemeral. |
| Display handling | Consider 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
| Item | What to verify |
|---|---|
| Terraform | Write-only arguments require 1.11 or later. |
| Resource and provider | The particular argument must be declared write-only by that resource schema. |
| Value flow | Check for copies into ordinary attributes or outputs. |
| Update behavior | Read 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
- Limit which processes and people need values; avoid unnecessary outputs or screen copies.
- Review state, saved plans and CI artifacts: storage, readers, encryption, retention and deletion.
- Consider ephemeral/write-only where versions and providers support them, then inspect actual value flows.
- 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.
Check, then explain in your own words
- Use the counterexample to distinguish redaction from persistence.
- Map storage surfaces, version conditions and valid consumers.
- 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.
- Terraform input variablesChecked:
Scope and conditionsSensitive variable persistence and ephemeral consumer restrictions; no actual secrets used.
Used in this lessonRedaction and persisted contents are different Ephemeral values address a different concern Check your understanding
- Terraform output commandChecked:
Scope and conditionsRoot output display versus named/-json/-raw retrieval; explicit output can reveal sensitive values.
Used in this lessonRedaction and persisted contents are different Trace the value and access to its destinations Ephemeral values address a different concern Review stored artifacts and their distribution Check your understanding
Scope and conditionsRedaction differs from persistence; inspect state/plan handling and separate ephemeral and write-only conditions.
Used in this lessonRedaction and persisted contents are different Trace the value and access to its destinations Ephemeral values address a different concern Review stored artifacts and their distribution Check your understanding
- Terraform plan commandChecked:
Scope and conditionsNormal planning reads targets and proposes changes; distinguish a proposal from an applied outcome.
Used in this lessonRedaction and persisted contents are different Trace the value and access to its destinations Review stored artifacts and their distribution Check your understanding
- Terraform state lockingChecked:
Scope and conditionsLocking depends on backend support; remote storage alone does not guarantee it, and force-unlock is not a routine fix.
Used in this lessonTrace the value and access to its destinations
Scope and conditionsTerraform 1.11+ and resource support, non-persistence and resource-specific update behavior; no provider example executed.
Used in this lessonWrite-only arguments belong to supported resource schemas Review stored artifacts and their distribution Check your understanding
- Git gitignore documentationChecked:
Scope and conditionsIgnore rules do not remove already tracked files; separately review existing contents and history.
Used in this lessonReview stored artifacts and their distribution Check your understanding