Skip to main content

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.

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

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.2.1.tar.gz (12.2 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.2.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file iac_scanner-0.2.1.tar.gz.

File metadata

  • Download URL: iac_scanner-0.2.1.tar.gz
  • Upload date:
  • Size: 12.2 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.2.1.tar.gz
Algorithm Hash digest
SHA256 cd44647523a13f4c95ea85667edbb0255e96aa7fe7c7ed97d20e03896c9e447c
MD5 f87854002219de170e4154c0f059f8f9
BLAKE2b-256 058102785365e7a4f4aed8219b42ae57ae977fea3c9782a5afd7eae864f8ada2

See more details on using hashes here.

File details

Details for the file iac_scanner-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: iac_scanner-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cafcf88389b4957901b2bc5d9725642e8f3b0fba78daf5b2384a051095d42e27
MD5 f793ef6f39657929b22d2b23c541f386
BLAKE2b-256 e04f5f730db5454e1adc71d711bb92352d9c240e659e3cee80d5b5c1aa3ee6c5

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