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 and versioning

  • Contributing: See CONTRIBUTING.md (issues, PRs, code style, versioning).
  • Releases: We use Semantic Versioning; releases are tagged (e.g. v0.1.0). CI runs on GitLab and GitHub (lint, test, build on tags).

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.1.0.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.1.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iac_scanner-0.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 f95d6e5a1ecc74cc82637cbad9dc58fd0edd00498cee6ba1794e5ce4043082d5
MD5 73e1628390c2c747cb0b9e43bfef7e3e
BLAKE2b-256 9d587cbea8cea467028b374d04b4d0574bcfc679efb6b2ed5ad9f7b97d61d858

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iac_scanner-0.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07affd1c4b17b892ca1cab71ea2cf9f6de509942e925fae867f5a9c2fb61201d
MD5 1b9809f410a0298fdac955675df41a8e
BLAKE2b-256 6fbe00d9eef338090730c2bf4a9e4956b360dccaf5b85fdb6c1674339152b495

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