Skip to main content

Terraform drift intelligence: detect, attribute, score, and fix IaC drift

Project description

๐Ÿ” drifty

Terraform drift intelligence โ€” detect what changed, who changed it, how dangerous it is, and how to fix it.

PyPI version Python CI License: MIT

pip install drifty

The Problem

terraform plan tells you what drifted. It doesn't tell you who changed it, how dangerous the change is, or what to do about it.

Manual changes in the AWS console during incidents, auto-scaling events, and ad-hoc CLI commands silently diverge your infrastructure from your Terraform state. By the time you notice, you don't know if it was a colleague, a runbook, or a security incident.

Enterprise platforms like Spacelift and HCP Terraform Cloud detect drift on a schedule โ€” but they're full IaC platforms that are heavyweight, expensive, and still offer zero attribution or severity intelligence.

drifty fills this exact gap.


Demo

$ drifty scan --workspace ./infra --attribute

๐Ÿ” drifty โ€” Terraform Drift Intelligence
Scanning workspace: ./infra  |  2026-06-05 14:00 UTC

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  3 drifts detected  -   1 Critical  -   1 High  -   1 Low      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ”ด CRITICAL  aws_security_group.main  (sg-0abc1234)
   Changed:  ingress.0.cidr_blocks  โ†’  ["0.0.0.0/0"]  (was: ["10.0.0.0/8"])
   Who:      arn:aws:iam::123456789:user/john.doe
   When:     2026-06-03 14:22:11 UTC
   Action:   ModifySecurityGroupRules
   Fix:      terraform import aws_security_group.main sg-0abc1234

๐ŸŸ  HIGH  aws_instance.api_server  (i-0def5678)
   Changed:  instance_type  โ†’  t3.large  (was: t3.medium)
   Who:      arn:aws:iam::123456789:role/ops-automation
   When:     2026-06-02 09:15:44 UTC
   Action:   ModifyInstanceAttribute
   Fix:      terraform import aws_instance.api_server i-0def5678

๐ŸŸข LOW  aws_s3_bucket.assets  (assets-bucket-prod)
   Changed:  tags.LastModified  โ†’  "2026-06-01"  (was: "2026-05-15")
   Who:      attribution unavailable (event outside 90-day CloudTrail window)
   Fix:      Add tag to Terraform config or run terraform apply to reconcile

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Run `drifty report --format markdown` to export this as a report.

Install

Requirements: Python 3.10+, Terraform 1.1+, AWS credentials configured

pip install drifty

Quick Start

# 1. Initialize config in your Terraform workspace
cd ./infra
drifty init

# 2. Scan for drift
drifty scan

# 3. Scan with CloudTrail attribution (who caused each drift)
drifty scan --attribute

# 4. Filter to critical and high only
drifty scan --severity high

# 5. Output as JSON (for CI/CD piping)
drifty scan --output json | jq '.findings[] | select(.severity=="critical")'

# 6. Export a markdown report
drifty report --format markdown --out ./drift-report.md

# 7. Send drift summary to Slack
drifty config set slack_webhook=https://hooks.slack.com/services/xxx/yyy/zzz
drifty scan --notify slack

# 8. Watch for new drift continuously (poll every 5 minutes)
drifty watch --interval 300 --threshold high --notify slack

# 9. Watch with CloudTrail attribution on every cycle
drifty watch --interval 300 --attribute --notify slack

How It Works

drifty scan
    โ”‚
    โ”œโ”€ 1. runs: terraform plan -refresh-only -json
    โ”‚
    โ”œโ”€ 2. parses JSON Lines output โ†’ extracts resource_drift entries
    โ”‚
    โ”œโ”€ 3. scores each finding (scorer.py)
    โ”‚       critical โ†’ IAM, security groups, S3 policies
    โ”‚       high     โ†’ EC2 instances, RDS, load balancers
    โ”‚       medium   โ†’ Lambda, Auto Scaling, CloudWatch
    โ”‚       low      โ†’ tag-only changes
    โ”‚
    โ”œโ”€ 4. attributes each finding via CloudTrail (if --attribute)
    โ”‚       boto3 โ†’ LookupEvents by resource ID
    โ”‚       returns: IAM principal, timestamp, API action
    โ”‚
    โ””โ”€ 5. renders output
            terminal โ†’ Rich color-coded table
            json     โ†’ structured output for CI/CD
            markdown โ†’ report for Confluence / Notion

Commands

drifty scan

Options:
  --workspace PATH    Terraform directory (default: current dir)
  --profile TEXT      AWS CLI profile (default: "default")
  --attribute         Enable CloudTrail attribution
  --severity TEXT     Minimum severity: critical | high | medium | low
  --output TEXT       Output format: terminal | json | markdown
  --notify TEXT       Send results to: slack

drifty init

Initializes .drifty/config.yaml in the workspace with default settings.

drifty config set KEY=VALUE

drifty config set default_severity=high
drifty config set default_profile=prod
drifty config set slack_webhook=https://hooks.slack.com/...
drifty config set cloudtrail_lookback_days=30

drifty report

drifty report --format markdown --out ./reports/drift-$(date +%F).md
drifty report --format json

