Ephemeral Values and Write-Only Arguments
Terraform 1.10 and 1.11 added ways to use secrets without ever storing them. This lesson covers ephemeral variables, outputs and resources, write-only arguments and how they work together.
Learning outcomes
After completing this lesson, you will be able to:
- Explain ephemeral variables, outputs and resources.
- Describe how write-only arguments and their version arguments work.
- Identify the contexts where ephemeral values are allowed.
Ephemeral input variables and outputs
An input variable declared with ephemeral = true accepts a value for the current run only; Terraform does not record it in plan or state files. An output in a child module can also be ephemeral, which lets a module pass an ephemeral value to its caller. Root module outputs cannot be ephemeral.
variable "db_admin_password" {
type = string
sensitive = true
ephemeral = true
}Ephemeral values may be used only in ephemeral contexts: other ephemeral variables and outputs, local values (which then become ephemeral), ephemeral resources, provider and provisioner blocks, and write-only arguments. Using one in an ordinary resource argument is an error, because that argument would be stored in state.
Can an ephemeral value go here?
Ephemeral resources
An ephemeral resource is declared with an ephemeral block and referenced with the ephemeral. prefix. Terraform opens it during each plan and apply to obtain a temporary value, may renew it during a long run, and closes it at the end; nothing is stored. Providers offer ephemeral resources for generated passwords, secrets from secret stores and short-lived tokens.
ephemeral "random_password" "db" {
length = 24
special = true
}
ephemeral "aws_secretsmanager_secret_version" "api_key" {
secret_id = "prod/api-key"
}
provider "example" {
token = ephemeral.aws_secretsmanager_secret_version.api_key.secret_string
}- Ephemeral resource
- A block that obtains a temporary value during a run and is never stored in plan or state.
- Ephemeral context
- A place where ephemeral values are allowed: ephemeral variables and outputs, locals, ephemeral resources, provider and provisioner blocks, write-only arguments.
- Write-only argument
- A managed resource argument that is sent to the provider but never persisted.
Ephemeral resources
Write-only arguments
Managed resources still need secrets, such as a database's master password. A write-only argument, available from Terraform 1.11, accepts a value, usually an ephemeral one, passes it to the provider during apply and never stores it in plan or state. By convention their names end in _wo, such as password_wo on aws_db_instance or value_wo on aws_ssm_parameter.
resource "aws_db_instance" "main" {
identifier = "app-db"
engine = "postgres"
instance_class = "db.t4g.micro"
allocated_storage = 20
username = "app_admin"
password_wo = ephemeral.random_password.db.result
password_wo_version = 1
skip_final_snapshot = true
}Because Terraform keeps no copy of the value, it cannot tell when it changes. Each write-only argument therefore has a companion version argument, here password_wo_version, which is stored. Terraform sends the write-only value on create and again whenever the version changes, so rotating the password means increasing the version to 2 and applying.
The following diagram shows an ephemeral password reaching two write-only arguments.

Write-only arguments
A secret that never touches state
A security policy forbids database passwords in Terraform state. A team must create a PostgreSQL database with Terraform and make the password available to applications through AWS Secrets Manager.
The decisive requirement is that the password is never persisted by Terraform.
The team generates the password with ephemeral "random_password", passes it to the database's password_wo argument and to the secret_string_wo write-only argument of an aws_secretsmanager_secret_version, each with a version argument set to 1. Neither the plan nor the state contains the password. To rotate it, they increase both version arguments: a new ephemeral value is generated and written to both places in one apply.
How do you make Terraform send a new value to a write-only argument?
Show answer
Change its companion version argument, such as password_wo_version, because Terraform keeps no copy of the value to compare.
Exam Tips
Remember for the exam
- ephemeral = true on variables and child module outputs keeps values out of state.
- Ephemeral resources use ephemeral blocks and the ephemeral. prefix.
- Write-only (_wo) arguments are never stored; bump _wo_version to send a new value.
- Ephemeral values only work in ephemeral contexts.