Logo Infrastructure Drift Detection

Infrastructure Drift Detection

Tổ chức
skillmds
infrastructure-drift-detection

Drift is the divergence between declared infrastructure and live infrastructure.

Tổng quan

Nhà phát hànhskillmds
Kho mãskillmd
Tên kỹ nănginfrastructure-drift-detection
Sao
249
Bản fork
3
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được skillmds công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Infrastructure Drift Detection trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/skillmds/skillmd/tree/main/plugins/cloud-devops/skills/infrastructure-drift-detection
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/skillmds/skillmd.git /tmp/skillmd
mkdir -p .claude/skills
cp -r /tmp/skillmd/plugins/cloud-devops/skills/infrastructure-drift-detection .claude/skills/infrastructure-drift-detection
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Infrastructure Drift Detection trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Infrastructure Drift Detection ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Infrastructure Drift Detection với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Infrastructure Drift Detection (Verbose)

Core Patterns

Where Drift Actually Comes From

Drift is the divergence between declared infrastructure and live infrastructure. Naming its sources matters because they call for different remedies.

SourceExampleRemedy
Emergency console changeSecurity group widened during an incidentRemove standing write access; codify after
Convenience console change"Just bumping the instance size"Same — plus a faster pipeline
Provider defaultsTags, ARNs, or KMS keys injected at createCodify the default, or ignore narrowly
Controllers and autoscalersdesired_count, node group sizeNarrow ignore_changes
Out-of-band automationA Lambda that rotates a ruleBring it into code or exclude explicitly
Manual state surgerystate rm after a botched applyReview process; import rather than remove

The dominant source, by a wide margin, is the first two. Someone with production console access fixes a real problem in ninety seconds and does not come back to write it down — because the incident is over and the fix is working.

What makes this expensive is the delay. The infrastructure is now correct and the code is now wrong, and nothing reports the discrepancy. Weeks later an unrelated pull request adds a tag; the plan includes a quiet ~ line narrowing that security group back to its declared value; the apply reproduces the original outage with no apparent cause. The eventual timeline reconstruction (see incident-timeline-creation) will show a deploy that "changed nothing relevant".

The Detection Mechanism

terraform plan refreshes state against the provider APIs and diffs. The flag that makes it automatable is -detailed-exitcode:

bash
terraform init -input=false
terraform plan -detailed-exitcode -lock-timeout=5m -out=drift.tfplan
Exit codeMeaningJob behaviour
0No changesSuccess, no notification
1Error — credentials, lock contention, API failurePage the platform team
2Changes presentDrift finding: report and route

Collapsing 1 and 2 into "non-zero means drift" is the most common implementation bug: an expired credential then looks identical to a clean run of findings, and a persistently broken job reads as persistent drift until someone stops looking.

One important caveat: a scheduled plan against main reports both true drift and merged-but-unapplied code. Run the check against the ref that is actually deployed — tag it on apply and check out that tag — or you will spend your first month triaging your own backlog.

For a read-only check without producing a plan artifact, newer Terraform supports terraform plan -refresh-only -detailed-exitcode, which reports only changes the provider made outside Terraform and excludes changes originating in your code. That is usually the more precise drift signal.

Scheduling

Drift detection belongs on a timer, not in the deploy pipeline. Checking at deploy time is checking at the moment it is most expensive to act: the finding lands in front of an engineer who is trying to ship something unrelated, mixed into a plan they are about to approve.

yaml
name: drift-detection
on:
  schedule:
    - cron: "0 */6 * * *"
  workflow_dispatch: {}

permissions:
  id-token: write
  contents: read

jobs:
  detect:
    strategy:
      fail-fast: false
      matrix:
        stack: [network, data, platform, apps]
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ env.DEPLOYED_REF }}
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::111122223333:role/tf-drift-readonly
          aws-region: us-east-1
      - run: terraform -chdir=infra/${{ matrix.stack }}/prod init -input=false
      - id: plan
        continue-on-error: true
        run: |
          terraform -chdir=infra/${{ matrix.stack }}/prod \
            plan -refresh-only -detailed-exitcode -lock-timeout=5m -out=drift.tfplan
      - if: steps.plan.outcome == 'failure' && steps.plan.conclusion != 'success'
        run: ./scripts/report-drift.sh infra/${{ matrix.stack }}/prod/drift.tfplan

Cadence guidance:

EnvironmentIntervalRationale
Regulated / PCI / HIPAAHourlyEvidence requirement; short unauthorized-change window
Production4–6 hoursCatches same-day drift while the context is fresh
StagingDailyLower stakes, still worth trending
EphemeralNeverRebuilt from code anyway

Two hard rules for the scheduled job:

Read-only credentials. The role should hold Describe*/Get*/List* and nothing else. This is not merely defence in depth — it makes the next rule structurally impossible to violate.

Never auto-apply. An auto-remediating drift job reverts the mitigation an on-call engineer put in place, unattended, in the middle of the night, with no human in the loop. The correct output of a drift job is a notification.

Reporting

Raw plan output is unreadable at 200 lines. Parse the JSON:

bash
terraform show -json drift.tfplan | jq -r '
  .resource_changes[]
  | select(.change.actions | inside(["no-op"]) | not)
  | "\(.change.actions | join(",")) \(.address)"
'

