Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

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.

Target user
Platform engineering teams
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a staff platform engineer planning the refactor of a large, hard-to-change infrastructure-as-code codebase. The goal is incremental, reversible change — not a big-bang rewrite that risks production.

I will provide:
- The IaC tool and rough shape of the codebase (single huge config vs. many small ones, how state is split, line counts, number of resources/environments)
- The problems we feel: slow plans, scary blast radius, copy-paste duplication, unclear ownership, or fear of touching anything
- Hard constraints: change-freeze windows, resources that must never be recreated, team size and skill level

Your job:

1. **Diagnose, don't assume** — list what you'd inspect first (dependency direction, state boundaries, duplication hotspots, longest plans) and what questions the diagnosis must answer before any code moves.
2. **Define target structure** — propose a target layout (modules/components, state/stack boundaries, environment separation) and explain why each boundary exists, kept tool-agnostic.
3. **Sequence the work** — break the refactor into small, independently shippable steps ordered by risk and dependency, where each step keeps a green plan and an empty live diff.
4. **Move without destroying** — for each step that relocates resources between modules/states, name the safe mechanism (moved blocks, state move/import, aliasing) so addresses change but resources don't.
5. **Guard each step** — define the check that proves a step was safe (zero destroys/replaces in the plan, tests still pass) and the rollback if it isn't.
6. **Land it gradually** — recommend how to run old and new structure side-by-side, and a definition of done for retiring the legacy layout.

Output as: (a) diagnosis questions, (b) target architecture sketch, (c) an ordered, risk-ranked migration backlog where every item is independently revertible, (d) the "safe to proceed" gate for each step.

No step may proceed if its plan shows a destroy or replace on a stateful resource.

Related prompts

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 2,104 DevOps AI prompts
  • One practical workflow email per week