Skip to main content

CLI to scan and fix Terraform and CDK IaC with LangChain-orchestrated agents

Project description

IaC Scanner

PyPI version CI

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 to main.tf itself.
  • CDK: path to a directory containing index.ts or index.js, or path to that file.

Process

  1. Factory creates the right scanner (TerraformScanner or CdkScanner) from the given path.
  2. Scan: load entry file(s) and gather content.
  3. Analysis task (LangChain + analysis AI): security and best-practice findings.
  4. Fix task (LangChain + fix AI): generate corrected code from findings.
  5. Output: report (JSON) and fixed TF/CDK code under an output directory.

Output

  • Report: scan-report.json with iac_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) or anthropic; IAC_ANALYSIS_MODEL for model name. Uses OPENAI_API_KEY or ANTHROPIC_API_KEY.
  • Fix task: IAC_FIX_AI=openai (default) or anthropic; IAC_FIX_MODEL for 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


Download files

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

Source Distribution

iac_scanner-0.3.2.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

iac_scanner-0.3.2-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

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

Hashes for iac_scanner-0.3.2.tar.gz
Algorithm Hash digest
SHA256 eacb168ecbb7f178480e5814aea8d9032b1d7395bb850aa3e8d22e9b7f5da5f7
MD5 2644630f01d86fd96fb0f398ece421e8
BLAKE2b-256 56c5d82aff71e3db1ca56497ec732a35137b535ec19f06dd1e9430559583bc9b

See more details on using hashes here.

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

Hashes for iac_scanner-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 529d64310c606bf78ffb4fed3aa34fe55e448a5cd5715a0bb3c773fa86611476
MD5 783ea789ca37bdb543c5c5fe8b057dc0
BLAKE2b-256 c465c8f73bc2f8830dd9a53b842ed91b0fe93bb882fbe426dd7b9bc56f587b50

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