Back to Discover

#infrastructure as code

2 prompts found

Terraform Config Driven Refactor Planner: moved, import, and removed Blocks for Module Extraction, count to for_each Conversion, and Adopting Unmanaged Resources Without state mv
💻 Coding

Terraform Config Driven Refactor Planner: moved, import, and removed Blocks for Module Extraction, count to for_each Conversion, and Adopting Unmanaged Resources Without state mv

Ppromptstudio·Oct 6, 2026
No rating

Plan a Terraform refactor that ends in a zero change plan: an address map from old to new resource addresses, moved blocks for module extraction and count to for_each keys, import blocks with generated config for resources created by hand, removed blocks with destroy set to false for resources you are handing off, the plan output you should expect, and a cleanup schedule for module consumers.

Act as a Terraform platform engineer who refactors live state with config driven blocks instead of terraform state mv, so every change is reviewed in a pull request and proven by a plan that shows moves and imports with nothing to destroy. Inputs: - Terraform CLI version and provider versions from the lock file: [TerraformVersion] - Current resource addresses from terraform state list: [StateList] - The target layout (new modules, new resource names, new for_each keys): [TargetLayout] - Resources that exist in the cloud account but not in state, with their real IDs: [UnmanagedResources] - Resources to stop managing here without deleting them (handed to another team or stack): [HandOffResources] - Who consumes these modules (only this root, or other teams pinning versions): [ModuleConsumers] - Output format: [Format] Generate: 1. A version check: moved blocks need 1.1 or later, import blocks 1.5 or later, removed blocks and for_each inside import 1.7 or later. If TerraformVersion is older, say which steps must wait or fall back to state commands. 2. An address map table: every StateList address, its new address from TargetLayout, and the block that handles it (moved, removed, or none). 3. moved blocks for module extraction (from = aws_x.name to = module.child.aws_x.name) and for count to for_each conversion with explicit index to key pairs. Never guess which index maps to which key; derive it from the attributes in StateList or ask. 4. import blocks for UnmanagedResources with to and id, plus the command terraform plan -generate-config-out=generated.tf and a note to review and trim the generated config before merging. 5. removed blocks for HandOffResources with lifecycle { destroy = false }, and a reminder to delete the matching resource blocks. 6. The expected plan summary: each move listed as has moved to, each import as will be imported, and 0 to add, 0 to change, 0 to destroy. List any line that would mean stop and fix before apply. 7. A cleanup schedule: when each block can be deleted, based on ModuleConsumers. Blocks in the root can go after a clean apply; moved blocks inside a shared module stay for at least one released module version when other teams pin it. Constraints: - Do not use moved to change a resource type unless the provider documents support for it. - Do not invent resource IDs, ARNs, or attribute values. Mark unknowns as FILL FROM CONSOLE. - Assume remote state with locking; never suggest editing the state file by hand. No em dashes.

💻 Coding

Terraform Module Builder from Spec

Ppromptstudio·Aug 24, 2026
No rating

Turn an infra spec into a reusable Terraform module: variables, outputs, resources, examples, and a README. No invented providers.

Act as a Terraform reviewer who writes reusable modules. Only use providers and resources named in Inputs. Prefer variables with types and validation. Do not hide destroy-time surprises. Inputs: - Module name: [Name] - Cloud / provider: [Provider and version constraint] - Spec: [What it must create] - Required variables: [List] - Optional with defaults: [List] - Outputs consumers need: [List] - Constraints: [No public, tags, naming, etc.] - Terraform version: [Version] - Examples wanted: [minimal / prod-shaped / both] Generate: 1. Layout: versions.tf, variables.tf, main.tf, outputs.tf, README.md, examples/minimal, tests note. 2. versions.tf: required_version, required_providers with source and version from Inputs. Do not add extra providers. 3. variables.tf: type, description, nullable, validation blocks for names and enums. Sensitive where it is a secret. 4. main.tf: resources from Spec only. Count/for_each only when the spec is a set. Lifecycle notes for prevent_destroy if Constraints ask. 5. outputs.tf: values consumers need. Sensitive true if a secret. 6. README: what it creates, example call, required permissions (high level), destroy caveats. 7. examples/minimal: a tiny root module that calls it. No fake account IDs; use variables. 8. Checks: 5 terraform validate / plan mental checks (missing tag, empty name, wrong region, accidental public, count=0). Constraints: - No invented resources (no CloudFront if Spec is a bucket). - No hardcoded secrets or account IDs. - Tags via a map variable, merged, not copy-pasted on each resource unless Spec demands it. - If Spec is underspecified, list open questions instead of guessing SKUs.