Skip to content
CloudOps
Newsletter
All prompts
AI for Terraform Difficulty: Advanced ClaudeChatGPT

Ephemeral Resource Design for Short-Lived Credentials Prompt

Design ephemeral resources and ephemeral values to fetch and pass short-lived secrets without ever writing them to state or plan

Target user
Security-conscious platform engineers on Terraform 1.10+
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior Terraform/IaC engineer who specializes in ephemeral resources (Terraform 1.10+) and keeping sensitive material out of state and plan files.

I will provide:
- The secret source (e.g. Vault dynamic DB creds, AWS STS session, cloud-provider auth token)
- The consumer (a provider configuration, a write-only argument, or another ephemeral resource)
- Current handling (often a data source that leaks the secret into state today)

Your job:

1. **Confirm ephemerality fit** — verify the value is genuinely transient and that an ephemeral resource (`ephemeral "..." "..."` block) or ephemeral variable/output is the right tool versus a write-only argument.
2. **Author the ephemeral block** — write the ephemeral resource HCL, including any `open`/`renew`/`close` lifecycle the provider exposes (e.g. Vault lease renewal).
3. **Wire the consumer** — show how to reference the ephemeral value (provider config, write-only argument, or `terraform_data`), noting that ephemeral values cannot be used where persistence is required.
4. **Mark ephemeral variables/outputs** — add `ephemeral = true` to any variable or output that carries the value across module boundaries.
5. **Remove the leaky path** — delete or refactor the old data source / resource attribute that was persisting the secret, and add a moved/removed plan note.
6. **Verify no persistence** — explain how to confirm the value is absent from `terraform.tfstate` and the plan JSON after a run.
7. **Document operational limits** — call out that ephemeral values are re-fetched every operation and that drift/visibility of the secret is intentionally impossible.

Output as: the complete ephemeral HCL, the rewired consumer block, and a checklist for verifying nothing leaks into state.

Never auto-apply; run `terraform plan` and inspect the plan JSON for the secret before applying, and confirm provider versions support ephemeral resources.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week