lgbarn/devops-skills

terraform-drift-detection

Use when detecting infrastructure drift between Terraform state and actual AWS resources.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/lgbarn/devops-skills --skill terraform-drift-detection

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

Terraform Drift Detection

Overview

Detect and categorize drift between Terraform-managed state and actual infrastructure. Drift indicates out-of-band changes that can cause problems during the next apply.

Announce at start: "I'm using the terraform-drift-detection skill to check for infrastructure drift."

The Process

Step 1: Verify Environment

bash
# Verify AWS credentials and account
aws sts get-caller-identity

# Confirm we're in the right directory/environment
pwd
ls -la *.tf 2>/dev/null | head -5

Step 2: Refresh State

bash
# Initialize if needed
terraform init

# Refresh state to detect drift
terraform plan -refresh-only -out=drift.out

# Convert to JSON for analysis
terraform show -json drift.out > drift.json

Step 3: Analyze Drift

Parse drift.json and categorize changes:

Drift Categories

CategorySeverityExamples
Security DriftCRITICALSecurity groups, IAM, encryption
Configuration DriftHIGHInstance settings, networking
Tag DriftLOWTags modified outside Terraform
Metadata DriftINFOAWS-managed fields that change

Step 4: Dispatch Analysis Agent

Task(drift-detector) → Categorize and assess drift impact

Agent should:

  • Categorize each drifted resource
  • Assess impact of accepting vs rejecting drift
  • Identify potential causes (manual changes, AWS updates, etc.)

Step 5: Present Findings

markdown
## Drift Detection Report

### Summary
- Total drifted resources: X
- Critical drift: Y
- High drift: Z
- Low/Info drift: W

### Critical Drift (Requires Immediate Attention)
| Resource | Attribute | State Value | Actual Value |
|----------|-----------|-------------|--------------|
| ... | ... | ... | ... |

### Potential Causes
- Manual console changes: [list if detected]
- AWS service updates: [list if detected]
- Unknown origin: [list if detected]

### Recommended Actions
1. [Action for each drifted resource]

Step 6: Resolution Options

Present user with options:

  1. Accept Drift: Run terraform apply -refresh-only to update state to match actual
  2. Reject Drift: Run terraform apply to revert actual infrastructure to match code
  3. Investigate: Manual review needed before deciding
  4. Hybrid: Accept some drift, reject other drift

Never auto-resolve drift. Always get user approval.

Common Drift Sources

Intentional (Usually Accept)

  • AWS auto-scaling adjustments
  • Managed service updates
  • Emergency manual fixes (document these!)

Unintentional (Usually Reject)

  • Console click-ops mistakes
  • Unapproved manual changes
  • Conflicting automation

Systemic (Fix Root Cause)

  • Multiple tools managing same resources
  • Missing Terraform coverage
  • CI/CD race conditions

Integration with Memory

Store detected drift patterns:

  • Which resources commonly drift
  • Common causes in this environment
  • Resolution preferences

Query memory before analysis:

  • Has this resource drifted before?
  • What was the cause last time?
  • What resolution was chosen?

Verification Checklist

Before presenting:

  • [ ] Refresh completed successfully
  • [ ] All drift categorized by severity
  • [ ] Root causes identified where possible
  • [ ] Resolution options are clear
  • [ ] No sensitive values exposed in output

관련 작업

같은 저장소의 Skills

더 많은 Skills

모든 Skills