Pulumi Transformations & Aliases Refactor Prompt
Refactor Pulumi resource names, parents, and structure at scale using aliases and stack transformations so URNs change on paper but no live resource is destroyed or replaced.
- Target user
- Platform engineers restructuring long-lived Pulumi programs
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior platform engineer refactoring a large, long-lived Pulumi program without destroying a single live resource. Renaming a resource, moving it under a new parent, or splitting a component changes its URN — and Pulumi treats a changed URN as a delete-and-create unless you tell it otherwise with `aliases`.
I will provide:
- The Pulumi language (TypeScript, Python, Go, or .NET) and the current program structure
- The refactor goal (rename resources, introduce/collapse a ComponentResource, re-parent, or split one project into many)
- The output of `pulumi preview --diff` before the refactor (or a description of which resources are stateful/protected)
Your job:
1. **Map every URN change** the refactor causes. For each resource whose logical name, parent, or type changes, produce the old URN and the new URN, and mark whether Pulumi would otherwise replace it.
2. **Author the aliases.** Give the exact `aliases: [{ name, parent, type, project, stack }]` (or `pulumi.URN` form) for each moved resource so the preview shows an in-place rename with zero replacements. Cover the subtle cases: a ComponentResource rename cascades URNs to all its children, so children need parent-based aliases too.
3. **Use transformations for cross-cutting edits** — when the refactor also applies a policy uniformly (tags, `protect`, `retainOnDelete`, provider overrides), show a `registerStackTransformation` (or resource `transformations`) that mutates props at registration time instead of editing every resource by hand. Explain ordering: transformations run before the engine diffs.
4. **Prove safety.** Provide the `pulumi preview --diff` you expect after the change — every stateful resource must show `~`/no-op, never `+/-` (replace) or `-` (delete). Give the targeted command to verify one blast-radius group at a time.
5. **Sequence and clean up.** Order the rollout so aliases can be removed in a later commit once state has settled, and note that aliases are only consulted while the old URN still exists in state.
Output as: (a) an old-URN → new-URN mapping table with replace-risk flags, (b) the concrete alias code per resource, (c) any transformation code, (d) the before/after preview you expect and the verification commands. Assume production traffic depends on these resources.
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
-
Pulumi Secrets Provider Migration & Key Rotation Prompt
Migrate a Pulumi stack's secrets provider (passphrase to KMS/Vault or between clouds) and rotate the encryption key so all encrypted config and state secrets are re-wrapped without leaking plaintext.
-
Pulumi Refresh & Drift Remediation Prompt
Detect and safely reconcile out-of-band drift between a Pulumi stack's state and live cloud reality — deciding per resource whether to adopt, revert, or ignore the change without triggering an unwanted replace.
-
Pulumi Brownfield Import & Bulk Adoption Prompt
Adopt an existing, hand-built cloud estate into Pulumi safely — bulk-importing live resources into state, generating matching program code, and reconciling drift without destroying or recreating anything in production.
-
Large IaC Codebase Refactor Plan Prompt
Plan a safe, incremental refactor of a large or tangled infrastructure-as-code codebase — decompose monoliths, untangle dependencies, and sequence the work so live infrastructure is never recreated mid-flight, across any IaC tool.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code 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.