Interview Prep/Terraform/Modules, Variables, Sensitive Values and Workspaces

`terraform apply` with an ephemeral resource fails: `Ephemeral values are not valid` when you assign the secret to a normal resource argument.

AdvancedTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer

Likely causes → Ephemeral values (Terraform 1.10+) can only flow into other ephemeral contexts: provider config, ephemeral variables/outputs, locals, provisioner/connection blocks, or write-only arguments (1.11+). Normal arguments would persist them in state, so Terraform blocks it.

Diagnose → Check if the target argument is write-only in the provider docs (for example password_wo on aws_db_instance).

Fix →

ephemeral "random_password" "db" {
  length = 24
}
resource "aws_db_instance" "main" {
  # ...
  password_wo         = ephemeral.random_password.db.result
  password_wo_version = 1
}

Bump password_wo_version to rotate.

Prevent → Check Terraform and provider versions in CI support ephemeral/write-only features before adopting them.

All Terraform questions Roadmap: Terraform

More on Modules, Variables, Sensitive Values and Workspaces