oh-my-agent-commandcode 0.0.0-stage → 20.38.4
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/README.md +35 -2
- package/filter-test-output.sh +52 -0
- package/mods/oma.ts +347 -0
- package/package.json +30 -4
- package/skills/_shared/conditional/experiment-ledger.md +28 -0
- package/skills/_shared/conditional/exploration-loop.md +22 -0
- package/skills/_shared/conditional/quality-score.md +33 -0
- package/skills/_shared/core/anti-ai-prose.md +191 -0
- package/skills/_shared/core/api-contracts/README.md +28 -0
- package/skills/_shared/core/api-contracts/template.md +90 -0
- package/skills/_shared/core/clarification-protocol.md +23 -0
- package/skills/_shared/core/code-intelligence.md +46 -0
- package/skills/_shared/core/collaboration-policy.md +28 -0
- package/skills/_shared/core/common-checklist.md +28 -0
- package/skills/_shared/core/context-budget.md +22 -0
- package/skills/_shared/core/context-loading.md +34 -0
- package/skills/_shared/core/difficulty-guide.md +26 -0
- package/skills/_shared/core/execution-policy.md +31 -0
- package/skills/_shared/core/lessons-learned.md +33 -0
- package/skills/_shared/core/prompt-structure.md +18 -0
- package/skills/_shared/core/quality-principles.md +11 -0
- package/skills/_shared/core/session-metrics.md +35 -0
- package/skills/_shared/core/skill-routing.md +39 -0
- package/skills/_shared/core/test-approach.md +54 -0
- package/skills/_shared/core/vendor-detection.md +52 -0
- package/skills/_shared/runtime/memory-protocol.md +118 -0
- package/skills/_shared/runtime/result-contract.md +64 -0
- package/skills/_shared/ui-interaction-quality.md +133 -0
- package/skills/oma-academic-writing/SKILL.md +181 -0
- package/skills/oma-academic-writing/resources/abstract-guide.md +51 -0
- package/skills/oma-academic-writing/resources/academic-verb-tiers.md +42 -0
- package/skills/oma-academic-writing/resources/anti-ai-checklist.md +52 -0
- package/skills/oma-academic-writing/resources/hedging-guide.md +132 -0
- package/skills/oma-academic-writing/resources/sentence-structure-reference.md +151 -0
- package/skills/oma-architecture/SKILL.md +203 -0
- package/skills/oma-architecture/resources/api-evolution.md +41 -0
- package/skills/oma-architecture/resources/checklist.md +42 -0
- package/skills/oma-architecture/resources/execution-protocol.md +115 -0
- package/skills/oma-architecture/resources/methodology-selection.md +92 -0
- package/skills/oma-architecture/resources/migration-patterns.md +28 -0
- package/skills/oma-architecture/resources/output-templates.md +111 -0
- package/skills/oma-architecture/resources/stakeholder-synthesis.md +80 -0
- package/skills/oma-backend/SKILL.md +202 -0
- package/skills/oma-backend/resources/checklist.md +45 -0
- package/skills/oma-backend/resources/error-playbook.md +97 -0
- package/skills/oma-backend/resources/execution-protocol.md +39 -0
- package/skills/oma-backend/resources/orm-reference.md +61 -0
- package/skills/oma-backend/variants/node/api-template.ts +315 -0
- package/skills/oma-backend/variants/node/snippets.md +475 -0
- package/skills/oma-backend/variants/node/stack.yaml +21 -0
- package/skills/oma-backend/variants/node/tech-stack.md +33 -0
- package/skills/oma-backend/variants/python/api-template.py +378 -0
- package/skills/oma-backend/variants/python/snippets.md +199 -0
- package/skills/oma-backend/variants/python/stack.yaml +18 -0
- package/skills/oma-backend/variants/python/tech-stack.md +45 -0
- package/skills/oma-backend/variants/rust/api-template.rs +635 -0
- package/skills/oma-backend/variants/rust/snippets.md +471 -0
- package/skills/oma-backend/variants/rust/stack.yaml +20 -0
- package/skills/oma-backend/variants/rust/tech-stack.md +36 -0
- package/skills/oma-backend/variants/stack.schema.json +73 -0
- package/skills/oma-brainstorm/SKILL.md +166 -0
- package/skills/oma-brainstorm/resources/triz-lite.md +117 -0
- package/skills/oma-coordination/SKILL.md +171 -0
- package/skills/oma-db/SKILL.md +201 -0
- package/skills/oma-db/resources/anti-patterns.md +177 -0
- package/skills/oma-db/resources/checklist.md +67 -0
- package/skills/oma-db/resources/document-templates.md +107 -0
- package/skills/oma-db/resources/error-playbook.md +50 -0
- package/skills/oma-db/resources/examples.md +170 -0
- package/skills/oma-db/resources/execution-protocol.md +127 -0
- package/skills/oma-db/resources/iso-controls.md +98 -0
- package/skills/oma-db/resources/migration-playbook.md +93 -0
- package/skills/oma-db/resources/query-tuning.md +57 -0
- package/skills/oma-db/resources/vector-db.md +159 -0
- package/skills/oma-debug/SKILL.md +146 -0
- package/skills/oma-debug/resources/bug-report-template.md +327 -0
- package/skills/oma-debug/resources/checklist.md +31 -0
- package/skills/oma-debug/resources/common-patterns.md +734 -0
- package/skills/oma-debug/resources/debugging-checklist.md +364 -0
- package/skills/oma-debug/resources/error-playbook.md +94 -0
- package/skills/oma-debug/resources/execution-protocol.md +40 -0
- package/skills/oma-design/SKILL.md +135 -0
- package/skills/oma-design/resources/asset-strategy.md +34 -0
- package/skills/oma-design/resources/checklist.md +63 -0
- package/skills/oma-design/resources/data-grid.md +48 -0
- package/skills/oma-design/resources/design-md-spec.md +107 -0
- package/skills/oma-design/resources/design-tokens.md +53 -0
- package/skills/oma-design/resources/error-playbook.md +18 -0
- package/skills/oma-design/resources/execution-protocol.md +95 -0
- package/skills/oma-design/resources/external-design-skills.md +130 -0
- package/skills/oma-design/resources/getdesign-fetcher.md +104 -0
- package/skills/oma-design/resources/product-interface-review.md +59 -0
- package/skills/oma-design/resources/redesign-protocol.md +52 -0
- package/skills/oma-design/resources/stitch-integration.md +244 -0
- package/skills/oma-dev-workflow/SKILL.md +375 -0
- package/skills/oma-dev-workflow/resources/affected-checks.py +58 -0
- package/skills/oma-dev-workflow/resources/api-workflows.md +58 -0
- package/skills/oma-dev-workflow/resources/database-patterns.md +107 -0
- package/skills/oma-dev-workflow/resources/i18n-patterns.md +63 -0
- package/skills/oma-dev-workflow/resources/release-coordination.md +240 -0
- package/skills/oma-dev-workflow/resources/tooling-profiles.md +217 -0
- package/skills/oma-dev-workflow/resources/troubleshooting.md +78 -0
- package/skills/oma-dev-workflow/resources/validation-pipeline.md +246 -0
- package/skills/oma-docs/SKILL.md +77 -0
- package/skills/oma-docs/resources/commands.md +76 -0
- package/skills/oma-explanation/SKILL.md +212 -0
- package/skills/oma-explanation/resources/document-structure.md +115 -0
- package/skills/oma-explanation/resources/draft-format.md +199 -0
- package/skills/oma-explanation/resources/html-contract.md +102 -0
- package/skills/oma-frontend/SKILL.md +227 -0
- package/skills/oma-frontend/resources/angular-rules.md +110 -0
- package/skills/oma-frontend/resources/checklist.md +76 -0
- package/skills/oma-frontend/resources/error-playbook.md +125 -0
- package/skills/oma-frontend/resources/execution-protocol.md +46 -0
- package/skills/oma-frontend/resources/snippets.md +354 -0
- package/skills/oma-frontend/resources/specialized-visual-implementation.md +193 -0
- package/skills/oma-frontend/resources/tailwind-rules.md +83 -0
- package/skills/oma-frontend/resources/tech-stack.md +156 -0
- package/skills/oma-hwp/SKILL.md +166 -0
- package/skills/oma-hwp/config/hwp-config.yaml +35 -0
- package/skills/oma-hwp/resources/balanced-tables.ts +39 -0
- package/skills/oma-hwp/resources/execution-protocol.md +145 -0
- package/skills/oma-hwp/resources/flatten-tables.ts +101 -0
- package/skills/oma-hwp/resources/package.json +13 -0
- package/skills/oma-hwp/resources/troubleshooting.md +70 -0
- package/skills/oma-hwp/resources/tsconfig.json +10 -0
- package/skills/oma-hwp/resources/turndown-plugin-gfm.d.ts +9 -0
- package/skills/oma-image/SKILL.md +142 -0
- package/skills/oma-image/config/image-config.yaml +70 -0
- package/skills/oma-image/resources/checklist.md +18 -0
- package/skills/oma-image/resources/execution-protocol.md +117 -0
- package/skills/oma-image/resources/invocation.md +105 -0
- package/skills/oma-image/resources/prompt-tips.md +71 -0
- package/skills/oma-image/resources/vendor-matrix.md +90 -0
- package/skills/oma-market/SKILL.md +142 -0
- package/skills/oma-market/resources/checklist.md +12 -0
- package/skills/oma-market/resources/error-playbook.md +12 -0
- package/skills/oma-market/resources/execution-protocol.md +60 -0
- package/skills/oma-market/resources/frameworks/pestel.md +101 -0
- package/skills/oma-market/resources/frameworks/porters-5f.md +90 -0
- package/skills/oma-market/resources/frameworks/swot.md +61 -0
- package/skills/oma-market/resources/intent-rules.md +35 -0
- package/skills/oma-market/resources/output-laws.md +53 -0
- package/skills/oma-mobile/SKILL.md +168 -0
- package/skills/oma-mobile/resources/checklist.md +77 -0
- package/skills/oma-mobile/resources/error-playbook.md +198 -0
- package/skills/oma-mobile/resources/execution-protocol.md +47 -0
- package/skills/oma-mobile/resources/screen-template.dart +331 -0
- package/skills/oma-mobile/resources/screen-template.swift +239 -0
- package/skills/oma-mobile/resources/screen-template.tsx +179 -0
- package/skills/oma-mobile/resources/tech-stack.md +69 -0
- package/skills/oma-mobile/variants/README.md +45 -0
- package/skills/oma-mobile/variants/flutter/api-template.dart +461 -0
- package/skills/oma-mobile/variants/flutter/snippets.md +1353 -0
- package/skills/oma-mobile/variants/flutter/stack.yaml +21 -0
- package/skills/oma-mobile/variants/flutter/tech-stack.md +201 -0
- package/skills/oma-mobile/variants/kotlin-android/api-template.kt +182 -0
- package/skills/oma-mobile/variants/kotlin-android/snippets.md +871 -0
- package/skills/oma-mobile/variants/kotlin-android/stack.yaml +32 -0
- package/skills/oma-mobile/variants/kotlin-android/tech-stack.md +159 -0
- package/skills/oma-mobile/variants/react-native/api-template.ts +531 -0
- package/skills/oma-mobile/variants/react-native/snippets.md +1014 -0
- package/skills/oma-mobile/variants/react-native/stack.yaml +22 -0
- package/skills/oma-mobile/variants/react-native/tech-stack.md +192 -0
- package/skills/oma-mobile/variants/stack.schema.json +68 -0
- package/skills/oma-mobile/variants/swift-ios/api-template.swift +165 -0
- package/skills/oma-mobile/variants/swift-ios/snippets.md +1028 -0
- package/skills/oma-mobile/variants/swift-ios/stack.yaml +25 -0
- package/skills/oma-mobile/variants/swift-ios/tech-stack.md +174 -0
- package/skills/oma-observability/SKILL.md +225 -0
- package/skills/oma-observability/resources/anti-patterns.md +555 -0
- package/skills/oma-observability/resources/boundaries/cross-application.md +348 -0
- package/skills/oma-observability/resources/boundaries/multi-tenant.md +290 -0
- package/skills/oma-observability/resources/boundaries/release.md +372 -0
- package/skills/oma-observability/resources/boundaries/slo.md +225 -0
- package/skills/oma-observability/resources/checklist.md +123 -0
- package/skills/oma-observability/resources/examples.md +448 -0
- package/skills/oma-observability/resources/execution-protocol.md +166 -0
- package/skills/oma-observability/resources/incident-forensics.md +348 -0
- package/skills/oma-observability/resources/intent-rules.md +307 -0
- package/skills/oma-observability/resources/layers/L3-network.md +281 -0
- package/skills/oma-observability/resources/layers/L4-transport.md +299 -0
- package/skills/oma-observability/resources/layers/L7-application/crash-analytics.md +359 -0
- package/skills/oma-observability/resources/layers/L7-application/mobile-rum.md +278 -0
- package/skills/oma-observability/resources/layers/L7-application/waf.md +246 -0
- package/skills/oma-observability/resources/layers/L7-application/web-rum.md +350 -0
- package/skills/oma-observability/resources/layers/mesh.md +368 -0
- package/skills/oma-observability/resources/matrix.md +177 -0
- package/skills/oma-observability/resources/meta-observability.md +605 -0
- package/skills/oma-observability/resources/observability-as-code.md +666 -0
- package/skills/oma-observability/resources/signals/audit.md +310 -0
- package/skills/oma-observability/resources/signals/cost.md +303 -0
- package/skills/oma-observability/resources/signals/logs.md +263 -0
- package/skills/oma-observability/resources/signals/metrics.md +478 -0
- package/skills/oma-observability/resources/signals/privacy.md +351 -0
- package/skills/oma-observability/resources/signals/profiles.md +245 -0
- package/skills/oma-observability/resources/signals/traces.md +360 -0
- package/skills/oma-observability/resources/standards.md +214 -0
- package/skills/oma-observability/resources/transport/collector-topology.md +308 -0
- package/skills/oma-observability/resources/transport/otlp-grpc-vs-http.md +256 -0
- package/skills/oma-observability/resources/transport/sampling-recipes.md +297 -0
- package/skills/oma-observability/resources/transport/udp-statsd-mtu.md +167 -0
- package/skills/oma-observability/resources/vendor-categories.md +352 -0
- package/skills/oma-orchestration/SKILL.md +302 -0
- package/skills/oma-orchestration/config/cli-config.yaml +92 -0
- package/skills/oma-orchestration/resources/memory-schema.md +232 -0
- package/skills/oma-orchestration/resources/subagent-prompt-template.md +30 -0
- package/skills/oma-orchestration/scripts/parallel-run.sh +6 -0
- package/skills/oma-orchestration/scripts/spawn-agent.sh +5 -0
- package/skills/oma-orchestration/scripts/verify.sh +20 -0
- package/skills/oma-orchestration/templates/backend-task.md +19 -0
- package/skills/oma-orchestration/templates/debug-task.md +16 -0
- package/skills/oma-orchestration/templates/frontend-task.md +18 -0
- package/skills/oma-orchestration/templates/mobile-task.md +18 -0
- package/skills/oma-orchestration/templates/qa-task.md +16 -0
- package/skills/oma-orchestration/templates/tasks-example.yaml +15 -0
- package/skills/oma-pdf/SKILL.md +162 -0
- package/skills/oma-pdf/config/pdf-config.yaml +27 -0
- package/skills/oma-pdf/resources/execution-protocol.md +127 -0
- package/skills/oma-pm/SKILL.md +157 -0
- package/skills/oma-pm/resources/error-playbook.md +75 -0
- package/skills/oma-pm/resources/examples.md +439 -0
- package/skills/oma-pm/resources/execution-protocol.md +62 -0
- package/skills/oma-pm/resources/iso-planning.md +110 -0
- package/skills/oma-pm/resources/plan-phase-protocol.md +66 -0
- package/skills/oma-pm/resources/task-template.json +86 -0
- package/skills/oma-qa/SKILL.md +141 -0
- package/skills/oma-qa/resources/checklist.md +339 -0
- package/skills/oma-qa/resources/error-playbook.md +98 -0
- package/skills/oma-qa/resources/execution-protocol.md +169 -0
- package/skills/oma-qa/resources/iso-quality.md +82 -0
- package/skills/oma-qa/resources/verify-ship-protocol.md +116 -0
- package/skills/oma-recap/SKILL.md +245 -0
- package/skills/oma-recap/resources/output-formats.md +83 -0
- package/skills/oma-refactor/SKILL.md +184 -0
- package/skills/oma-refactor/resources/definition.md +108 -0
- package/skills/oma-refactor/resources/governance.md +33 -0
- package/skills/oma-refactor/resources/hotspots.py +44 -0
- package/skills/oma-refactor/resources/measurement.md +93 -0
- package/skills/oma-scholar/SKILL.md +276 -0
- package/skills/oma-scholar/config/scholar-config.yaml +79 -0
- package/skills/oma-scholar/resources/api-endpoints.md +174 -0
- package/skills/oma-scholar/resources/checklist.md +92 -0
- package/skills/oma-scholar/resources/execution-protocol.md +224 -0
- package/skills/oma-scholar/resources/fallback-providers.md +143 -0
- package/skills/oma-scholar/resources/setup-openalex.md +85 -0
- package/skills/oma-scholar/resources/sidecar-spec.md +341 -0
- package/skills/oma-scholar/resources/upstream-spec-cache.md +972 -0
- package/skills/oma-scm/SKILL.md +103 -0
- package/skills/oma-scm/resources/cm-operations.md +56 -0
- package/skills/oma-scm/resources/codeowners-playbook.md +45 -0
- package/skills/oma-scm/resources/conventional-commits.md +108 -0
- package/skills/oma-scm/resources/merge-risk.md +76 -0
- package/skills/oma-scm/resources/onboarding-risk-signals.md +71 -0
- package/skills/oma-search/SKILL.md +125 -0
- package/skills/oma-search/resources/checklist.md +36 -0
- package/skills/oma-search/resources/error-playbook.md +66 -0
- package/skills/oma-search/resources/examples.md +80 -0
- package/skills/oma-search/resources/execution-protocol.md +86 -0
- package/skills/oma-search/resources/intent-rules.md +47 -0
- package/skills/oma-search/resources/trust-registry.md +53 -0
- package/skills/oma-security/SKILL.md +172 -0
- package/skills/oma-security/resources/artex.md +108 -0
- package/skills/oma-security/resources/ci.md +134 -0
- package/skills/oma-security/resources/cisco-source.md +108 -0
- package/skills/oma-security/resources/deepsec-config.md +45 -0
- package/skills/oma-security/resources/deepsec-matchers.md +35 -0
- package/skills/oma-security/resources/deepsec-scanning.md +45 -0
- package/skills/oma-security/resources/deepsec-setup.md +41 -0
- package/skills/oma-security/resources/findings-contract.md +408 -0
- package/skills/oma-security/resources/mcp-scanning.md +122 -0
- package/skills/oma-security/resources/skill-scanning.md +106 -0
- package/skills/oma-security/resources/validation.md +71 -0
- package/skills/oma-skill-creation/SKILL.md +84 -0
- package/skills/oma-skill-creation/resources/prompt-evaluation.md +36 -0
- package/skills/oma-skill-creation/resources/ssl-lite-template.md +108 -0
- package/skills/oma-skill-creation/resources/validation-checklist.md +101 -0
- package/skills/oma-slide/SKILL.md +277 -0
- package/skills/oma-slide/resources/animation-patterns.md +245 -0
- package/skills/oma-slide/resources/assets/deck-stage.js +514 -0
- package/skills/oma-slide/resources/assets/viewport-base.css +257 -0
- package/skills/oma-slide/resources/canva-integration.md +203 -0
- package/skills/oma-slide/resources/checklist.md +46 -0
- package/skills/oma-slide/resources/design-doctrine.md +260 -0
- package/skills/oma-slide/resources/fixed-stage.md +232 -0
- package/skills/oma-slide/resources/generation-protocol.md +393 -0
- package/skills/oma-slide/resources/native-pptx.md +84 -0
- package/skills/oma-slide/resources/selection-index.json +461 -0
- package/skills/oma-slide/resources/style-presets.LICENSE +10 -0
- package/skills/oma-slide/resources/style-presets.md +520 -0
- package/skills/oma-tf-infra/SKILL.md +201 -0
- package/skills/oma-tf-infra/resources/checklist.md +53 -0
- package/skills/oma-tf-infra/resources/cost-optimization.md +574 -0
- package/skills/oma-tf-infra/resources/error-playbook.md +68 -0
- package/skills/oma-tf-infra/resources/examples.md +38 -0
- package/skills/oma-tf-infra/resources/execution-protocol.md +129 -0
- package/skills/oma-tf-infra/resources/iso-42001-infra.md +229 -0
- package/skills/oma-tf-infra/resources/multi-cloud-examples.md +241 -0
- package/skills/oma-tf-infra/resources/policy-testing-examples.md +332 -0
- package/skills/oma-translation/SKILL.md +229 -0
- package/skills/oma-translation/resources/anti-ai-patterns.md +104 -0
- package/skills/oma-translation/resources/lang/_template.md +73 -0
- package/skills/oma-translation/resources/lang/en.md +123 -0
- package/skills/oma-translation/resources/lang/ja.md +274 -0
- package/skills/oma-translation/resources/lang/ko.md +228 -0
- package/skills/oma-translation/resources/lang/zh.md +285 -0
- package/skills/oma-translation/resources/style-skills.md +104 -0
- package/skills/oma-translation/resources/translation-rubric.md +126 -0
- package/skills/oma-video/SKILL.md +229 -0
- package/skills/oma-video/config/video-config.yaml +60 -0
- package/skills/oma-video/resources/checklist.md +26 -0
- package/skills/oma-video/resources/execution-protocol.md +122 -0
- package/skills/oma-video/resources/existing-media.md +185 -0
- package/skills/oma-video/resources/hyperframes-authoring/README.md +44 -0
- package/skills/oma-video/resources/hyperframes-authoring/demo.md +31 -0
- package/skills/oma-video/resources/hyperframes-authoring/explainer.md +10 -0
- package/skills/oma-video/resources/hyperframes-authoring/shorts.md +10 -0
- package/skills/oma-video/resources/motion-principles.md +81 -0
- package/skills/oma-video/resources/mpt/driver.py +301 -0
- package/skills/oma-video/resources/prompt-tips.md +75 -0
- package/skills/oma-video/resources/script-schema.md +81 -0
- package/skills/oma-video/resources/sound-design.md +127 -0
- package/skills/oma-video/resources/strudel/package.json +11 -0
- package/skills/oma-video/resources/strudel/page.html +87 -0
- package/skills/oma-video/resources/strudel/render.mjs +295 -0
- package/skills/oma-video/resources/vendor-matrix.md +124 -0
- package/skills/oma-voice/SKILL.md +249 -0
- package/skills/oma-voice/config/voice-config.yaml +30 -0
- package/skills/oma-voice/resources/audio-processing.md +119 -0
- package/skills/oma-voice/resources/checklist.md +47 -0
- package/skills/oma-voice/resources/execution-protocol.md +215 -0
- package/skills/oma-voice/resources/prompt-tips.md +43 -0
- package/skills/oma-voice/resources/voice-matrix.md +51 -0
- package/skills/oma-voice/resources/voicestudio.md +87 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
# Cost Optimization Examples
|
|
2
|
+
|
|
3
|
+
Terraform patterns for optimizing cloud infrastructure costs across AWS, GCP, and Azure.
|
|
4
|
+
|
|
5
|
+
## Environment-Based Resource Sizing
|
|
6
|
+
|
|
7
|
+
Dynamically size resources based on environment to reduce non-production costs.
|
|
8
|
+
|
|
9
|
+
```hcl
|
|
10
|
+
# locals.tf
|
|
11
|
+
locals {
|
|
12
|
+
# Instance sizing by environment
|
|
13
|
+
instance_sizes = {
|
|
14
|
+
production = "t3.large"
|
|
15
|
+
staging = "t3.medium"
|
|
16
|
+
development = "t3.micro"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Database sizing by environment
|
|
20
|
+
db_instance_classes = {
|
|
21
|
+
production = "db.r5.xlarge"
|
|
22
|
+
staging = "db.t3.medium"
|
|
23
|
+
development = "db.t3.micro"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Enable HA only in production
|
|
27
|
+
enable_multi_az = var.environment == "production" ? true : false
|
|
28
|
+
enable_backups = var.environment == "production" ? true : false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Compute resource with environment-based sizing
|
|
32
|
+
resource "aws_instance" "app" {
|
|
33
|
+
instance_type = local.instance_sizes[var.environment]
|
|
34
|
+
# ...
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Database with environment-based sizing
|
|
38
|
+
resource "aws_db_instance" "main" {
|
|
39
|
+
instance_class = local.db_instance_classes[var.environment]
|
|
40
|
+
multi_az = local.enable_multi_az
|
|
41
|
+
# ...
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Reserved Instances & Savings Plans
|
|
46
|
+
|
|
47
|
+
### AWS Reserved Instances
|
|
48
|
+
|
|
49
|
+
```hcl
|
|
50
|
+
# Note: Reserved Instances are purchased via Console or API, not Terraform
|
|
51
|
+
# Use tags to track RI-eligible resources
|
|
52
|
+
resource "aws_instance" "app" {
|
|
53
|
+
instance_type = "t3.medium"
|
|
54
|
+
|
|
55
|
+
tags = {
|
|
56
|
+
Name = "app-server"
|
|
57
|
+
RIEligible = "true"
|
|
58
|
+
Environment = "production"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### GCP Committed Use Discounts (CUDs)
|
|
64
|
+
|
|
65
|
+
```hcl
|
|
66
|
+
# Resource-based CUDs can be purchased directly via Terraform.
|
|
67
|
+
# WARNING: commitments are binding contracts — they cannot be updated
|
|
68
|
+
# or deleted once created. Review amounts carefully before apply.
|
|
69
|
+
resource "google_compute_region_commitment" "cud" {
|
|
70
|
+
name = "app-cud"
|
|
71
|
+
region = var.region
|
|
72
|
+
plan = "TWELVE_MONTH" # or THIRTY_SIX_MONTH
|
|
73
|
+
|
|
74
|
+
resources {
|
|
75
|
+
type = "VCPU"
|
|
76
|
+
amount = "4"
|
|
77
|
+
}
|
|
78
|
+
resources {
|
|
79
|
+
type = "MEMORY"
|
|
80
|
+
amount = "16"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Tag commitment-covered resources for cost tracking
|
|
85
|
+
resource "google_compute_instance" "app" {
|
|
86
|
+
machine_type = "n2-standard-4"
|
|
87
|
+
|
|
88
|
+
labels = {
|
|
89
|
+
cud_covered = "true"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Azure Reserved VM Instances
|
|
95
|
+
|
|
96
|
+
```hcl
|
|
97
|
+
# Note: Reserved Instances are purchased separately
|
|
98
|
+
# Tag resources for RI tracking
|
|
99
|
+
resource "azurerm_linux_virtual_machine" "app" {
|
|
100
|
+
size = "Standard_D4s_v3"
|
|
101
|
+
|
|
102
|
+
tags = {
|
|
103
|
+
RIEligible = "true"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Spot/Preemptible Instances
|
|
109
|
+
|
|
110
|
+
For fault-tolerant workloads, use spot instances for up to 90% savings.
|
|
111
|
+
|
|
112
|
+
### AWS Spot Instances
|
|
113
|
+
|
|
114
|
+
```hcl
|
|
115
|
+
resource "aws_launch_template" "spot" {
|
|
116
|
+
name_prefix = "spot-"
|
|
117
|
+
image_id = data.aws_ami.amazon_linux.id
|
|
118
|
+
instance_type = "t3.medium"
|
|
119
|
+
|
|
120
|
+
# Mixed policy controls On-Demand/Spot distribution; omit InstanceMarketOptions.
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
resource "aws_autoscaling_group" "spot" {
|
|
124
|
+
name = "spot-asg"
|
|
125
|
+
vpc_zone_identifier = var.private_subnets
|
|
126
|
+
target_group_arns = [aws_lb_target_group.app.arn]
|
|
127
|
+
health_check_type = "ELB"
|
|
128
|
+
|
|
129
|
+
min_size = 1
|
|
130
|
+
max_size = 10
|
|
131
|
+
desired_capacity = 3
|
|
132
|
+
|
|
133
|
+
# Mixed instances policy for spot diversification
|
|
134
|
+
mixed_instances_policy {
|
|
135
|
+
launch_template {
|
|
136
|
+
launch_template_specification {
|
|
137
|
+
launch_template_id = aws_launch_template.spot.id
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
override {
|
|
141
|
+
instance_type = "t3.medium"
|
|
142
|
+
}
|
|
143
|
+
override {
|
|
144
|
+
instance_type = "t3a.medium"
|
|
145
|
+
}
|
|
146
|
+
override {
|
|
147
|
+
instance_type = "m5.large"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
instances_distribution {
|
|
152
|
+
on_demand_base_capacity = 1
|
|
153
|
+
on_demand_percentage_above_base_capacity = 0
|
|
154
|
+
spot_allocation_strategy = "capacity-optimized"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### GCP Spot VMs
|
|
161
|
+
|
|
162
|
+
```hcl
|
|
163
|
+
# Spot VMs are the recommended successor to preemptible VMs (no 24h limit).
|
|
164
|
+
# `preemptible = true` alone creates a legacy preemptible VM;
|
|
165
|
+
# `provisioning_model = "SPOT"` is what makes it a Spot VM.
|
|
166
|
+
resource "google_compute_instance" "worker" {
|
|
167
|
+
name = "worker"
|
|
168
|
+
machine_type = "n2-standard-4"
|
|
169
|
+
zone = var.zone
|
|
170
|
+
|
|
171
|
+
scheduling {
|
|
172
|
+
preemptible = true
|
|
173
|
+
automatic_restart = false
|
|
174
|
+
provisioning_model = "SPOT"
|
|
175
|
+
instance_termination_action = "STOP"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
# Separate cost lever: start/stop schedule for dev/test VMs (off-hours shutdown)
|
|
180
|
+
resource "google_compute_resource_policy" "business_hours" {
|
|
181
|
+
name = "business-hours-schedule"
|
|
182
|
+
region = var.region
|
|
183
|
+
|
|
184
|
+
instance_schedule_policy {
|
|
185
|
+
vm_start_schedule {
|
|
186
|
+
schedule = "0 8 * * MON-FRI"
|
|
187
|
+
}
|
|
188
|
+
vm_stop_schedule {
|
|
189
|
+
schedule = "0 20 * * MON-FRI"
|
|
190
|
+
}
|
|
191
|
+
time_zone = "America/New_York"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Azure Spot VMs
|
|
197
|
+
|
|
198
|
+
```hcl
|
|
199
|
+
resource "azurerm_linux_virtual_machine" "spot" {
|
|
200
|
+
name = "spot-vm"
|
|
201
|
+
resource_group_name = var.resource_group_name
|
|
202
|
+
location = var.location
|
|
203
|
+
size = "Standard_D4s_v3"
|
|
204
|
+
priority = "Spot"
|
|
205
|
+
eviction_policy = "Deallocate" # or "Delete"
|
|
206
|
+
|
|
207
|
+
# Only create if spot price is acceptable
|
|
208
|
+
max_bid_price = "0.1"
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Autoscaling Schedules
|
|
213
|
+
|
|
214
|
+
Scale down during non-business hours to reduce costs.
|
|
215
|
+
|
|
216
|
+
### AWS Autoscaling Schedule
|
|
217
|
+
|
|
218
|
+
```hcl
|
|
219
|
+
# Scale down in the evening
|
|
220
|
+
resource "aws_autoscaling_schedule" "scale_down_evening" {
|
|
221
|
+
scheduled_action_name = "scale-down-evening"
|
|
222
|
+
min_size = 1
|
|
223
|
+
max_size = 1
|
|
224
|
+
desired_capacity = 1
|
|
225
|
+
recurrence = "0 20 * * MON-THU" # Friday is handled by weekend_shutdown
|
|
226
|
+
autoscaling_group_name = aws_autoscaling_group.app.name
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
# Scale up in the morning
|
|
230
|
+
resource "aws_autoscaling_schedule" "scale_up_morning" {
|
|
231
|
+
scheduled_action_name = "scale-up-morning"
|
|
232
|
+
min_size = 3
|
|
233
|
+
max_size = 10
|
|
234
|
+
desired_capacity = 3
|
|
235
|
+
recurrence = "0 7 * * MON-FRI" # 7 AM weekdays
|
|
236
|
+
autoscaling_group_name = aws_autoscaling_group.app.name
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# Weekend shutdown
|
|
240
|
+
resource "aws_autoscaling_schedule" "weekend_shutdown" {
|
|
241
|
+
scheduled_action_name = "weekend-shutdown"
|
|
242
|
+
min_size = 0
|
|
243
|
+
max_size = 0
|
|
244
|
+
desired_capacity = 0
|
|
245
|
+
recurrence = "0 18 * * FRI" # 6 PM Friday
|
|
246
|
+
autoscaling_group_name = aws_autoscaling_group.app.name
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### GCP Autoscaler Schedules
|
|
251
|
+
|
|
252
|
+
```hcl
|
|
253
|
+
resource "google_compute_autoscaler" "app" {
|
|
254
|
+
name = "app-autoscaler"
|
|
255
|
+
zone = var.zone
|
|
256
|
+
target = google_compute_instance_group_manager.app.id
|
|
257
|
+
|
|
258
|
+
autoscaling_policy {
|
|
259
|
+
min_replicas = 1
|
|
260
|
+
max_replicas = 10
|
|
261
|
+
cooldown_period = 60
|
|
262
|
+
|
|
263
|
+
cpu_utilization {
|
|
264
|
+
target = 0.6
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
scaling_schedules {
|
|
268
|
+
name = "scale-down-evening"
|
|
269
|
+
description = "Scale down in the evening"
|
|
270
|
+
min_required_replicas = 1
|
|
271
|
+
schedule = "0 20 * * 1-5" # 8 PM weekdays
|
|
272
|
+
time_zone = "America/New_York"
|
|
273
|
+
duration_sec = 39600 # 11 hours
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
scaling_schedules {
|
|
277
|
+
name = "scale-up-morning"
|
|
278
|
+
description = "Scale up in the morning"
|
|
279
|
+
min_required_replicas = 3
|
|
280
|
+
schedule = "0 7 * * 1-5" # 7 AM weekdays
|
|
281
|
+
time_zone = "America/New_York"
|
|
282
|
+
duration_sec = 46800 # 13 hours
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Storage Lifecycle Rules
|
|
289
|
+
|
|
290
|
+
Transition data to cheaper storage classes based on age.
|
|
291
|
+
|
|
292
|
+
### AWS S3 Lifecycle Rules
|
|
293
|
+
|
|
294
|
+
```hcl
|
|
295
|
+
resource "aws_s3_bucket_lifecycle_configuration" "data" {
|
|
296
|
+
bucket = aws_s3_bucket.data.id
|
|
297
|
+
|
|
298
|
+
rule {
|
|
299
|
+
id = "transition-to-ia"
|
|
300
|
+
status = "Enabled"
|
|
301
|
+
|
|
302
|
+
filter {
|
|
303
|
+
prefix = "logs/"
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
# Transition to Infrequent Access after 30 days
|
|
307
|
+
transition {
|
|
308
|
+
days = 30
|
|
309
|
+
storage_class = "STANDARD_IA"
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
# Transition to Glacier after 90 days
|
|
313
|
+
transition {
|
|
314
|
+
days = 90
|
|
315
|
+
storage_class = "GLACIER"
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
# Delete after 1 year
|
|
319
|
+
expiration {
|
|
320
|
+
days = 365
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
# Clean up incomplete multipart uploads
|
|
324
|
+
abort_incomplete_multipart_upload {
|
|
325
|
+
days_after_initiation = 7
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
# Rule for temporary data
|
|
330
|
+
rule {
|
|
331
|
+
id = "delete-temp-data"
|
|
332
|
+
status = "Enabled"
|
|
333
|
+
|
|
334
|
+
filter {
|
|
335
|
+
prefix = "temp/"
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
expiration {
|
|
339
|
+
days = 7
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
# Enable Intelligent-Tiering for automatic cost optimization
|
|
345
|
+
resource "aws_s3_bucket_intelligent_tiering_configuration" "data" {
|
|
346
|
+
bucket = aws_s3_bucket.data.id
|
|
347
|
+
name = "EntireBucket"
|
|
348
|
+
|
|
349
|
+
tiering {
|
|
350
|
+
access_tier = "ARCHIVE_ACCESS"
|
|
351
|
+
days = 90
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
tiering {
|
|
355
|
+
access_tier = "DEEP_ARCHIVE_ACCESS"
|
|
356
|
+
days = 180
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### GCP Storage Lifecycle Rules
|
|
362
|
+
|
|
363
|
+
```hcl
|
|
364
|
+
resource "google_storage_bucket" "data" {
|
|
365
|
+
name = "${var.project_id}-data"
|
|
366
|
+
location = var.region
|
|
367
|
+
storage_class = "STANDARD"
|
|
368
|
+
|
|
369
|
+
lifecycle_rule {
|
|
370
|
+
condition {
|
|
371
|
+
age = 30
|
|
372
|
+
}
|
|
373
|
+
action {
|
|
374
|
+
type = "SetStorageClass"
|
|
375
|
+
storage_class = "NEARLINE"
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
lifecycle_rule {
|
|
380
|
+
condition {
|
|
381
|
+
age = 90
|
|
382
|
+
}
|
|
383
|
+
action {
|
|
384
|
+
type = "SetStorageClass"
|
|
385
|
+
storage_class = "COLDLINE"
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
lifecycle_rule {
|
|
390
|
+
condition {
|
|
391
|
+
age = 365
|
|
392
|
+
}
|
|
393
|
+
action {
|
|
394
|
+
type = "Delete"
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Azure Blob Storage Lifecycle
|
|
401
|
+
|
|
402
|
+
```hcl
|
|
403
|
+
resource "azurerm_storage_management_policy" "data" {
|
|
404
|
+
storage_account_id = azurerm_storage_account.data.id
|
|
405
|
+
|
|
406
|
+
rule {
|
|
407
|
+
name = "transition-to-cool"
|
|
408
|
+
enabled = true
|
|
409
|
+
filters {
|
|
410
|
+
prefix_match = ["logs/"]
|
|
411
|
+
blob_types = ["blockBlob"]
|
|
412
|
+
}
|
|
413
|
+
actions {
|
|
414
|
+
base_blob {
|
|
415
|
+
tier_to_cool_after_days_since_modification_greater_than = 30
|
|
416
|
+
tier_to_archive_after_days_since_modification_greater_than = 90
|
|
417
|
+
delete_after_days_since_modification_greater_than = 365
|
|
418
|
+
}
|
|
419
|
+
snapshot {
|
|
420
|
+
delete_after_days_since_creation_greater_than = 30
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## Cost Allocation Tags
|
|
428
|
+
|
|
429
|
+
Tag all resources for cost tracking and chargeback.
|
|
430
|
+
|
|
431
|
+
### AWS Cost Allocation Tags
|
|
432
|
+
|
|
433
|
+
```hcl
|
|
434
|
+
locals {
|
|
435
|
+
common_tags = {
|
|
436
|
+
Environment = var.environment
|
|
437
|
+
Project = var.project_name
|
|
438
|
+
Owner = var.team_email
|
|
439
|
+
CostCenter = var.cost_center
|
|
440
|
+
ManagedBy = "terraform"
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
# Apply tags to all resources
|
|
445
|
+
resource "aws_instance" "app" {
|
|
446
|
+
ami = data.aws_ami.amazon_linux.id
|
|
447
|
+
instance_type = "t3.medium"
|
|
448
|
+
|
|
449
|
+
tags = local.common_tags
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
resource "aws_db_instance" "main" {
|
|
453
|
+
identifier = "${var.project_name}-db"
|
|
454
|
+
instance_class = "db.t3.medium"
|
|
455
|
+
|
|
456
|
+
tags = local.common_tags
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
# Activate cost allocation tags (run once per account)
|
|
460
|
+
resource "aws_ce_cost_allocation_tag" "environment" {
|
|
461
|
+
tag_key = "Environment"
|
|
462
|
+
status = "Active"
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
resource "aws_ce_cost_allocation_tag" "project" {
|
|
466
|
+
tag_key = "Project"
|
|
467
|
+
status = "Active"
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### GCP Labels
|
|
472
|
+
|
|
473
|
+
```hcl
|
|
474
|
+
locals {
|
|
475
|
+
common_labels = {
|
|
476
|
+
environment = var.environment
|
|
477
|
+
project = var.project_name
|
|
478
|
+
owner = var.team_label # validated lowercase label ID, not an email
|
|
479
|
+
cost-center = var.cost_center
|
|
480
|
+
managed-by = "terraform"
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
resource "google_compute_instance" "app" {
|
|
485
|
+
name = "app-server"
|
|
486
|
+
machine_type = "n2-standard-4"
|
|
487
|
+
|
|
488
|
+
labels = local.common_labels
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
# Budget alerts (configure BigQuery billing export separately)
|
|
492
|
+
resource "google_billing_budget" "monthly" {
|
|
493
|
+
billing_account = var.billing_account
|
|
494
|
+
display_name = "Monthly Budget"
|
|
495
|
+
|
|
496
|
+
amount {
|
|
497
|
+
specified_amount {
|
|
498
|
+
currency_code = "USD"
|
|
499
|
+
units = "1000"
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
threshold_rules {
|
|
504
|
+
threshold_percent = 0.5
|
|
505
|
+
}
|
|
506
|
+
threshold_rules {
|
|
507
|
+
threshold_percent = 0.9
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
### Azure Tags
|
|
513
|
+
|
|
514
|
+
```hcl
|
|
515
|
+
locals {
|
|
516
|
+
common_tags = {
|
|
517
|
+
Environment = var.environment
|
|
518
|
+
Project = var.project_name
|
|
519
|
+
Owner = var.team_email
|
|
520
|
+
CostCenter = var.cost_center
|
|
521
|
+
ManagedBy = "terraform"
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
resource "azurerm_linux_virtual_machine" "app" {
|
|
526
|
+
name = "app-vm"
|
|
527
|
+
resource_group_name = var.resource_group_name
|
|
528
|
+
location = var.location
|
|
529
|
+
size = "Standard_D4s_v3"
|
|
530
|
+
|
|
531
|
+
tags = local.common_tags
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
# Cost Management Budget
|
|
535
|
+
resource "azurerm_consumption_budget_resource_group" "monthly" {
|
|
536
|
+
name = "monthly-budget"
|
|
537
|
+
resource_group_id = var.resource_group_id
|
|
538
|
+
amount = 1000
|
|
539
|
+
time_grain = "Monthly"
|
|
540
|
+
|
|
541
|
+
time_period {
|
|
542
|
+
start_date = "2024-01-01T00:00:00Z"
|
|
543
|
+
end_date = "2024-12-31T00:00:00Z"
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
notification {
|
|
547
|
+
enabled = true
|
|
548
|
+
threshold = 90
|
|
549
|
+
operator = "GreaterThan"
|
|
550
|
+
contact_emails = [var.team_email]
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
## Cost Estimation Before Apply
|
|
556
|
+
|
|
557
|
+
Use Infracost to turn `terraform plan` into a monthly cost estimate, locally or as a CI diff comment:
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
infracost breakdown --path . # cost of current config
|
|
561
|
+
infracost diff --path . --compare-to infracost-base.json # cost delta for a change
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
## Best Practices Summary
|
|
565
|
+
|
|
566
|
+
1. **Use environment-based sizing** - Smaller instances for dev/staging
|
|
567
|
+
2. **Reserved capacity for production** - 1-3 year commitments for predictable workloads
|
|
568
|
+
3. **Spot instances for fault-tolerant workloads** - Up to 90% savings
|
|
569
|
+
4. **Scheduled scaling** - Scale down during off-hours
|
|
570
|
+
5. **Storage lifecycle policies** - Automate transitions to cheaper tiers
|
|
571
|
+
6. **Cost allocation tags** - Track and optimize spending
|
|
572
|
+
7. **Right-sizing** - Use the smallest instance that meets performance needs
|
|
573
|
+
8. **Auto-shutdown** - Stop dev/test resources when not in use
|
|
574
|
+
9. **Estimate before apply** - Run Infracost (or provider pricing calculators) on every plan that adds resources
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# TF Infra Agent: Error Recovery Playbook
|
|
2
|
+
|
|
3
|
+
## State Lock Error
|
|
4
|
+
**Symptom:** `Error acquiring the state lock`
|
|
5
|
+
**Recovery:**
|
|
6
|
+
1. Read the lock owner, operation, timestamp and ID from the original lock error.
|
|
7
|
+
2. Confirm the owning local/remote job has stopped; do not assume a missing local process means a remote apply ended.
|
|
8
|
+
3. Only for a confirmed stale lock, use `terraform force-unlock <LOCK_ID>`. This removes a lock; it does not inspect ownership.
|
|
9
|
+
|
|
10
|
+
## Resource Already Exists
|
|
11
|
+
**Symptom:** `Error: already exists` on create
|
|
12
|
+
**Recovery:**
|
|
13
|
+
1. Import the existing resource. On Terraform >= 1.5, prefer a config-driven `import` block (plannable and reviewable):
|
|
14
|
+
```hcl
|
|
15
|
+
import {
|
|
16
|
+
to = aws_s3_bucket.assets
|
|
17
|
+
id = "my-existing-bucket"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
On older versions, use the CLI: `terraform import <resource_type>.<name> <id>`
|
|
21
|
+
2. Verify imported state matches config: `terraform plan`
|
|
22
|
+
3. Adjust config if drift exists
|
|
23
|
+
4. For refactors, use `moved` blocks (rename/move without recreate) and `removed` blocks (TF >= 1.7, drop from state without destroying)
|
|
24
|
+
|
|
25
|
+
## Permission Denied
|
|
26
|
+
**Symptom:** `AccessDenied`, `403 Forbidden`, `insufficient permissions`
|
|
27
|
+
**Recovery:**
|
|
28
|
+
1. Check current identity:
|
|
29
|
+
- AWS: `aws sts get-caller-identity`
|
|
30
|
+
- GCP: `gcloud auth list`
|
|
31
|
+
- Azure: `az account show`
|
|
32
|
+
- OCI: `oci iam region list`
|
|
33
|
+
2. Verify IAM policies attached to the identity
|
|
34
|
+
3. Add missing permissions following least privilege
|
|
35
|
+
|
|
36
|
+
## Provider Version Conflict
|
|
37
|
+
**Symptom:** `Incompatible provider version` or `Could not retrieve the list of available versions`
|
|
38
|
+
**Recovery:**
|
|
39
|
+
1. Update version constraint in `versions.tf`
|
|
40
|
+
2. Run `terraform init -upgrade`
|
|
41
|
+
3. Review changelog for breaking changes
|
|
42
|
+
|
|
43
|
+
## Drift Detected
|
|
44
|
+
**Symptom:** `terraform plan` shows unexpected changes on existing resources
|
|
45
|
+
**Recovery:**
|
|
46
|
+
1. Run `terraform plan -refresh-only` to review drift (the standalone `terraform refresh` command is deprecated — it updates state without confirmation)
|
|
47
|
+
2. If the detected changes are correct, sync state with `terraform apply -refresh-only`
|
|
48
|
+
3. If manual changes exist, decide: import to state or revert manual change
|
|
49
|
+
|
|
50
|
+
## Wrong Provider Configuration
|
|
51
|
+
**Symptom:** Resources targeting wrong region/project/subscription
|
|
52
|
+
**Recovery:**
|
|
53
|
+
1. Check `provider.tf` for region/project/subscription settings
|
|
54
|
+
2. Check `backend.tf` for state configuration
|
|
55
|
+
3. Use provider aliases for multi-region setups
|
|
56
|
+
|
|
57
|
+
## Module Source Error
|
|
58
|
+
**Symptom:** `Module not found` or `Failed to download module`
|
|
59
|
+
**Recovery:**
|
|
60
|
+
1. Check module source path (local) or registry URL (remote)
|
|
61
|
+
2. For git sources, verify access credentials
|
|
62
|
+
3. Run `terraform init` to re-download modules
|
|
63
|
+
|
|
64
|
+
## General Principles
|
|
65
|
+
- After 3 consecutive failures on the same issue, try a fundamentally different approach
|
|
66
|
+
- Check cloud provider status pages for service outages
|
|
67
|
+
- Never modify `terraform.tfstate` manually; use `terraform state mv` / `terraform state rm` for state surgery
|
|
68
|
+
- Always backup state before destructive operations: `terraform state pull > backup.tfstate`
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# TF Infra Agent: Examples
|
|
2
|
+
|
|
3
|
+
## Example 1: GCP Cloud Run Service with Cloud SQL
|
|
4
|
+
|
|
5
|
+
**Input:** "Deploy an API service on Cloud Run and connect it to Cloud SQL PostgreSQL"
|
|
6
|
+
|
|
7
|
+
**Output:**
|
|
8
|
+
- Files created: `compute.tf`, `database.tf`, `networking.tf`, `iam.tf`, `outputs.tf`
|
|
9
|
+
- Cloud provider: GCP (detected from existing `provider "google"`)
|
|
10
|
+
- Resources: Cloud Run service, Cloud SQL PostgreSQL, VPC connector, service account
|
|
11
|
+
- Key decisions:
|
|
12
|
+
- VPC connector for private Cloud SQL access
|
|
13
|
+
- Dedicated service account with minimal permissions
|
|
14
|
+
- Cloud SQL Auth Proxy sidecar for secure connection
|
|
15
|
+
- Environment-based sizing: `db-f1-micro` (dev) vs `db-custom-4-16384` (prod)
|
|
16
|
+
|
|
17
|
+
## Example 2: AWS ECS Fargate with GitHub OIDC
|
|
18
|
+
|
|
19
|
+
**Input:** "Set up OIDC so GitHub Actions can deploy to ECS Fargate"
|
|
20
|
+
|
|
21
|
+
**Output:**
|
|
22
|
+
- Files created: `cicd-auth.tf`, `iam.tf`
|
|
23
|
+
- Cloud provider: AWS (detected from existing `aws_*` resources)
|
|
24
|
+
- Resources: OIDC provider, IAM role with trust policy, ECR/ECS permissions
|
|
25
|
+
- Key decisions:
|
|
26
|
+
- Trust policy scoped to specific repo and branch
|
|
27
|
+
- Permissions limited to ECR push + ECS task update only
|
|
28
|
+
- No long-lived access keys
|
|
29
|
+
|
|
30
|
+
## Example 3: Terraform Plan Review
|
|
31
|
+
|
|
32
|
+
**Input:** "Review this terraform plan output"
|
|
33
|
+
|
|
34
|
+
**Output:**
|
|
35
|
+
- Summary: 3 to add, 1 to change, 1 to destroy
|
|
36
|
+
- Risk: HIGH; `aws_db_instance` will be destroyed and recreated (engine version change)
|
|
37
|
+
- Recommendation: Use `lifecycle { prevent_destroy = true }` or manual migration
|
|
38
|
+
- Checklist: backup verified, maintenance window set, rollback plan documented
|