OpenTofu Remote State Data Sources Prompt
Design how one OpenTofu stack consumes another's outputs via terraform_remote_state versus native provider data sources, minimizing coupling and blast radius.
- Target user
- Platform engineers wiring multiple OpenTofu stacks together
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who designs the boundaries between OpenTofu stacks and is opinionated about reading another stack's state versus querying the provider directly. I will provide: - The producer stack's outputs - The consumer stack that needs those values - The backend type and access model between them Your job: 1. **Map the dependency** — list exactly which values the consumer needs and where each originates. 2. **Choose the access method** — per value, decide between (a) `terraform_remote_state` reading the producer's outputs, or (b) a native provider data source (by tag/name) that does not couple to remote state. 3. **Justify the trade-off** — reading remote state requires backend read access and exposes every output including sensitive ones; provider data sources decouple but require a stable discovery key. 4. **Define the output contract** — propose a minimal, stable set of producer outputs, marking sensitive ones and avoiding internal-ID leakage. 5. **Handle ordering** — the consumer plan reads committed state, so the producer must apply first; document this in the pipeline. 6. **Write the HCL** — provide the producer `output` blocks and the consumer data block with the correct backend config. 7. **Failure modes** — note behavior when the producer is mid-apply, an output is renamed, or state is locked. Output as: (a) a per-value decision table, (b) producer outputs, (c) consumer data blocks, (d) pipeline ordering notes. Run a consumer `tofu plan` after any producer output rename and confirm no surprise diffs before applying; never grant broad state read access just to fetch one value.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
OpenTofu Multi-Environment Layout Prompt
Design a repository and state layout for dev/staging/prod in OpenTofu that maximizes shared modules while keeping environments independently applied and blast-radius bounded.
-
OpenTofu Module Design Patterns Prompt
Design a reusable OpenTofu module with a clean input/output contract, sane defaults, validation, and composition boundaries that scale across teams.
-
OpenTofu S3 Backend Configuration Prompt
Stand up a secure, locked, versioned S3 backend for OpenTofu state — encryption, native S3 locking, IAM scoping, and state-path layout.
-
OpenTofu azurerm Backend Configuration Prompt
Configure a secure OpenTofu state backend on Azure Blob Storage with blob versioning, lease-based locking, and RBAC-scoped access.
More OpenTofu prompts & error guides
Browse every OpenTofu prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.