CLI to scan and fix Terraform and CDK IaC with LangChain-orchestrated agents
Project description
IaC Scanner
Python CLI that scans Terraform and AWS CDK Infrastructure-as-Code, then produces a report and fixed code. Built with a factory pattern (scanner per IaC type) and LangChain orchestration where each task uses a different AI (analysis vs code generation).
License: Personal Use License — personal use permitted; redistribution (including publishing or selling) requires permission. Contributing back via pull request is welcome.
Quickstart (30 seconds, no API key)
pip install iac-scanner
iac-scan scan ./samples/tf -o ./out --scan-only
Example output:
Detected: terraform (entry: .../samples/tf/main.tf)
Scan-only: writing report (no AI).
Output written to: ./out
- ./out/scan-report.json
Open ./out/scan-report.json for iac_type, metadata.files, and findings. To get findings and fixed code, set OPENAI_API_KEY (or ANTHROPIC_API_KEY) and run without --scan-only:
export OPENAI_API_KEY=sk-...
iac-scan scan ./samples/tf -o ./out
Input (CLI)
- Terraform: path to a directory containing
main.tf, or path tomain.tfitself. - CDK: path to a directory containing
index.tsorindex.js, or path to that file.
Process
- Factory creates the right scanner (
TerraformScannerorCdkScanner) from the given path. - Scan: load entry file(s) and gather content.
- Analysis task (LangChain + analysis AI): security and best-practice findings.
- Fix task (LangChain + fix AI): generate corrected code from findings.
- Output: report (JSON) and fixed TF/CDK code under an output directory.
Output
- Report:
scan-report.jsonwithiac_type,entry_path,findings, and metadata. - Fixed code: under
fixed/(same structure as detected files when the model returns multi-file blocks).
Install
cd iac-scanner
pip install -e .
# or
pip install -r requirements.txt
Usage
# Scan Terraform (directory with main.tf or path to main.tf)
iac-scan scan ./my-tf-dir
iac-scan scan ./my-tf-dir/main.tf
# Scan CDK (directory with index.ts or path to index.ts)
iac-scan scan ./my-cdk-app
iac-scan scan ./my-cdk-app/index.ts
# Custom output directory and report name
iac-scan scan ./my-tf-dir -o ./reports --report-name report.json
# Only report, no fix step
iac-scan scan ./my-tf-dir --no-fix
# Scan only (no AI), for testing without API keys
iac-scan scan ./my-tf-dir --scan-only
# Choose AI per task (analysis vs fix)
iac-scan scan ./my-tf-dir --analysis-ai openai --fix-ai anthropic
Environment (different AI per task)
- Analysis task:
IAC_ANALYSIS_AI=openai(default) oranthropic;IAC_ANALYSIS_MODELfor model name. UsesOPENAI_API_KEYorANTHROPIC_API_KEY. - Fix task:
IAC_FIX_AI=openai(default) oranthropic;IAC_FIX_MODELfor model name.
Example:
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
iac-scan scan ./tf -o ./out
Blog and tutorial
Articles and a step-by-step tutorial are published on GitHub Pages. Enable in the repo under Settings → Pages (source: branch main, folder /docs). The site will be at https://<owner>.github.io/iac-scanner/.
Contributing
Contribution guidelines, development setup, and release process are in CONTRIBUTING.md (in the source repository). If you installed from PyPI, open the project repo to see that file.
Project layout (factory + orchestration)
src/iac_scanner/
cli.py # CLI entry (click)
factory.py # create_scanner(path) -> TerraformScanner | CdkScanner
scanners/
base.py # IacScanner (abstract), ScanResult
terraform.py # TerraformScanner (main.tf)
cdk.py # CdkScanner (index.ts / index.js)
orchestration/
tasks.py # analysis_chain() / fix_chain() — different LLM per task
runner.py # run_pipeline(scanner) -> PipelineResult
output/
report.py # write_report_and_fixes()
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 iac_scanner-0.3.2.tar.gz.
File metadata
- Download URL: iac_scanner-0.3.2.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eacb168ecbb7f178480e5814aea8d9032b1d7395bb850aa3e8d22e9b7f5da5f7
|
|
| MD5 |
2644630f01d86fd96fb0f398ece421e8
|
|
| BLAKE2b-256 |
56c5d82aff71e3db1ca56497ec732a35137b535ec19f06dd1e9430559583bc9b
|
File details
Details for the file iac_scanner-0.3.2-py3-none-any.whl.
File metadata
- Download URL: iac_scanner-0.3.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
529d64310c606bf78ffb4fed3aa34fe55e448a5cd5715a0bb3c773fa86611476
|
|
| MD5 |
783ea789ca37bdb543c5c5fe8b057dc0
|
|
| BLAKE2b-256 |
c465c8f73bc2f8830dd9a53b842ed91b0fe93bb882fbe426dd7b9bc56f587b50
|