IaC Review
Ortak Doktrin
agents/shared/severity-rubric.md ve agents/shared/escalation-matrix.md default-load
sayılır (agents/coordination.md §11). Bu skill'in çıktısı Critical / High / Medium /
Low + kanıt formatında olmak zorunda — spekülatif Critical yasak. Sahiplik dışı bulgu
ilgili agent'a delege; karar yetkisi eşiği aşılırsa kullanıcı onayı zorunlu.
Ne Zaman Kullanılır
- IaC PR review (yeni resource / değişiklik)
- Yeni module yazımı
- State migration planı
- Drift detection alarm
- Security scan bulgu inceleme (tfsec/checkov)
- Multi-env refactor
- Cost engineering
Workflow
1) Tool tespit
| Tool |
İşaret |
| Terraform |
*.tf, terraform.tfstate*, .terraform.lock.hcl |
| Pulumi |
Pulumi.yaml, Pulumi.<stack>.yaml |
| CloudFormation |
*.yaml/*.json AWSTemplateFormatVersion |
| Ansible |
playbook.yml, inventory/, roles/ |
| AWS CDK |
cdk.json, bin/, lib/*.ts |
2) State management review
- Remote backend mu? Local state fail.
- Locking (DynamoDB / GCS object lock).
- Encryption at rest (KMS / SSE-S3).
- Versioning açık (state geri alma için).
- Per-env ayrı state (dev/staging/prod karışmıyor).
- Workspace vs directory — directory tercih (clarity).
3) Module contract review
variables.tf input + outputs.tf output explicit.
versions.tf Terraform + provider versiyonu pin.
variable validation block (tip + range + regex).
default değer verilirken comment.
- Module source
?ref=v1.2.0 semver pin (mutable ref yasak).
4) Plan output review
PR description'da terraform plan zorunlu:
Plan: 3 to add, 1 to change, 0 to destroy.
to destroy > 0 → highlight + 2-person review.
prevent_destroy = false ihlali → block.
- Sensitive resource (DB, KMS, prod K8s) → ek onay.
- Provider/region değişimi → state migration ayrı PR.
5) Resource hijyeni
- Naming:
<env>-<service>-<purpose> convention.
- Tag/label zorunlu: Environment, Service, ManagedBy, Owner, CostCenter.
- Lifecycle:
prevent_destroy = true DB/KMS/VPC.
create_before_destroy = true zero-downtime.
ignore_changes minimum (drift kaynağı).
for_each > count (stable address).
- Provider alias multi-region explicit.
6) Secret review
- State'te plaintext:
random_password, local_file → state encryption şart.
*.tfvars Git'te: terraform.tfvars .gitignore'da olmalı; sample
terraform.tfvars.example OK.
TF_VAR_* ENV preferred runtime için.
- Vault provider secret reference; plaintext yok.
- CI'da OIDC federation (AWS / GCP); long-lived access key yok.
7) Security scan
| Tool |
Kapsam |
| tfsec |
TF-specific, hızlı, CIS/HIPAA/PCI rule set |
| checkov |
Multi-IaC, geniş policy (1k+ check) |
| kics |
Multi-IaC, KICS query language |
| OPA + Conftest |
Custom policy (organization-specific) |
| Sentinel |
TF Cloud paid, policy-as-code |
Severity threshold:
- Critical → block PR (örn. public S3 bucket, security group
0.0.0.0/0 to all ports).
- High → review + plan eklenir.
- Medium → ticket, follow-up.
8) Drift detection
terraform plan cron (haftalık) — drift varsa alert.
- AWS Config / GCP Asset Inventory — gerçek state karşılaştırma.
- Drift sebepleri:
- Console click (insan).
- Auto-scaling / managed service değişimi (beklenen).
- 3rd party tool (Crossplane, Operator).
- Reconcile: state'e adapte (
terraform import / state mv) veya
config'e ekle (ignore_changes precise).
9) Cost diff (Infracost)
- PR comment:
Δ cost / month.
> $100/ay artış → review + justification.
- Idle resource detection (gauge unused).
10) Module test
- terratest (Go) — apply + assert + destroy.
terraform test (1.6+) — declarative.
- Kitchen-terraform (Ruby).
- Ayrı test AWS account / GCP project — prod'a bulaşma yok.
Checklist
Antipattern
- Local state.
master/main ref module source.
-auto-approve rutin.
- State manuel
rm/mv review'sız.
- Cross-env tek state.
*.tfvars secret Git'te.
count = enabled ? 1 : 0 boolean toggle.
provisioner "local-exec" rutin.
null_resource + local-exec state-driven olmayan.
ignore_changes = all.
-target apply rutin.
- Console click prod'da.
- Module versiyon
latest prod'da.
- Plan output review yok.
Örnek Agent Davranışı
User: /iac-review terraform/envs/prod/
Agent (iac-engineer):
1. Tool tespit: Terraform 1.6.4, AWS provider 5.x.
2. State: S3 backend + DynamoDB lock ✓; encryption KMS ✓; versioning ✓.
3. Module contract: 3 modül; `vpc` `master` ref kullanıyor (Critical, mutable).
4. Plan output:
- Plan: 7 to add, 2 to change, 1 to destroy.
- destroy: aws_db_instance.legacy → `prevent_destroy = false` (Critical).
5. Tag eksik: 4 resource'ta `CostCenter` yok (Medium).
6. Secret: `terraform.tfvars` `.gitignore`'da var ✓; `TF_VAR_DB_PASSWORD` CI ENV.
7. Security: tfsec 3 finding (1 High public S3 ACL, 2 Medium SG egress).
8. Cost: Infracost +$340/ay → RDS instance class büyütüldü.
9. Output:
- Critical: vpc module ref pin + DB prevent_destroy + S3 ACL
- High: SG egress
- Medium: tag eksik 4 resource
- 8 issue açıldı (sahip + tarih).
Çıktı Formatı
# IaC Review: <path>
## State / Backend
- Remote, locking, encryption, versioning, per-env
## Module Contract
- variables / outputs / versions / source pin
## Plan Output
```text
Plan: ... to add, ... to change, ... to destroy
Critical / High / Medium / Low
Security Scan
- tfsec / checkov / OPA özet
Cost Diff (Infracost)
Action Items
| Öncelik | Aksiyon | Sahip | Bitiş | Issue |
1---2name: iac-review3description: Terraform / Pulumi / CloudFormation review — state management, module contract, plan output, drift detection, security scan (tfsec/checkov/OPA), cost diff (Infracost). Plan ≠ apply disiplini.4metadata:5 source: https://skillmd.com/skills/aibot88/iac-review6---78# IaC Review910## Ortak Doktrin1112`agents/shared/severity-rubric.md` ve `agents/shared/escalation-matrix.md` default-load13sayılır (`agents/coordination.md` §11). Bu skill'in çıktısı **Critical / High / Medium /14Low + kanıt** formatında olmak zorunda — spekülatif Critical yasak. Sahiplik dışı bulgu15ilgili agent'a delege; karar yetkisi eşiği aşılırsa **kullanıcı onayı zorunlu**.1617## Ne Zaman Kullanılır18- IaC PR review (yeni resource / değişiklik)19- Yeni module yazımı20- State migration planı21- Drift detection alarm22- Security scan bulgu inceleme (tfsec/checkov)23- Multi-env refactor24- Cost engineering2526## Workflow2728### 1) Tool tespit29| Tool | İşaret |30|---|---|31| Terraform | `*.tf`, `terraform.tfstate*`, `.terraform.lock.hcl` |32| Pulumi | `Pulumi.yaml`, `Pulumi.<stack>.yaml` |33| CloudFormation | `*.yaml`/`*.json` `AWSTemplateFormatVersion` |34| Ansible | `playbook.yml`, `inventory/`, `roles/` |35| AWS CDK | `cdk.json`, `bin/`, `lib/*.ts` |3637### 2) State management review38- **Remote backend** mu? Local state **fail**.39- **Locking** (DynamoDB / GCS object lock).40- **Encryption at rest** (KMS / SSE-S3).41- **Versioning** açık (state geri alma için).42- **Per-env ayrı state** (dev/staging/prod karışmıyor).43- **Workspace vs directory** — directory tercih (clarity).4445### 3) Module contract review46- `variables.tf` input + `outputs.tf` output explicit.47- `versions.tf` Terraform + provider versiyonu pin.48- `variable` validation block (tip + range + regex).49- `default` değer verilirken comment.50- Module source `?ref=v1.2.0` semver pin (mutable ref yasak).5152### 4) Plan output review53PR description'da `terraform plan` zorunlu:54```text55Plan: 3 to add, 1 to change, 0 to destroy.56```5758- **`to destroy > 0`** → highlight + 2-person review.59- **`prevent_destroy = false` ihlali** → block.60- **Sensitive resource** (DB, KMS, prod K8s) → ek onay.61- **Provider/region değişimi** → state migration ayrı PR.6263### 5) Resource hijyeni64- **Naming**: `<env>-<service>-<purpose>` convention.65- **Tag/label** zorunlu: Environment, Service, ManagedBy, Owner, CostCenter.66- **Lifecycle**:67 - `prevent_destroy = true` DB/KMS/VPC.68 - `create_before_destroy = true` zero-downtime.69 - `ignore_changes` minimum (drift kaynağı).70- **`for_each` > `count`** (stable address).71- **Provider alias** multi-region explicit.7273### 6) Secret review74- **State'te plaintext**: `random_password`, `local_file` → state encryption şart.75- **`*.tfvars` Git'te**: `terraform.tfvars` `.gitignore`'da olmalı; sample76 `terraform.tfvars.example` OK.77- **`TF_VAR_*`** ENV preferred runtime için.78- **Vault provider** secret reference; plaintext yok.79- **CI'da OIDC federation** (AWS / GCP); long-lived access key yok.8081### 7) Security scan82| Tool | Kapsam |83|---|---|84| **tfsec** | TF-specific, hızlı, CIS/HIPAA/PCI rule set |85| **checkov** | Multi-IaC, geniş policy (1k+ check) |86| **kics** | Multi-IaC, KICS query language |87| **OPA + Conftest** | Custom policy (organization-specific) |88| **Sentinel** | TF Cloud paid, policy-as-code |8990Severity threshold:91- **Critical** → block PR (örn. public S3 bucket, security group `0.0.0.0/0` to all ports).92- **High** → review + plan eklenir.93- **Medium** → ticket, follow-up.9495### 8) Drift detection96- **`terraform plan` cron** (haftalık) — drift varsa alert.97- **AWS Config / GCP Asset Inventory** — gerçek state karşılaştırma.98- **Drift sebepleri**:99 - Console click (insan).100 - Auto-scaling / managed service değişimi (beklenen).101 - 3rd party tool (Crossplane, Operator).102- **Reconcile**: state'e adapte (`terraform import` / `state mv`) veya103 config'e ekle (`ignore_changes` precise).104105### 9) Cost diff (Infracost)106- PR comment: `Δ cost / month`.107- `> $100/ay` artış → review + justification.108- Idle resource detection (gauge unused).109110### 10) Module test111- **terratest** (Go) — apply + assert + destroy.112- **`terraform test`** (1.6+) — declarative.113- **Kitchen-terraform** (Ruby).114- Ayrı test AWS account / GCP project — prod'a bulaşma yok.115116## Checklist117- [ ] Remote backend + locking + encryption + versioning118- [ ] Per-env ayrı state119- [ ] Module contract (variables/outputs/versions)120- [ ] Module source semver pin (`?ref=v1.2.0`)121- [ ] Plan output PR'a yapışık122- [ ] `to destroy` highlight + onay123- [ ] Tag/label zorunlu124- [ ] `prevent_destroy` kritik resource'larda125- [ ] Secret state encryption + tfvars Git dışı126- [ ] tfsec/checkov clean (Critical=0)127- [ ] OPA/Conftest custom policy (varsa)128- [ ] Cost diff (Infracost) PR'a yapışık129- [ ] Drift detection cron aktif130- [ ] Module test (terratest / terraform test)131132## Antipattern133- **Local state**.134- **`master`/`main` ref** module source.135- **`-auto-approve`** rutin.136- **State manuel `rm`/`mv`** review'sız.137- **Cross-env tek state**.138- **`*.tfvars` secret** Git'te.139- **`count = enabled ? 1 : 0`** boolean toggle.140- **`provisioner "local-exec"`** rutin.141- **`null_resource + local-exec`** state-driven olmayan.142- **`ignore_changes = all`**.143- **`-target`** apply rutin.144- **Console click** prod'da.145- **Module versiyon `latest`** prod'da.146- **Plan output review yok**.147148## Örnek Agent Davranışı149```150User: /iac-review terraform/envs/prod/151Agent (iac-engineer):1521. Tool tespit: Terraform 1.6.4, AWS provider 5.x.1532. State: S3 backend + DynamoDB lock ✓; encryption KMS ✓; versioning ✓.1543. Module contract: 3 modül; `vpc` `master` ref kullanıyor (Critical, mutable).1554. Plan output:156 - Plan: 7 to add, 2 to change, 1 to destroy.157 - destroy: aws_db_instance.legacy → `prevent_destroy = false` (Critical).1585. Tag eksik: 4 resource'ta `CostCenter` yok (Medium).1596. Secret: `terraform.tfvars` `.gitignore`'da var ✓; `TF_VAR_DB_PASSWORD` CI ENV.1607. Security: tfsec 3 finding (1 High public S3 ACL, 2 Medium SG egress).1618. Cost: Infracost +$340/ay → RDS instance class büyütüldü.1629. Output:163 - Critical: vpc module ref pin + DB prevent_destroy + S3 ACL164 - High: SG egress165 - Medium: tag eksik 4 resource166 - 8 issue açıldı (sahip + tarih).167```168169## Çıktı Formatı170```markdown171# IaC Review: <path>172173## State / Backend174- Remote, locking, encryption, versioning, per-env175176## Module Contract177- variables / outputs / versions / source pin178179## Plan Output180```text181Plan: ... to add, ... to change, ... to destroy182```183184## Critical / High / Medium / Low185186## Security Scan187- tfsec / checkov / OPA özet188189## Cost Diff (Infracost)190- Δ $/ay191192## Action Items193| Öncelik | Aksiyon | Sahip | Bitiş | Issue |194```