@c0x12c/ai-toolkit 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +16 -0
- package/.claude-plugin/plugin.json +12 -0
- package/README.md +439 -0
- package/VERSION +1 -0
- package/agents/design-critic.md +127 -0
- package/agents/idea-killer.md +72 -0
- package/agents/infrastructure-expert.md +49 -0
- package/agents/micronaut-backend-expert.md +45 -0
- package/agents/phase-reviewer.md +150 -0
- package/agents/research-planner.md +70 -0
- package/agents/solution-architect-cto.md +49 -0
- package/agents/sre-architect.md +49 -0
- package/agents/team-coordinator.md +111 -0
- package/bin/cli.js +780 -0
- package/claude-md/00-header.md +39 -0
- package/claude-md/01-core.md +105 -0
- package/claude-md/05-database.md +20 -0
- package/claude-md/11-backend-micronaut.md +19 -0
- package/claude-md/20-frontend-react.md +44 -0
- package/claude-md/25-ux-design.md +56 -0
- package/claude-md/30-infrastructure.md +24 -0
- package/claude-md/30-project-mgmt.md +119 -0
- package/claude-md/40-product.md +39 -0
- package/claude-md/50-ops.md +34 -0
- package/claude-md/60-research.md +27 -0
- package/claude-md/90-footer.md +21 -0
- package/commands/spartan/brainstorm.md +134 -0
- package/commands/spartan/brownfield.md +157 -0
- package/commands/spartan/build.md +435 -0
- package/commands/spartan/careful.md +94 -0
- package/commands/spartan/commit-message.md +112 -0
- package/commands/spartan/content.md +17 -0
- package/commands/spartan/context-save.md +161 -0
- package/commands/spartan/contribute.md +140 -0
- package/commands/spartan/daily.md +42 -0
- package/commands/spartan/debug.md +308 -0
- package/commands/spartan/deep-dive.md +55 -0
- package/commands/spartan/deploy.md +207 -0
- package/commands/spartan/e2e.md +264 -0
- package/commands/spartan/env-setup.md +166 -0
- package/commands/spartan/epic.md +199 -0
- package/commands/spartan/fe-review.md +181 -0
- package/commands/spartan/figma-to-code.md +260 -0
- package/commands/spartan/forensics.md +46 -0
- package/commands/spartan/freeze.md +84 -0
- package/commands/spartan/fundraise.md +53 -0
- package/commands/spartan/gate-review.md +229 -0
- package/commands/spartan/gsd-upgrade.md +376 -0
- package/commands/spartan/guard.md +42 -0
- package/commands/spartan/init-project.md +178 -0
- package/commands/spartan/init-rules.md +298 -0
- package/commands/spartan/interview.md +154 -0
- package/commands/spartan/kickoff.md +73 -0
- package/commands/spartan/kotlin-service.md +109 -0
- package/commands/spartan/lean-canvas.md +222 -0
- package/commands/spartan/lint-rules.md +122 -0
- package/commands/spartan/map-codebase.md +124 -0
- package/commands/spartan/migration.md +82 -0
- package/commands/spartan/next-app.md +317 -0
- package/commands/spartan/next-feature.md +212 -0
- package/commands/spartan/onboard.md +326 -0
- package/commands/spartan/outreach.md +16 -0
- package/commands/spartan/phase.md +142 -0
- package/commands/spartan/pitch.md +18 -0
- package/commands/spartan/plan.md +210 -0
- package/commands/spartan/pr-ready.md +202 -0
- package/commands/spartan/project.md +106 -0
- package/commands/spartan/qa.md +222 -0
- package/commands/spartan/research.md +254 -0
- package/commands/spartan/review.md +132 -0
- package/commands/spartan/scan-rules.md +173 -0
- package/commands/spartan/sessions.md +143 -0
- package/commands/spartan/spec.md +131 -0
- package/commands/spartan/startup.md +257 -0
- package/commands/spartan/team.md +570 -0
- package/commands/spartan/teardown.md +161 -0
- package/commands/spartan/testcontainer.md +97 -0
- package/commands/spartan/tf-cost.md +123 -0
- package/commands/spartan/tf-deploy.md +116 -0
- package/commands/spartan/tf-drift.md +100 -0
- package/commands/spartan/tf-import.md +107 -0
- package/commands/spartan/tf-module.md +121 -0
- package/commands/spartan/tf-plan.md +100 -0
- package/commands/spartan/tf-review.md +106 -0
- package/commands/spartan/tf-scaffold.md +109 -0
- package/commands/spartan/tf-security.md +147 -0
- package/commands/spartan/think.md +221 -0
- package/commands/spartan/unfreeze.md +13 -0
- package/commands/spartan/update.md +134 -0
- package/commands/spartan/ux.md +1233 -0
- package/commands/spartan/validate.md +193 -0
- package/commands/spartan/web-to-prd.md +706 -0
- package/commands/spartan/workstreams.md +109 -0
- package/commands/spartan/write.md +16 -0
- package/commands/spartan.md +386 -0
- package/frameworks/00-framework-comparison-guide.md +317 -0
- package/frameworks/01-lean-canvas.md +196 -0
- package/frameworks/02-design-sprint.md +304 -0
- package/frameworks/03-foundation-sprint.md +337 -0
- package/frameworks/04-business-model-canvas.md +391 -0
- package/frameworks/05-customer-development.md +426 -0
- package/frameworks/06-jobs-to-be-done.md +358 -0
- package/frameworks/07-mom-test.md +392 -0
- package/frameworks/08-value-proposition-canvas.md +488 -0
- package/frameworks/09-javelin-board.md +428 -0
- package/frameworks/10-build-measure-learn.md +467 -0
- package/frameworks/11-mvp-approaches.md +533 -0
- package/frameworks/think-before-build.md +593 -0
- package/lib/assembler.js +197 -0
- package/lib/assembler.test.js +159 -0
- package/lib/detector.js +166 -0
- package/lib/detector.test.js +221 -0
- package/lib/packs.js +16 -0
- package/lib/resolver.js +272 -0
- package/lib/resolver.test.js +298 -0
- package/lib/worktree.sh +104 -0
- package/package.json +50 -0
- package/packs/backend-micronaut.yaml +35 -0
- package/packs/backend-nodejs.yaml +15 -0
- package/packs/backend-python.yaml +15 -0
- package/packs/core.yaml +37 -0
- package/packs/database.yaml +21 -0
- package/packs/frontend-react.yaml +24 -0
- package/packs/infrastructure.yaml +40 -0
- package/packs/ops.yaml +16 -0
- package/packs/packs.compiled.json +371 -0
- package/packs/product.yaml +22 -0
- package/packs/project-mgmt.yaml +24 -0
- package/packs/research.yaml +39 -0
- package/packs/shared-backend.yaml +14 -0
- package/packs/ux-design.yaml +21 -0
- package/rules/backend-micronaut/API_DESIGN.md +313 -0
- package/rules/backend-micronaut/BATCH_PROCESSING.md +92 -0
- package/rules/backend-micronaut/CONTROLLERS.md +388 -0
- package/rules/backend-micronaut/KOTLIN.md +414 -0
- package/rules/backend-micronaut/RETROFIT_PLACEMENT.md +290 -0
- package/rules/backend-micronaut/SERVICES_AND_BEANS.md +325 -0
- package/rules/core/NAMING_CONVENTIONS.md +208 -0
- package/rules/core/SKILL_AUTHORING.md +174 -0
- package/rules/core/TIMEZONE.md +316 -0
- package/rules/database/ORM_AND_REPO.md +289 -0
- package/rules/database/SCHEMA.md +146 -0
- package/rules/database/TRANSACTIONS.md +311 -0
- package/rules/frontend-react/FRONTEND.md +344 -0
- package/rules/infrastructure/MODULES.md +260 -0
- package/rules/infrastructure/NAMING.md +196 -0
- package/rules/infrastructure/PROVIDERS.md +309 -0
- package/rules/infrastructure/SECURITY.md +310 -0
- package/rules/infrastructure/STATE_AND_BACKEND.md +237 -0
- package/rules/infrastructure/STRUCTURE.md +234 -0
- package/rules/infrastructure/VARIABLES.md +285 -0
- package/rules/shared-backend/ARCHITECTURE.md +46 -0
- package/rules/ux-design/DESIGN_PROCESS.md +176 -0
- package/skills/api-endpoint-creator/SKILL.md +455 -0
- package/skills/api-endpoint-creator/error-handling-guide.md +244 -0
- package/skills/api-endpoint-creator/examples.md +522 -0
- package/skills/api-endpoint-creator/testing-patterns.md +302 -0
- package/skills/article-writing/SKILL.md +109 -0
- package/skills/article-writing/examples.md +59 -0
- package/skills/backend-api-design/SKILL.md +84 -0
- package/skills/backend-api-design/code-patterns.md +138 -0
- package/skills/brainstorm/SKILL.md +95 -0
- package/skills/browser-qa/SKILL.md +87 -0
- package/skills/browser-qa/playwright-snippets.md +110 -0
- package/skills/ci-cd-patterns/SKILL.md +108 -0
- package/skills/ci-cd-patterns/workflows.md +149 -0
- package/skills/competitive-teardown/SKILL.md +93 -0
- package/skills/competitive-teardown/example-analysis.md +50 -0
- package/skills/content-engine/SKILL.md +131 -0
- package/skills/content-engine/examples.md +72 -0
- package/skills/database-patterns/SKILL.md +72 -0
- package/skills/database-patterns/code-templates.md +114 -0
- package/skills/database-table-creator/SKILL.md +141 -0
- package/skills/database-table-creator/examples.md +552 -0
- package/skills/database-table-creator/kotlin-templates.md +400 -0
- package/skills/database-table-creator/migration-template.sql +68 -0
- package/skills/database-table-creator/validation-checklist.md +337 -0
- package/skills/deep-research/SKILL.md +80 -0
- package/skills/design-intelligence/SKILL.md +268 -0
- package/skills/design-workflow/SKILL.md +127 -0
- package/skills/design-workflow/checklists.md +45 -0
- package/skills/idea-validation/SKILL.md +129 -0
- package/skills/idea-validation/example-report.md +50 -0
- package/skills/investor-materials/SKILL.md +122 -0
- package/skills/investor-materials/example-outline.md +70 -0
- package/skills/investor-outreach/SKILL.md +112 -0
- package/skills/investor-outreach/examples.md +76 -0
- package/skills/kotlin-best-practices/SKILL.md +58 -0
- package/skills/kotlin-best-practices/code-patterns.md +132 -0
- package/skills/market-research/SKILL.md +99 -0
- package/skills/security-checklist/SKILL.md +65 -0
- package/skills/security-checklist/audit-reference.md +95 -0
- package/skills/service-debugging/SKILL.md +116 -0
- package/skills/service-debugging/common-issues.md +65 -0
- package/skills/startup-pipeline/SKILL.md +152 -0
- package/skills/terraform-best-practices/SKILL.md +244 -0
- package/skills/terraform-module-creator/SKILL.md +284 -0
- package/skills/terraform-review/SKILL.md +222 -0
- package/skills/terraform-security-audit/SKILL.md +280 -0
- package/skills/terraform-service-scaffold/SKILL.md +574 -0
- package/skills/testing-strategies/SKILL.md +116 -0
- package/skills/testing-strategies/examples.md +103 -0
- package/skills/testing-strategies/integration-test-setup.md +71 -0
- package/skills/ui-ux-pro-max/SKILL.md +238 -0
- package/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/python-setup.md +146 -0
- package/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/skills/web-to-prd/SKILL.md +478 -0
- package/templates/build-config.yaml +44 -0
- package/templates/commands-config.yaml +55 -0
- package/templates/competitor-analysis.md +60 -0
- package/templates/content/AGENT_TEMPLATE.md +47 -0
- package/templates/content/COMMAND_TEMPLATE.md +27 -0
- package/templates/content/RULE_TEMPLATE.md +40 -0
- package/templates/content/SKILL_TEMPLATE.md +41 -0
- package/templates/design-config.md +105 -0
- package/templates/design-doc.md +207 -0
- package/templates/epic.md +100 -0
- package/templates/feature-spec.md +181 -0
- package/templates/idea-canvas.md +47 -0
- package/templates/implementation-plan.md +159 -0
- package/templates/prd-template.md +86 -0
- package/templates/preamble.md +89 -0
- package/templates/project-readme.md +35 -0
- package/templates/quality-gates.md +230 -0
- package/templates/spartan-config.yaml +164 -0
- package/templates/user-interview.md +69 -0
- package/templates/validation-checklist.md +108 -0
- package/templates/workflow-backend-micronaut.md +409 -0
- package/templates/workflow-frontend-react.md +233 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spartan:teardown
|
|
3
|
+
description: Deep competitor analysis — pricing, features, strengths, weaknesses, and where they leave gaps
|
|
4
|
+
argument-hint: "[competitor name or URL]"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Competitor Teardown: {{ args[0] | default: "competitor" }}
|
|
8
|
+
|
|
9
|
+
You are running a deep competitor analysis. Be brutally honest — don't downplay their strengths or inflate their weaknesses. The goal is to understand them clearly so we can find real gaps.
|
|
10
|
+
|
|
11
|
+
If the user gives a URL, use web search to find real data about the company. If they give just a name, search for it.
|
|
12
|
+
|
|
13
|
+
**Use web search** to find pricing pages, G2/Capterra reviews, traffic data, and social media mentions. Real data beats guessing.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Section 1: Overview
|
|
18
|
+
|
|
19
|
+
Write one paragraph: What do they do? Who do they serve? When were they founded? How big are they?
|
|
20
|
+
|
|
21
|
+
Keep it factual. No opinions yet.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Section 2: Pricing
|
|
26
|
+
|
|
27
|
+
| Plan | Price | Key Features |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| Free / Trial | | |
|
|
30
|
+
| Starter / Basic | | |
|
|
31
|
+
| Pro / Growth | | |
|
|
32
|
+
| Enterprise | | |
|
|
33
|
+
|
|
34
|
+
Note: Do they have a free tier? Free trial length? Annual vs monthly pricing difference?
|
|
35
|
+
What's the cheapest way to get started?
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Section 3: Feature Breakdown
|
|
40
|
+
|
|
41
|
+
| Feature | Have It? | How Good? (1-5) | Notes |
|
|
42
|
+
|---|---|---|---|
|
|
43
|
+
| [core feature 1] | Yes/No | | |
|
|
44
|
+
| [core feature 2] | Yes/No | | |
|
|
45
|
+
| [core feature 3] | Yes/No | | |
|
|
46
|
+
| ... | | | |
|
|
47
|
+
|
|
48
|
+
List 10-15 features that matter for this market. Score quality honestly.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Section 4: What They Do Well (Top 3)
|
|
53
|
+
|
|
54
|
+
List their top 3 strengths. For each one:
|
|
55
|
+
- What is it?
|
|
56
|
+
- Evidence (user reviews, market position, product quality)
|
|
57
|
+
- How hard would it be to match this?
|
|
58
|
+
|
|
59
|
+
Don't skip this. If they're winning, there's a reason.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Section 5: What They Do Poorly (Top 3)
|
|
64
|
+
|
|
65
|
+
List their top 3 weaknesses. For each one:
|
|
66
|
+
- What is it?
|
|
67
|
+
- Evidence (user complaints, missing features, bad UX)
|
|
68
|
+
- Is this a real gap or just nitpicking?
|
|
69
|
+
|
|
70
|
+
Only list real problems. "Their logo is ugly" doesn't count.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Section 6: User Reviews
|
|
75
|
+
|
|
76
|
+
Search G2, Capterra, Reddit, Twitter/X, Product Hunt for real user feedback.
|
|
77
|
+
|
|
78
|
+
**What users love:**
|
|
79
|
+
- [quote or paraphrase + source]
|
|
80
|
+
- [quote or paraphrase + source]
|
|
81
|
+
- [quote or paraphrase + source]
|
|
82
|
+
|
|
83
|
+
**What users hate:**
|
|
84
|
+
- [quote or paraphrase + source]
|
|
85
|
+
- [quote or paraphrase + source]
|
|
86
|
+
- [quote or paraphrase + source]
|
|
87
|
+
|
|
88
|
+
**Common themes:** What shows up over and over in reviews?
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Section 7: Traffic & Traction
|
|
93
|
+
|
|
94
|
+
| Metric | Value | Source |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| Monthly visitors (estimate) | | SimilarWeb / search |
|
|
97
|
+
| Growth trend | Growing / Flat / Declining | |
|
|
98
|
+
| Team size (estimate) | | LinkedIn / Crunchbase |
|
|
99
|
+
| Total funding | | Crunchbase |
|
|
100
|
+
| Last funding round | | |
|
|
101
|
+
| Notable customers | | |
|
|
102
|
+
|
|
103
|
+
If data isn't available, say so. Don't make up numbers.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Section 8: How They Get Users
|
|
108
|
+
|
|
109
|
+
Check which channels they use:
|
|
110
|
+
|
|
111
|
+
| Channel | Active? | Evidence |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| SEO / Content marketing | | Blog posts? Ranking for key terms? |
|
|
114
|
+
| Paid ads (Google/Meta) | | Found ads? Sponsorships? |
|
|
115
|
+
| Social media | | Active accounts? Engagement? |
|
|
116
|
+
| Community / Forums | | Discord? Slack? Reddit presence? |
|
|
117
|
+
| Partnerships / Integrations | | App stores? Partner pages? |
|
|
118
|
+
| Word of mouth / Referrals | | Referral program? Organic mentions? |
|
|
119
|
+
| Product Hunt / Launch sites | | Past launches? |
|
|
120
|
+
|
|
121
|
+
What's their main growth channel? Where do most users come from?
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Section 9: Positioning
|
|
126
|
+
|
|
127
|
+
- **How they describe themselves:** [their tagline / hero text]
|
|
128
|
+
- **Target persona:** Who are they really building for?
|
|
129
|
+
- **Positioning:** Are they the cheap option? The premium option? The easy option? The powerful option?
|
|
130
|
+
- **Brand voice:** Corporate / Casual / Technical / Friendly?
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Section 10: Our Opportunity
|
|
135
|
+
|
|
136
|
+
This is the "so what?" section. Based on everything above:
|
|
137
|
+
|
|
138
|
+
**Gaps they leave open:**
|
|
139
|
+
- [gap 1 — who's underserved?]
|
|
140
|
+
- [gap 2 — what feature is missing or weak?]
|
|
141
|
+
- [gap 3 — what segment do they ignore?]
|
|
142
|
+
|
|
143
|
+
**What we'd do differently:**
|
|
144
|
+
- [difference 1]
|
|
145
|
+
- [difference 2]
|
|
146
|
+
- [difference 3]
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## So What?
|
|
151
|
+
|
|
152
|
+
Write one paragraph: What does this teardown mean for our strategy? Where should we compete, and where should we avoid competing?
|
|
153
|
+
|
|
154
|
+
Be specific. "We should differentiate" is useless. Say HOW and WHERE.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
**Next steps:**
|
|
159
|
+
- Want to analyze another competitor? Run `/spartan:teardown [name]` again
|
|
160
|
+
- Ready to compare multiple competitors side by side? Ask me to build a comparison matrix
|
|
161
|
+
- Want to validate your positioning? Run `/spartan:validate` with your idea
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spartan:testcontainer
|
|
3
|
+
description: Set up integration testing infrastructure for a Kotlin Micronaut service using @MicronautTest and Testcontainers
|
|
4
|
+
argument-hint: "[postgres | kafka | redis | all]"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Set up integration testing in this Kotlin Micronaut project.
|
|
8
|
+
|
|
9
|
+
**Reference:** `/testing-strategies` skill and `rules/backend-micronaut/API_DESIGN.md` (testing section)
|
|
10
|
+
|
|
11
|
+
## Requested containers: {{ args[0] | default: "postgres" }}
|
|
12
|
+
|
|
13
|
+
### 1. Add Dependencies (build.gradle.kts)
|
|
14
|
+
|
|
15
|
+
```kotlin
|
|
16
|
+
testImplementation("org.testcontainers:testcontainers:1.19.3")
|
|
17
|
+
testImplementation("org.testcontainers:junit-jupiter:1.19.3")
|
|
18
|
+
testImplementation("org.testcontainers:postgresql:1.19.3")
|
|
19
|
+
testImplementation("io.micronaut.test:micronaut-test-junit5")
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Create Base Test Configuration
|
|
23
|
+
|
|
24
|
+
Create `src/test/kotlin/.../AbstractControllerTest.kt`:
|
|
25
|
+
|
|
26
|
+
```kotlin
|
|
27
|
+
@MicronautTest(environments = ["test"], transactional = false)
|
|
28
|
+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
29
|
+
abstract class AbstractControllerTest {
|
|
30
|
+
|
|
31
|
+
@Inject
|
|
32
|
+
lateinit var embeddedServer: EmbeddedServer
|
|
33
|
+
|
|
34
|
+
@BeforeAll
|
|
35
|
+
open fun beforeAll() {
|
|
36
|
+
// Setup test clients from embeddedServer.url
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
companion object {
|
|
40
|
+
@Container
|
|
41
|
+
@JvmStatic
|
|
42
|
+
val postgres = PostgreSQLContainer("postgres:16-alpine")
|
|
43
|
+
.withDatabaseName("testdb")
|
|
44
|
+
.withUsername("test")
|
|
45
|
+
.withPassword("test")
|
|
46
|
+
|
|
47
|
+
@DynamicPropertySource
|
|
48
|
+
@JvmStatic
|
|
49
|
+
fun overrideProperties(registry: DynamicPropertyRegistry) {
|
|
50
|
+
registry.add("datasources.default.url", postgres::getJdbcUrl)
|
|
51
|
+
registry.add("datasources.default.username", postgres::getUsername)
|
|
52
|
+
registry.add("datasources.default.password", postgres::getPassword)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Create Example Integration Test
|
|
59
|
+
|
|
60
|
+
```kotlin
|
|
61
|
+
class EmployeeControllerTest : AbstractControllerTest() {
|
|
62
|
+
|
|
63
|
+
private lateinit var employeeClient: EmployeeClient
|
|
64
|
+
|
|
65
|
+
@BeforeAll
|
|
66
|
+
override fun beforeAll() {
|
|
67
|
+
super.beforeAll()
|
|
68
|
+
val url = embeddedServer.url.toString()
|
|
69
|
+
employeeClient = EmployeeClient(url)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Test
|
|
73
|
+
fun `create employee returns success`() {
|
|
74
|
+
val request = CreateEmployeeRequest(name = "Test User", email = "test@example.com")
|
|
75
|
+
val response = employeeClient.create(request)
|
|
76
|
+
assertNotNull(response.id)
|
|
77
|
+
assertEquals("Test User", response.name)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 4. Application config for test profile
|
|
83
|
+
|
|
84
|
+
Create `src/test/resources/application-test.yml`:
|
|
85
|
+
```yaml
|
|
86
|
+
datasources:
|
|
87
|
+
default:
|
|
88
|
+
# Overridden by Testcontainers DynamicPropertySource
|
|
89
|
+
dialect: POSTGRES
|
|
90
|
+
flyway:
|
|
91
|
+
datasources:
|
|
92
|
+
default:
|
|
93
|
+
enabled: true
|
|
94
|
+
locations: classpath:db/migration
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
After setup, verify all tests pass with: `./gradlew test`
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spartan:tf-cost
|
|
3
|
+
description: Cost estimation guidance — sizing recommendations, common patterns, optimization tips
|
|
4
|
+
argument-hint: "[optional: resource-type]"
|
|
5
|
+
preamble-tier: 2
|
|
6
|
+
---
|
|
7
|
+
@rules/infrastructure/STRUCTURE.md
|
|
8
|
+
@rules/infrastructure/MODULES.md
|
|
9
|
+
|
|
10
|
+
# Terraform Cost Estimation: {{ args[0] | default: "infrastructure review" }}
|
|
11
|
+
|
|
12
|
+
Review infrastructure costs and provide sizing recommendations.
|
|
13
|
+
|
|
14
|
+
## Step 1: Identify Resources
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# List all resource types in the current config
|
|
18
|
+
grep -r "^resource " *.tf modules/ 2>/dev/null | awk '{print $2}' | sort | uniq -c | sort -rn
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Step 2: Common Cost Patterns
|
|
22
|
+
|
|
23
|
+
### RDS (PostgreSQL/Aurora)
|
|
24
|
+
|
|
25
|
+
| Environment | Instance | Storage | Multi-AZ | Est. Monthly |
|
|
26
|
+
|-------------|----------|---------|----------|-------------|
|
|
27
|
+
| dev | `db.t3.micro` | 20 GB gp3 | No | ~$15 |
|
|
28
|
+
| staging | `db.t3.small` | 50 GB gp3 | No | ~$30 |
|
|
29
|
+
| prod | `db.r6g.large` | 100 GB gp3 | Yes | ~$400 |
|
|
30
|
+
|
|
31
|
+
**Optimization:**
|
|
32
|
+
- Use `db.t3.*` for dev/staging — burstable is fine for low traffic
|
|
33
|
+
- Enable storage autoscaling with a max limit
|
|
34
|
+
- Aurora Serverless v2 for variable workloads (0.5-128 ACU)
|
|
35
|
+
|
|
36
|
+
### ElastiCache (Redis)
|
|
37
|
+
|
|
38
|
+
| Environment | Instance | Replicas | Est. Monthly |
|
|
39
|
+
|-------------|----------|----------|-------------|
|
|
40
|
+
| dev | `cache.t3.micro` | 0 | ~$12 |
|
|
41
|
+
| staging | `cache.t3.small` | 0 | ~$25 |
|
|
42
|
+
| prod | `cache.r6g.large` | 1 | ~$300 |
|
|
43
|
+
|
|
44
|
+
### NAT Gateway
|
|
45
|
+
|
|
46
|
+
> **Cost trap:** NAT gateways charge per hour AND per GB processed.
|
|
47
|
+
|
|
48
|
+
| Setup | Est. Monthly |
|
|
49
|
+
|-------|-------------|
|
|
50
|
+
| 1 NAT per AZ (3 AZs) | ~$100 + data |
|
|
51
|
+
| 1 shared NAT | ~$33 + data |
|
|
52
|
+
| NAT instance (t3.micro) | ~$8 |
|
|
53
|
+
|
|
54
|
+
**Optimization:**
|
|
55
|
+
- Dev: use a single NAT or NAT instance
|
|
56
|
+
- Prod: one NAT per AZ for high availability
|
|
57
|
+
- Route S3/DynamoDB through VPC endpoints (free) instead of NAT
|
|
58
|
+
|
|
59
|
+
### ECS Fargate
|
|
60
|
+
|
|
61
|
+
| Size | vCPU | Memory | Est. Monthly (24/7) |
|
|
62
|
+
|------|------|--------|-------------------|
|
|
63
|
+
| Micro | 0.25 | 0.5 GB | ~$9 |
|
|
64
|
+
| Small | 0.5 | 1 GB | ~$18 |
|
|
65
|
+
| Medium | 1 | 2 GB | ~$36 |
|
|
66
|
+
| Large | 2 | 4 GB | ~$73 |
|
|
67
|
+
|
|
68
|
+
**Optimization:**
|
|
69
|
+
- Use Fargate Spot for dev/staging (up to 70% savings)
|
|
70
|
+
- Right-size: check CloudWatch CPU/memory utilization
|
|
71
|
+
- Scale to zero in dev after hours
|
|
72
|
+
|
|
73
|
+
### EKS Node Groups
|
|
74
|
+
|
|
75
|
+
| Environment | Instance | Nodes | Est. Monthly |
|
|
76
|
+
|-------------|----------|-------|-------------|
|
|
77
|
+
| dev | `t3.medium` | 2 | ~$60 + $75 (control plane) |
|
|
78
|
+
| prod | `m6i.xlarge` | 3-6 | ~$300-600 + $75 |
|
|
79
|
+
|
|
80
|
+
**Note:** EKS control plane is $75/month regardless of size.
|
|
81
|
+
|
|
82
|
+
## Step 3: Dev vs Prod Sizing
|
|
83
|
+
|
|
84
|
+
| Resource | Dev | Prod | Savings |
|
|
85
|
+
|----------|-----|------|---------|
|
|
86
|
+
| RDS | t3.micro, no Multi-AZ | r6g.large, Multi-AZ | 95% |
|
|
87
|
+
| Redis | t3.micro, no replica | r6g.large, 1 replica | 95% |
|
|
88
|
+
| NAT | 1 shared or NAT instance | 1 per AZ | 70% |
|
|
89
|
+
| Fargate | Spot, min replicas | On-demand, auto-scale | 60% |
|
|
90
|
+
| EKS | Spot nodes, smaller | On-demand, right-sized | 50% |
|
|
91
|
+
|
|
92
|
+
## Step 4: Cost Optimization Tips
|
|
93
|
+
|
|
94
|
+
1. **VPC Endpoints** — S3 and DynamoDB gateway endpoints are free. Saves NAT data costs.
|
|
95
|
+
2. **Reserved Instances** — 1-year no-upfront saves ~30% on RDS/ElastiCache in prod.
|
|
96
|
+
3. **Scheduled scaling** — Scale down dev/staging outside business hours.
|
|
97
|
+
4. **S3 lifecycle rules** — Move old objects to Glacier or Intelligent-Tiering.
|
|
98
|
+
5. **Right-size** — Review CloudWatch metrics monthly. Downsize over-provisioned resources.
|
|
99
|
+
6. **Clean up** — Delete unused EBS snapshots, old AMIs, unattached EIPs.
|
|
100
|
+
|
|
101
|
+
## Step 5: Estimate for Current Config
|
|
102
|
+
|
|
103
|
+
Review the Terraform config and produce:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
## Cost Estimate: {env}
|
|
107
|
+
|
|
108
|
+
| Resource | Type | Size | Est. Monthly |
|
|
109
|
+
|----------|------|------|-------------|
|
|
110
|
+
| RDS | PostgreSQL | db.t3.small | $30 |
|
|
111
|
+
| ... | ... | ... | ... |
|
|
112
|
+
|
|
113
|
+
**Total estimated:** $X/month
|
|
114
|
+
**Potential savings:** $Y/month with [recommendations]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Rules
|
|
118
|
+
|
|
119
|
+
- These are estimates — use AWS Pricing Calculator for exact numbers
|
|
120
|
+
- Always compare dev vs prod sizing — dev should be minimal
|
|
121
|
+
- Flag NAT gateway costs explicitly — they surprise teams
|
|
122
|
+
- Recommend VPC endpoints before adding NAT gateways for AWS service traffic
|
|
123
|
+
- Cost reviews should happen before deploying new infrastructure, not after
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spartan:tf-deploy
|
|
3
|
+
description: Deployment checklist — pre-deploy verification, apply, post-deploy health checks
|
|
4
|
+
argument-hint: "[environment]"
|
|
5
|
+
preamble-tier: 3
|
|
6
|
+
---
|
|
7
|
+
@rules/infrastructure/STATE_AND_BACKEND.md
|
|
8
|
+
|
|
9
|
+
# Terraform Deploy: {{ args[0] | default: "target environment" }}
|
|
10
|
+
|
|
11
|
+
Deploy Terraform changes with a full pre/post checklist.
|
|
12
|
+
|
|
13
|
+
## Pre-Deploy Checklist
|
|
14
|
+
|
|
15
|
+
### 1. Verify Branch
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git branch --show-current
|
|
19
|
+
git status --short
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- [ ] On the correct branch (not `main` for direct apply)
|
|
23
|
+
- [ ] No uncommitted changes to `.tf` files
|
|
24
|
+
- [ ] PR approved (for staging/prod)
|
|
25
|
+
|
|
26
|
+
### 2. Run Plan
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
terraform plan \
|
|
30
|
+
-var-file=../../envs/{{ args[0] | default: "dev" }}.tfvars \
|
|
31
|
+
-out=tfplan \
|
|
32
|
+
-detailed-exitcode
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- [ ] Plan reviewed and understood
|
|
36
|
+
- [ ] No unexpected destroys or replacements
|
|
37
|
+
- [ ] Resource count matches expectations
|
|
38
|
+
|
|
39
|
+
### 3. Review Changes
|
|
40
|
+
|
|
41
|
+
Summarize what will change:
|
|
42
|
+
|
|
43
|
+
| Action | Resource | Detail |
|
|
44
|
+
|--------|----------|--------|
|
|
45
|
+
| create | `aws_...` | New resource |
|
|
46
|
+
| update | `aws_...` | What's changing |
|
|
47
|
+
| replace | `aws_...` | WHY it's being replaced |
|
|
48
|
+
|
|
49
|
+
### 4. Check State Locks
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Verify no one else is running terraform
|
|
53
|
+
terraform plan -lock=true 2>&1 | grep -i "lock"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If state is locked, identify who holds the lock before proceeding.
|
|
57
|
+
|
|
58
|
+
## Deploy
|
|
59
|
+
|
|
60
|
+
### 5. Apply
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
terraform apply tfplan
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- Monitor output for errors
|
|
67
|
+
- If apply fails mid-way, DO NOT re-plan — the state has partially updated
|
|
68
|
+
- On partial failure: fix the issue, then run `terraform plan` again to see remaining changes
|
|
69
|
+
|
|
70
|
+
### 6. Verify Apply Output
|
|
71
|
+
|
|
72
|
+
- [ ] All resources show `Creation complete` or `Modifications complete`
|
|
73
|
+
- [ ] No errors in output
|
|
74
|
+
- [ ] Apply completed with `Apply complete! Resources: X added, Y changed, Z destroyed.`
|
|
75
|
+
|
|
76
|
+
## Post-Deploy
|
|
77
|
+
|
|
78
|
+
### 7. Verify Resources
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Check key resources exist and are healthy
|
|
82
|
+
aws ecs describe-services --cluster {project}-{env} --services {service} 2>/dev/null
|
|
83
|
+
aws rds describe-db-instances --db-instance-identifier {project}-{env}-{service} 2>/dev/null
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- [ ] Service is running / database is available
|
|
87
|
+
- [ ] Security groups are correctly attached
|
|
88
|
+
- [ ] DNS records resolve (if applicable)
|
|
89
|
+
|
|
90
|
+
### 8. Health Check
|
|
91
|
+
|
|
92
|
+
- [ ] Application health endpoint returns 200
|
|
93
|
+
- [ ] Logs show successful startup (no crash loops)
|
|
94
|
+
- [ ] Metrics pipeline receiving data
|
|
95
|
+
|
|
96
|
+
### 9. Notify
|
|
97
|
+
|
|
98
|
+
Post deployment summary:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
## Deploy Complete: {service} → {{ args[0] | default: "dev" }}
|
|
102
|
+
|
|
103
|
+
- **Resources:** X added, Y changed, Z destroyed
|
|
104
|
+
- **Commit:** [hash]
|
|
105
|
+
- **Health:** [passing / issues]
|
|
106
|
+
- **Rollback plan:** [revert commit and re-apply / restore from state backup]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Rules
|
|
110
|
+
|
|
111
|
+
- Never apply without reviewing the plan first
|
|
112
|
+
- Never apply directly to prod without approval
|
|
113
|
+
- Always use saved plan file (`tfplan`) — never `terraform apply` without `-out`
|
|
114
|
+
- If apply fails partially, do NOT run `terraform destroy` — fix forward
|
|
115
|
+
- Keep the terminal open during apply — interrupted applies can corrupt state
|
|
116
|
+
- For prod deployments, have a rollback plan documented before applying
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spartan:tf-drift
|
|
3
|
+
description: Detect and categorize infrastructure drift — benign vs concerning changes
|
|
4
|
+
argument-hint: "[environment]"
|
|
5
|
+
preamble-tier: 2
|
|
6
|
+
---
|
|
7
|
+
@rules/infrastructure/STATE_AND_BACKEND.md
|
|
8
|
+
|
|
9
|
+
# Terraform Drift Detection: {{ args[0] | default: "target environment" }}
|
|
10
|
+
|
|
11
|
+
Detect and analyze differences between Terraform state and actual infrastructure.
|
|
12
|
+
|
|
13
|
+
## Step 1: Initialize
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
terraform init -backend-config=../../envs/{{ args[0] | default: "dev" }}.tfbackend
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Step 2: Refresh and Plan
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
terraform plan \
|
|
23
|
+
-var-file=../../envs/{{ args[0] | default: "dev" }}.tfvars \
|
|
24
|
+
-refresh-only \
|
|
25
|
+
-detailed-exitcode
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Exit code `2` means drift was detected.
|
|
29
|
+
|
|
30
|
+
For a full view including config vs state:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
terraform plan \
|
|
34
|
+
-var-file=../../envs/{{ args[0] | default: "dev" }}.tfvars \
|
|
35
|
+
-detailed-exitcode
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Step 3: Analyze Drift
|
|
39
|
+
|
|
40
|
+
For each drifted resource, determine the cause:
|
|
41
|
+
|
|
42
|
+
| Category | Examples | Action |
|
|
43
|
+
|----------|----------|--------|
|
|
44
|
+
| **Benign** | Auto-scaling changed instance count, AWS updated default SSL policy, tags added by AWS | Ignore or update config |
|
|
45
|
+
| **Expected** | Manual hotfix applied, console change during incident | Adopt into config or revert |
|
|
46
|
+
| **Concerning** | Security group rules changed, IAM policy modified, encryption disabled | Investigate immediately |
|
|
47
|
+
| **Critical** | Resources deleted outside Terraform, access controls weakened | Escalate and remediate |
|
|
48
|
+
|
|
49
|
+
## Step 4: Categorize Findings
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
## Drift Report: {{ args[0] | default: "dev" }}
|
|
53
|
+
|
|
54
|
+
### Benign (no action needed)
|
|
55
|
+
- `aws_autoscaling_group.this` — desired_count changed by auto-scaler
|
|
56
|
+
|
|
57
|
+
### Expected (adopt or revert)
|
|
58
|
+
- `aws_security_group_rule.hotfix` — added during incident on [date]
|
|
59
|
+
→ Recommendation: adopt into config
|
|
60
|
+
|
|
61
|
+
### Concerning (investigate)
|
|
62
|
+
- `aws_iam_policy.service_role` — permissions widened
|
|
63
|
+
→ Recommendation: review who changed this and why
|
|
64
|
+
|
|
65
|
+
### Critical (immediate action)
|
|
66
|
+
- [none found / list items]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Step 5: Remediate
|
|
70
|
+
|
|
71
|
+
For each category:
|
|
72
|
+
|
|
73
|
+
- **Benign** — Update Terraform config to match reality, or add `lifecycle { ignore_changes }`:
|
|
74
|
+
```hcl
|
|
75
|
+
lifecycle {
|
|
76
|
+
ignore_changes = [desired_count]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- **Expected** — Either update config to match (adopt) or run `terraform apply` to revert to config.
|
|
81
|
+
|
|
82
|
+
- **Concerning** — Investigate through CloudTrail, then decide: adopt or revert.
|
|
83
|
+
|
|
84
|
+
- **Critical** — Revert immediately with `terraform apply`, then investigate.
|
|
85
|
+
|
|
86
|
+
## Step 6: Apply Corrections
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
terraform plan -var-file=../../envs/{env}.tfvars -out=tfplan
|
|
90
|
+
# Review the plan
|
|
91
|
+
terraform apply tfplan
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Rules
|
|
95
|
+
|
|
96
|
+
- Run drift detection on a schedule — weekly for prod, bi-weekly for other envs
|
|
97
|
+
- Never auto-apply drift corrections without human review
|
|
98
|
+
- Use CloudTrail to identify who made out-of-band changes
|
|
99
|
+
- Add `ignore_changes` only for attributes that legitimately change outside Terraform (e.g., auto-scaling counts)
|
|
100
|
+
- Document all adopted drift in commit messages explaining why the manual change was made
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spartan:tf-import
|
|
3
|
+
description: Import existing AWS resources into Terraform state with config generation
|
|
4
|
+
argument-hint: "[resource-type resource-id]"
|
|
5
|
+
preamble-tier: 3
|
|
6
|
+
---
|
|
7
|
+
@rules/infrastructure/STRUCTURE.md
|
|
8
|
+
@rules/infrastructure/NAMING.md
|
|
9
|
+
|
|
10
|
+
# Terraform Import: {{ args[0] | default: "existing resource" }}
|
|
11
|
+
|
|
12
|
+
Import an existing resource into Terraform management.
|
|
13
|
+
|
|
14
|
+
## Step 1: Identify the Resource
|
|
15
|
+
|
|
16
|
+
Parse the user's input to determine:
|
|
17
|
+
- **Resource type** — AWS resource type (e.g., `aws_s3_bucket`, `aws_rds_instance`)
|
|
18
|
+
- **Resource ID** — The identifier used by AWS (ARN, name, or ID)
|
|
19
|
+
|
|
20
|
+
If not provided, ask:
|
|
21
|
+
|
|
22
|
+
> **What resource are you importing?**
|
|
23
|
+
>
|
|
24
|
+
> Examples:
|
|
25
|
+
> - `aws_s3_bucket my-bucket-name`
|
|
26
|
+
> - `aws_db_instance my-rds-instance`
|
|
27
|
+
> - `aws_security_group sg-0123456789abcdef`
|
|
28
|
+
> - `aws_iam_role my-role-name`
|
|
29
|
+
|
|
30
|
+
## Step 2: Write Terraform Config
|
|
31
|
+
|
|
32
|
+
Before importing, write the resource block that matches the existing resource.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Describe the resource to get current config
|
|
36
|
+
aws s3api get-bucket-versioning --bucket {bucket-name} 2>/dev/null
|
|
37
|
+
aws rds describe-db-instances --db-instance-identifier {instance-id} 2>/dev/null
|
|
38
|
+
aws ec2 describe-security-groups --group-ids {sg-id} 2>/dev/null
|
|
39
|
+
aws iam get-role --role-name {role-name} 2>/dev/null
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Write a resource block that matches the existing state as closely as possible:
|
|
43
|
+
|
|
44
|
+
```hcl
|
|
45
|
+
resource "aws_resource_type" "this" {
|
|
46
|
+
# Match existing configuration exactly
|
|
47
|
+
# to minimize drift on first plan
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Step 3: Run Import
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
terraform import aws_resource_type.this {resource-id}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Common Import Patterns
|
|
58
|
+
|
|
59
|
+
| Resource | Import ID Format |
|
|
60
|
+
|----------|-----------------|
|
|
61
|
+
| `aws_s3_bucket` | Bucket name |
|
|
62
|
+
| `aws_db_instance` | DB instance identifier |
|
|
63
|
+
| `aws_security_group` | Security group ID (`sg-xxx`) |
|
|
64
|
+
| `aws_iam_role` | Role name |
|
|
65
|
+
| `aws_ecs_service` | `{cluster}/{service}` |
|
|
66
|
+
| `aws_lb` | ALB ARN |
|
|
67
|
+
| `aws_route53_record` | `{zone_id}_{name}_{type}` |
|
|
68
|
+
| `aws_ecr_repository` | Repository name |
|
|
69
|
+
|
|
70
|
+
## Step 4: Verify State
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
terraform state show aws_resource_type.this
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Confirm the state contains the expected attributes.
|
|
77
|
+
|
|
78
|
+
## Step 5: Plan to Check Drift
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
terraform plan -var-file=../../envs/{env}.tfvars
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Review the plan output:
|
|
85
|
+
- **No changes** — config matches reality. Done.
|
|
86
|
+
- **In-place updates** — config differs from reality. Update your `.tf` to match, or accept the change.
|
|
87
|
+
- **Replace** — a force-new attribute differs. Update your `.tf` to match exactly.
|
|
88
|
+
|
|
89
|
+
Iterate: adjust the resource block until `terraform plan` shows no changes.
|
|
90
|
+
|
|
91
|
+
## Step 6: Commit
|
|
92
|
+
|
|
93
|
+
Once plan shows no changes:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git add -A
|
|
97
|
+
git commit -m "feat(infra): import {resource-type} into terraform state"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Rules
|
|
101
|
+
|
|
102
|
+
- Always write the resource config BEFORE running import
|
|
103
|
+
- After import, run plan immediately — never leave imported resources with drift
|
|
104
|
+
- Iterate until plan shows zero changes
|
|
105
|
+
- Import one resource at a time — don't batch
|
|
106
|
+
- For resources with dependencies, import in dependency order (VPC → subnet → security group → instance)
|
|
107
|
+
- Never import resources managed by another Terraform workspace
|