Ephemeral values and write-only arguments
Choose the correct persistence mechanism
Terraform 1.10 introduced ephemeral inputs, child outputs and ephemeral resource blocks. Terraform 1.11 added support for write-only managed-resource arguments. The provider must implement each relevant resource type or argument. These features target Terraform artifact persistence, not all information flows. The older sensitive flag controls presentation and can be combined with ephemeral inputs to reduce display exposure. Do not treat either feature as a universal guarantee of zero secret retention.
Pass a temporary value between modules
The root configuration below uses a synthetic temporary marker and a separate ordinary local record. The child module accepts the marker and exposes it only as an ephemeral child output. A root output cannot be ephemeral. This local fixture deliberately has no secret-consuming provider and no real authentication. The unused relay illustrates the interface, not proof that any provider receives the value.
terraform { required_version = "= 1.14.8"}variable "temporary_marker" { type = string sensitive = true ephemeral = true}module "relay" { source = "./relay" marker = var.temporary_marker}resource "terraform_data" "public_record" { input = "inventory-v1"}output "public_record" { value = terraform_data.public_record.output}variable "marker" { type = string sensitive = true ephemeral = true}output "temporary_marker" { value = var.marker sensitive = true ephemeral = true}The second snippet is the complete relay/main.tf. A local derived expression may carry an ephemeral value, but it does not turn a persistent destination into a permitted destination. A saved-plan apply can require ephemeral inputs to be supplied again because the plan does not retain them. Follow version-specific CLI instructions; never store the secret in a plan or copy a real value into a command line.
Recognize invalid destinations
A normal resource input may become part of the persisted state. The following is an intentionally invalid addition to the root example. Terraform should reject this use of the ephemeral variable rather than silently save it.
# Intentionally invalid: an ephemeral value cannot enter a persistent input.resource "terraform_data" "bad" { input = var.temporary_marker}Do not work around the error by coercing or exposing the value. Use a destination that supports ephemeral data, such as a compatible provider configuration, ephemeral child input or provider-defined write-only argument. A provisioner can also be a supported ephemeral context, but its external command and logs are separate risks; prefer native integration. A root output or ordinary resource input is not a valid general-purpose destination.
Understand provider-defined temporary resources
An ephemeral resource may obtain or generate a value during an operation; it is not a regular state-managed resource. Providers define the available ephemeral types, lifecycle and renewal or close behavior. Here is a deliberately fictional example, not an actual provider or valid deployable configuration.
# Fictional provider schema; NOT runnable.ephemeral "example_session" "auth" { audience = "inventory"}resource "example_service" "inventory" { name = "inventory" credential_wo = ephemeral.example_session.auth.token credential_rev = 2}The conceptual service accepts the credential during an operation and stores its revision separately. A real provider can expose a differently named write-only argument and a version trigger. Check its exact schema and documentation; a suffix alone proves nothing. Since Terraform does not retain the old write-only value, it cannot compare old and new secret bytes for an ordinary diff. A revision counter can support deliberate rotation when the provider implements that contract. It does not itself rotate credentials or prove they work. A non-ephemeral input supplied elsewhere can still be persisted even when one destination is write-only.
Design a safe artifact test
In a separately approved local fixture, use two distinct non-secret marker strings: one conventional sensitive input and one ephemeral input. Use a fresh copy of each configuration, with local state and no external plugins. Review the plan before any apply. Capture only synthetic artifacts in a restricted disposable folder. For each artifact inspect the decoded representation privately and record a boolean indicating whether each marker was present; do not print the value. Expected results: the normal marker is retained in the conventional fixture, while the ephemeral marker is absent from the ephemeral fixture plan and state. A binary substring search alone is insufficient for a saved plan; use an authorized decoded inspection. A real provider test also needs proof that the provider actually consumed the value and did not store it in another attribute. Our local relay cannot establish that. Check logs and backups independently, and clean up only lab-owned files after the local resource cleanup. No real artifacts are included.
Practice
Classify the synthetic destination cases and propose a test for a provider-supported write-only argument. Include exact versions, a positive control, negative control, provider-side success assertion and cleanup. Next: provider authentication and least privilege.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Ephemeral values and write-only arguments — knowledge check
Review sensitive and ephemeral value handling.
Which Terraform version introduced ephemeral input variables?
Where may an ephemeral value be passed?
What establishes that a managed argument is write-only?
Why might a provider supply a revision argument?
What does an absent synthetic marker in decoded plan and state establish?