For attribute-level detail:

bash
terraform show -json drift.tfplan | jq -r '
  .resource_changes[]
  | select(.change.actions[0] == "update")
  | .address as $a
  | .change.before as $b
  | .change.after  as $x
  | ($b | keys[]) as $k
  | select($b[$k] != $x[$k])
  | "\($a).\($k): \($b[$k]) -> \($x[$k])"
'

A good report answers three questions: which resource, which attribute, and who changed it. The third comes from the audit log, not from Terraform:

bash
aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=ResourceName,AttributeValue=sg-0abc123 \
  --start-time "$(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ)" \
  --query 'Events[].[EventTime,Username,EventName]' --output table

Route by owning team using resource tags. A shared #infra-alerts channel that receives every finding for every stack is a channel people mute within a fortnight.

Triage: Codify, Revert, or Ignore

Every finding resolves to exactly one of three outcomes, and leaving it unresolved is what makes drift chronic.

Codify when the manual change was correct. Write it into the module, open a PR, let the plan confirm it produces no diff, apply. This is the common case for incident mitigations, and it is the step teams skip.

Revert when the change was unauthorized or accidental. Apply the declared configuration — after confirming with the owning team that nothing depends on the live value. Then ask how the write happened; an unexplained production change is a security finding, not just a hygiene one.

Ignore when the attribute is legitimately owned by something else:

hcl
resource "aws_ecs_service" "api" {
  # ...
  lifecycle {
    ignore_changes = [
      desired_count,                 # managed by application autoscaling
      task_definition,               # managed by the deploy pipeline
    ]
  }
}

Name the attributes. ignore_changes = all converts the resource into a permanent blind spot — it will never report drift again, including a security group opened to the internet.

Complementary Controls

Terraform plan sees only what Terraform manages. Two gaps need separate coverage:

Unmanaged resources. Anything created outside code is invisible to plan entirely. Cloud-native config tooling — AWS Config rules, Azure Policy, GCP Organization Policy — evaluates every resource regardless of provenance, and is the right place for absolute rules like "no security group allows 0.0.0.0/0 on 22".

Preventive guardrails. Service control policies and IAM boundaries that deny the mutating action outright beat detecting it afterwards. Drift detection is a backstop for what the guardrails allow through.

Track findings over time. A resource that drifts on the same attribute every week is telling you the code is wrong, or the team's real workflow does not route through the pipeline. That is a process defect — feed it into the improvement loop (see continuous-improvement), because remediating it individually forever is not a solution.

Common Anti-Patterns

❌ Detecting drift only during a deploy — the finding arrives when it is most disruptive and least likely to be triaged properly. ✅ Scheduled detection every few hours, decoupled from releases.

❌ Treating exit codes 1 and 2 as the same — an expired credential is indistinguishable from clean findings, and a broken job looks like a busy one. ✅ Branch on the exit code: 1 pages, 2 reports.

❌ Auto-applying to "self-heal" — unattended reversion of an on-call engineer's mitigation, usually reproducing the original incident. ✅ Report only; humans decide codify, revert, or ignore. Read-only credentials make this enforceable.

❌ ignore_changes = all — silences the alarm rather than fixing the noise, including for changes that matter. ✅ Ignore specific attributes, with a comment naming what owns them.

❌ Planning against main and calling unapplied code "drift" — floods the report with your own pending changes. ✅ Check against the deployed ref, or use -refresh-only to isolate external changes.

❌ Standing production console write access for the whole team — this is the drift source; detection alone cannot outrun it. ✅ Read-only by default, time-boxed break-glass that alerts on assumption.

❌ Findings that are noted and forgotten — the same drift reappears every scheduled run and everyone learns to ignore the report. ✅ Every finding gets an owner and a resolution: codified, reverted, or ignored with justification.

❌ Assuming plan covers everything — resources created outside Terraform never appear in a plan at all. ✅ Pair with AWS Config / Azure Policy / GCP Org Policy for provenance-independent evaluation.

Drift Detection Checklist

  • Scheduled drift job on production, every 4–6 hours or better
  • Job runs against the deployed ref, not the tip of main
  • -detailed-exitcode used, with 1 and 2 handled differently
  • -refresh-only used where the goal is external-change detection
  • Detection role is strictly read-only
  • Job never applies
  • Findings parsed to resource and attribute level, not raw plan text
  • Reports routed to owning teams by tag
  • Audit log correlation identifies who made each change
  • Every finding closed as codify / revert / ignore-with-reason
  • ignore_changes scoped to named attributes; no all
  • Humans have no standing production write access
  • Cloud-native policy evaluation covers unmanaged resources
  • Recurring drift on the same resource escalated as a process defect

Câu hỏi thường gặp

Kỹ năng AI Infrastructure Drift Detection làm được gì?

Drift is the divergence between declared infrastructure and live infrastructure.

Vì sao nên dùng Infrastructure Drift Detection trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Infrastructure Drift Detection là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Infrastructure Drift Detection trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/skillmds/skillmd/tree/main/plugins/cloud-devops/skills/infrastructure-drift-detection. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Infrastructure Drift Detection?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Infrastructure Drift Detection với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Infrastructure Drift Detection với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Infrastructure Drift Detection có miễn phí không?

Có. Kỹ năng này được skillmds phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