Skip to main content

DriftWatch 🛡️

DriftWatch is a production-ready CLI tool and automation engine that detects Terraform infrastructure drift against live AWS environments, explains the security and reliability impact using AI, and safely guides remediation.


🚀 Key Features

  • Multi-Resource Drift Detection: Continuously monitors and compares EC2 instances, S3 buckets, Security Groups, RDS databases, Lambda functions, and IAM roles against your Terraform state.
  • Data-Driven Severity Scoring: Evaluates changes dynamically at the attribute level (e.g. security group open ports vs description updates) to classify drifts as CRITICAL, HIGH, MEDIUM, or LOW.
  • AI-Powered Risk Summaries: Integrates with LLMs to provide plain-English security analysis and compliance impact assessments.
  • Deterministic IaC Remediation: Recommends safe, template-generated terraform import and terraform apply commands rather than hallucinated AI outputs.
  • Guarded Auto-Remediation: Pre-flight validation checks for EC2 (EBS verification, Spot skip, running state), RDS maintenance-window defaults, and explicit interactive confirmations.
  • Multi-Channel Alerting: Instant notifications via Telegram, Slack, and Email.
  • CI/CD Quality Gate: Built-in GitHub Actions integration to enforce zero-tolerance drift policies in pull requests.

🏛️ Architecture Overview

driftwatch/
├── drift_engine/              # Core drift detection & reconciliation engine
│   ├── aws_client.py         # Live AWS resource discovery (boto3)
│   ├── core.py               # Diff evaluation & data-driven severity engine
│   ├── database.py           # PostgreSQL scan history recorder
│   ├── explain.py            # AI risk summaries & deterministic IaC templates
│   ├── models.py             # Data models & attribute severity tables
│   ├── notifications.py      # Alert dispatcher (Telegram, Slack, Email)
│   ├── remediation.py        # Guarded auto-remediation handlers
│   └── tf_parser.py          # Terraform state JSON parser
├── driftwatch/               # CLI Entrypoint (Typer)
│   └── cli.py                # Command definitions: scan, explain, remediate
├── terraform/                # Example infrastructure and state configuration
├── kubernetes/               # Kubernetes CronJob deployment
└── tests/                    # Comprehensive unit tests with moto AWS mocks

📋 Prerequisites

  • Python: >= 3.10
  • AWS Credentials: Configured via environment variables, IAM roles, or AWS CLI credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION).
  • Terraform State File: Local JSON state or remote state (terraform.tfstate).
  • PostgreSQL (Optional): For persistent scan audit history.
  • Groq API Key (Optional): GROQ_API_KEY for AI risk explanations.

📦 Installation

From Source (Local Development)

git clone https://github.com/hastagnitin/driftwatch.git
cd driftwatch
pip install -e .[dev]

⚙️ Configuration

Create a .env file in the root directory:

AWS_DEFAULT_REGION=ap-south-1
TF_STATE_PATH=terraform/terraform.tfstate

# Optional: AI Risk Summaries
GROQ_API_KEY=your_groq_api_key

# Optional: Notifications
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_telegram_chat_id

# Optional: PostgreSQL Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=driftwatch
DB_USER=postgres
DB_PASSWORD=your_db_password

💻 Usage & CLI Commands

1. Scan for Drift

Scan live AWS infrastructure against your Terraform state:

# Basic scan
driftwatch scan --region ap-south-1 --state terraform/terraform.tfstate

# Enforce CI Gate (fails build if CRITICAL drift is found)
driftwatch scan --region ap-south-1 --fail-on CRITICAL

2. Explain Drift

Generate AI risk analysis and deterministic IaC fix recommendations:

driftwatch explain sg-0123456789abcdef0 --region ap-south-1

3. Remediate Drift

Safely remediate drifted resources back to IaC specifications:

# Dry run mode (default)
driftwatch remediate sg-0123456789abcdef0 --region ap-south-1 --dry-run

# Apply mode with interactive confirmation
driftwatch remediate sg-0123456789abcdef0 --region ap-south-1 --apply

⚠️ Security & Safety Guidelines

[!WARNING] Auto-Remediation Safety:

  • Automated drift remediation is intended for Development and Staging environments.
  • In Production, DriftWatch enforces manual confirmation prompts (confirm_action()) and recommends template-generated terraform apply / terraform import workflows.
  • RDS modifications default to maintenance windows (ApplyImmediately=False) to avoid unplanned reboots.

🧪 Testing

Run the test suite with test coverage:

pytest tests/ -v --cov=drift_engine --cov=driftwatch --cov-report=term-missing

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Download files

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

Source Distribution

driftwatch_cli-0.1.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

driftwatch_cli-0.1.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file driftwatch_cli-0.1.0.tar.gz.

File metadata

  • Download URL: driftwatch_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for driftwatch_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83ac5c0a7cf9f2fc45ec624c3bce4441e07259da16b90086986fb6aece4c30d1
MD5 093faa163a2b6f51ae950a5472da46f9
BLAKE2b-256 58ff3f0888ab7a3ffb06e6a4a6f3b250590d0b398dfb558ce7398d754692e0ec

See more details on using hashes here.

File details

Details for the file driftwatch_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: driftwatch_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for driftwatch_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5158436a3c924a414c248713e64c217f7a8e6425d1c1c22d26118b340b2e6fa3
MD5 194f95e45206b4f212c1c73bbfe0c03a
BLAKE2b-256 c081368e7cf876168023bcf87a4a7f44166c5b3eaed315ed32f651997b47c6ba

See more details on using hashes here.

Release history Release notifications | RSS feed

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

This release

0.1.0 This release

2 files

Supported by

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