drifty scan --notify slack

Sends a Slack Block Kit message when drift is found. Requires a webhook URL configured in .drifty/config.yaml.

# One-time setup
drifty config set slack_webhook=https://hooks.slack.com/services/T.../B.../xxx

# Then just add the flag
drifty scan --notify slack
drifty scan --attribute --notify slack --severity high

The Slack message includes:

  • Severity summary (๐Ÿ”ด Critical / ๐ŸŸ  High / ๐ŸŸก Medium / ๐ŸŸข Low counts)
  • Per-finding blocks with changed attributes, CloudTrail attribution, and remediation hint
  • Capped at 10 findings per message to stay within Slack's block limit

drifty watch

Continuously monitors your Terraform workspace for drift and alerts when new findings appear.

Options:
  --workspace PATH    Terraform directory (default: current dir)
  --interval INT      Polling interval in seconds (default: 300)
  --threshold TEXT    Minimum severity to trigger alert: critical | high | medium | low
  --notify TEXT       Notifier to use when new drift is detected: slack
  --attribute         Enable CloudTrail attribution on each cycle
# Poll every 5 minutes, alert on high+ drift via Slack
drifty watch --interval 300 --threshold high --notify slack --attribute

# Run locally with a fast interval for testing
drifty watch --interval 60 --threshold low

drifty watch tracks state between cycles using a finding hash stored in .drifty/state.json. It only alerts on new drift โ€” findings already seen in the previous cycle are suppressed to avoid repeated noise.


Severity Rules

Resource Type Severity
aws_iam_role_policy, aws_iam_policy ๐Ÿ”ด Critical
aws_security_group, aws_security_group_rule ๐Ÿ”ด Critical
aws_s3_bucket_policy, aws_s3_bucket_public_access_block ๐Ÿ”ด Critical
aws_instance (type/AMI change) ๐ŸŸ  High
aws_rds_instance, aws_lb, aws_alb ๐ŸŸ  High
aws_lambda_function, aws_autoscaling_group ๐ŸŸก Medium
aws_cloudwatch_metric_alarm ๐ŸŸก Medium
aws_instance (tag-only change) ๐ŸŸข Low
aws_s3_bucket (tag-only change) ๐ŸŸข Low

Override any rule per-workspace:

# .drifty/config.yaml
severity_overrides:
  aws_lambda_function: high
  aws_cloudwatch_metric_alarm: low

drifty vs. the Alternatives

Feature terraform plan Spacelift / HCP TF drifty
Detects drift โœ… โœ… โœ…
Who caused it โŒ โŒ โœ… CloudTrail
Severity score โŒ โŒ โœ…
Remediation hint โŒ โŒ โœ…
JSON / Markdown output โŒ partial โœ…
Works locally / in CI โœ… โŒ SaaS only โœ…
Cost free $$$ free
Install N/A platform setup pip install drifty
Slack / webhook alerts โŒ โŒ โœ… v0.2.0
Continuous drift watch โŒ โœ… scheduled โœ… v0.3.0

Configuration Reference

# .drifty/config.yaml
default_profile: default          # AWS CLI profile
default_severity: null            # minimum severity filter (null = show all)
default_output: terminal          # terminal | json | markdown
slack_webhook: null               # Slack incoming webhook URL
cloudtrail_lookback_days: 90      # max 90 (CloudTrail API limit)
severity_overrides: {}            # per-resource type overrides

Roadmap

  • --notify slack โ€” post drift summary to Slack webhook (v0.2.0)
  • drifty watch โ€” continuous drift monitoring (poll on interval)
  • Azure and GCP provider support
  • GitHub PR comment integration
  • Drift history โ€” persist findings to .drifty/history.json
  • drifty ignore โ€” suppress known/accepted drift entries

Contributing

git clone https://github.com/satyajit-dey-17/drifty.git
cd drifty
poetry install
poetry run pytest -v
poetry run ruff check drifty/
poetry run black drifty/

Please open an issue before submitting a large PR. See .github/ISSUE_TEMPLATE/ for bug and feature templates.


License

MIT ยฉ Satyajit Dey

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drifty-0.4.0.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drifty-0.4.0-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file drifty-0.4.0.tar.gz.

File metadata

  • Download URL: drifty-0.4.0.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.1 Darwin/25.5.0

File hashes

Hashes for drifty-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b2c167a7db9e8037cbd339e7e588e4f5d136a56d6b3ed0e71565cf786bb1ff48
MD5 5583cd10af4a3acc82fc19099ff7d661
BLAKE2b-256 e9e5902d1bac49f46abe557522844bf6c5df7f77a9eec5872c2bdc4d4aa58a2a

See more details on using hashes here.

File details

Details for the file drifty-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: drifty-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 33.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.1 Darwin/25.5.0

File hashes

Hashes for drifty-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de6fb86e30d3e2a92091059bf5d328fb44df77692c2779b17cb8de7a906f4f3d
MD5 35392fdadbbd5bb27d22ce24c3501c37
BLAKE2b-256 dbcaee38bb802ff21657a44f28da84277d2c806b49606c48879b1453515246e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page