A CLI tool to detect drift in Terraform-managed infrastructure
Project description
Terraform Drift Detector
A Python CLI tool to detect and report drift between your Terraform configuration and the actual infrastructure state.
Overview
Infrastructure drift occurs when your actual cloud resources deviate from what's defined in your Terraform files. This tool helps you detect such drift by running terraform plan across your infrastructure and analyzing the results.
Features
- Scan single or multiple Terraform directories for drift
- Parallel processing for faster scanning of large infrastructure
- Detailed reporting of resources that will be added, changed, or destroyed
- Color-coded output for better readability
- Option to export results to JSON for further processing or integration
Installation
- Clone this repository or download the files
- Install the required dependencies:
pip install -r requirements.txt
- Make the script executable:
chmod +x terraform_drift_detector.py
Usage
Basic usage:
tfdd
This will scan the current directory for Terraform files and check for drift.
Command Line Options
usage: terraform_drift_detector.py [-h] [-d DIRECTORY] [--details] [-w WORKERS] [-o OUTPUT]
Detect drift in Terraform-managed infrastructure
options:
-h, --help show this help message and exit
-d DIRECTORY, --directory DIRECTORY
Directory containing Terraform files (default: current directory)
--details Show detailed information about detected drift
-w WORKERS, --workers WORKERS
Maximum number of parallel workers (default: 5)
-o OUTPUT, --output OUTPUT
Save results to a JSON file
Examples
Scan a specific directory with detailed output:
./terraform_drift_detector.py -d /path/to/terraform --details
Scan with more parallel workers and save results to a file:
./terraform_drift_detector.py -w 10 -o drift_results.json
Exit Codes
- 0: No drift detected
- 1: Error during execution
- 2: Drift detected
You can use these exit codes in CI/CD pipelines to fail builds or trigger alerts when drift is detected.
How It Works
The tool:
- Finds all directories containing Terraform files
- Runs
terraform initif needed - Executes
terraform planwith the-detailed-exitcodeoption - Parses the results to determine if drift exists
- For detailed reports, uses
terraform show -jsonto extract specific resource changes
Requirements
- Python 3.6+
- Terraform CLI installed and in PATH
- Valid Terraform configurations with proper authentication to your infrastructure provider
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file terraform_drift_detector-0.1.0.tar.gz.
File metadata
- Download URL: terraform_drift_detector-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afce2cf0b5c4aa7369965cd115da3329b8b2227f963712f971c459e6268365ed
|
|
| MD5 |
953ad53d8b3907d7874d820106ba1ab9
|
|
| BLAKE2b-256 |
5f618bafc40f099cb0aaa4771c7735a99c0967a168fa5ca1f2a82d49685a92a4
|
File details
Details for the file terraform_drift_detector-0.1.0-py3-none-any.whl.
File metadata
- Download URL: terraform_drift_detector-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c02a90643c6fa45e675cdc38285f65c090464a693cc7b2862cad4cea565de9d8
|
|
| MD5 |
41a48841cf0280ad3b801d91807fcf18
|
|
| BLAKE2b-256 |
c6c5d2c3f629eb3d52696026641aa187517173d48492c4907640ae9c4d2825e4
|