thothctl

ThothCTL Inventory IaC Command

Overview

The thothctl inventory iac command creates, updates, and manages an inventory of Infrastructure as Code (IaC) components in your project. This inventory tracks modules, their versions, sources, and dependencies, providing valuable insights into your infrastructure composition with modern, professional HTML reports and comprehensive provider version analysis.

Recent Improvements ✨

Command Options

Usage: thothctl inventory iac [OPTIONS]

  Create a inventory about IaC modules composition for terraform/tofu/terragrunt projects

Options:
  -cv, --check-versions           Check latest versions for modules
  -cpv, --check-provider-versions Check latest versions for providers
  --check-providers               Check and report provider information for each stack
  -ft, --framework-type [auto|terraform|terragrunt|terraform-terragrunt|module|cdkv2]
                                  Framework type to analyze (auto for automatic detection)
  -r, --report-type [html|json|cyclonedx|all]
                                  Type of report to generate
  --publish-sbom [dependency-track|defectdojo|secobserve]
                                  Publish CycloneDX SBOM to external platform after generation
  --product-group TEXT            SecObserve product group for a newly created product
                                  (requires --publish-sbom secobserve)
  -iact, --inventory-action [create|update|restore]
                                  Action for inventory tasks
  -iph, --inventory-path PATH     Path for saving inventory reports
  -pj, --project-name TEXT        Custom project name for the report
  --provider-tool [tofu|terraform]
                                  Tool to use for checking providers (default: tofu)
  --complete                      Include .terraform and .terragrunt-cache in analysis
  -auto, --auto-approve           Auto approve updating dependencies
  --post-to-pr                    Post inventory summary as a PR comment
                                  (Azure DevOps or GitHub)
  --vcs-provider [auto|azure_repos|github]
                                  VCS provider for PR comments (default:
                                  auto-detect from CI environment)
  --space TEXT                    Space name for credential resolution
                                  (Azure DevOps)
  --help                          Show this message and exit.

Basic Usage

Create a Basic Inventory

thothctl inventory iac

This creates an inventory of all IaC components in the current directory and generates a modern HTML report in the default location (./Reports/Inventory).

Create an Inventory with Version Checking

# Check module versions only
thothctl inventory iac -cv

# Check provider versions only
thothctl inventory iac -cpv

# Check both module and provider versions
thothctl inventory iac -cv -cpv

# Provider info without version lookup
thothctl inventory iac --check-providers

Generate Different Report Types

# HTML report with modern styling (default)
thothctl inventory iac --report-type html

# JSON report for automation
thothctl inventory iac --report-type json

# CycloneDX SBOM report (OWASP standard)
thothctl inventory iac --report-type cyclonedx

# All report types (HTML, JSON, and CycloneDX)
thothctl inventory iac --report-type all

Specify Custom Output Directory and Project Name

thothctl inventory iac \
  -cv -cpv \
  --inventory-path ./docs/infrastructure \
  --project-name "Production Infrastructure"

Modern HTML Reports 🎨

The new HTML reports feature:

CycloneDX SBOM Reports 🔒

ThothCTL now supports generating CycloneDX Software Bill of Materials (SBOM) reports, following the OWASP CycloneDX standard:

Features:

Use Cases:

Example:

# Generate CycloneDX SBOM for security audit
thothctl inventory iac -cv -cpv --report-type cyclonedx

# Complete analysis with all formats including SBOM
thothctl inventory iac -cv -cpv --report-type all

The CycloneDX report includes:

Dependency-Track Integration 🚀

Publish your CycloneDX SBOM directly to OWASP Dependency-Track for centralized vulnerability management:

Prerequisites

  1. Dependency-Track instance running (v4.x or v5.x) — install guide
  2. API key with the following permissions:
    • BOM_UPLOAD (required)
    • VIEW_PORTFOLIO (recommended — allows project lookup)
    • PROJECT_CREATION_UPLOAD (only if auto_create = true)

    To create an API key: Administration → Access Management → Teams → select team → API Keys → Generate

  3. Project in Dependency-Track (either pre-created or use auto_create = true)
    • If using an existing project, set DTRACK_PROJECT_UUID to skip auto-creation and avoid needing PROJECT_CREATION_UPLOAD permission

Usage

# Generate SBOM and publish to Dependency-Track in one command
thothctl inventory iac --check-versions --publish-sbom dependency-track

# With custom project name
thothctl inventory iac --check-versions --publish-sbom dependency-track \
  --project-name "my-platform-infra"

Configuration (priority: env vars > .thothcf.toml):

# Environment variables
export DTRACK_URL="https://dtrack.example.com"
export DTRACK_API_KEY="your-api-key"
export DTRACK_PROJECT_NAME="my-project"     # Optional (auto-detected from SBOM)
export DTRACK_PROJECT_VERSION="latest"       # Optional (default: latest)
export DTRACK_PROJECT_UUID="uuid-here"       # Optional (use existing project, skips auto-create)

Or in .thothcf.toml:

[integrations.dependency_track]
url = "https://dtrack.example.com"
api_key = "your-api-key"
project_name = "my-platform-infra"
project_version = "latest"
auto_create = true              # Create project if it doesn't exist
project_uuid = ""               # Optional: use existing project UUID (skips auto-create)
parent_project = "org-parent"   # Optional: nest under parent project

CI/CD Integration:

# GitHub Actions
- name: Inventory + Publish to Dependency-Track
  env:
    DTRACK_URL: $
    DTRACK_API_KEY: $
  run: |
    thothctl inventory iac --check-versions \
      --publish-sbom dependency-track \
      --project-name "$"

Features:

DefectDojo Integration 🛡️

Publish your CycloneDX SBOM to OWASP DefectDojo for vulnerability management and security orchestration:

Prerequisites

  1. DefectDojo instance running (v2.x+) — install guide
  2. API token — generate at: User menu → API v2 Key
  3. Token format: Token <your-api-key> (ThothCTL handles the prefix)

Usage

# Generate SBOM and publish to DefectDojo
thothctl inventory iac --check-versions --publish-sbom defectdojo

# With custom product name
thothctl inventory iac --check-versions --publish-sbom defectdojo \
  --project-name "my-platform-infra"

Configuration (priority: env vars > .thothcf.toml):

# Environment variables
export DEFECTDOJO_URL="http://defectdojo.example.com:8090"
export DEFECTDOJO_TOKEN="your-api-token"
export DEFECTDOJO_PRODUCT_NAME="my-project"         # Optional (uses --project-name)
export DEFECTDOJO_ENGAGEMENT_NAME="IaC Inventory"   # Optional (default: "IaC Supply Chain Inventory")

Or in .thothcf.toml:

[integrations.defectdojo]
url = "http://defectdojo.example.com:8090"
token = "your-api-token"
product_name = "my-platform-infra"
product_type_name = "Infrastructure"      # Product type category
engagement_name = "IaC Supply Chain Inventory"
auto_create = true                        # Create product/engagement if they don't exist
close_old_findings = true                 # Close findings no longer in SBOM
deduplication_on_engagement = true        # Deduplicate within engagement

CI/CD Integration:

# GitHub Actions
- name: Inventory + Publish to DefectDojo
  env:
    DEFECTDOJO_URL: $
    DEFECTDOJO_TOKEN: $
  run: |
    thothctl inventory iac --check-versions \
      --publish-sbom defectdojo \
      --project-name "$"

Features:

SecObserve Integration 🔍

Publish your CycloneDX SBOM and scan results to SecObserve for unified vulnerability and license management:

Prerequisites

  1. SecObserve instance running (tested with v1.41.1) — install guide
  2. API token — generate at: User menu → Settings → API Tokens
  3. Token format: APIToken <your-token> (ThothCTL handles the prefix)
  4. Product in SecObserve (auto-created if auto_create_product = true). Products can be placed in a product group to share security gate settings

Usage

# Publish SBOM for license tracking
thothctl inventory iac --check-versions --publish-sbom secobserve

# Publish scan findings (all scanners supported via SARIF)
thothctl scan iac -t checkov -t trivy -t kics -t opa --publish-to secobserve

# Create new products inside a product group (SBOM and scans)
thothctl inventory iac --check-versions --publish-sbom secobserve --product-group platform-team
thothctl scan iac -t checkov --publish-to secobserve --product-group platform-team

# Publish and let the SecObserve security gate decide pass/fail
thothctl scan iac -t checkov -t kics --publish-to secobserve \
  --gate-source secobserve --enforcement hard

Configuration (priority: env vars > .thothcf.toml):

# Environment variables
export SECOBSERVE_URL="http://secobserve-backend.localhost"
export SECOBSERVE_API_TOKEN="api_token_..."
export SECOBSERVE_PRODUCT_NAME="my-project"     # Optional (uses --project-name)
export SECOBSERVE_PRODUCT_GROUP="platform-team"  # Optional (group for new products; --product-group overrides)
export SECOBSERVE_BRANCH_NAME="main"             # Recommended (see note below)
export SECOBSERVE_ORIGIN_SERVICE="my-service"    # Optional (service for scans and SBOMs)
export SECOBSERVE_AUTO_CREATE="true"             # Optional (default: true)

Or in .thothcf.toml:

[integrations.secobserve]
url = "http://secobserve-backend.localhost"
api_token = "api_token_..."
product_name = "my-platform-infra"
product_group = "platform-team" # optional; group for products ThothCTL creates
branch_name = "main"
origin_service = "thothctl"     # optional; sent as SecObserve "service"
auto_create_product = true

!!! note “Branch name” The first branch imported for a product becomes its default branch, and SecObserve computes the security gate only for that branch. Always set SECOBSERVE_BRANCH_NAME in CI (for example main, or the PR branch). Without it, a product that already has a default branch can’t be gated (--gate-source secobserve reports UNKNOWN).

!!! note “Service name” By default each tool’s scan findings are attributed to a service with the tool’s name (kics, checkov, …). Setting origin_service sends that value as the SecObserve service for all tools, and for SBOM uploads, instead. Findings are still tracked separately per tool, because each tool uses its own upload file. SBOMs get no service unless origin_service is set.

!!! note “Product group” --product-group (or product_group) only applies to products that ThothCTL creates. Existing products are never moved between groups; a warning is shown instead. See Product groups.

CI/CD Integration:

# GitHub Actions
- name: Scan + Publish to SecObserve
  env:
    SECOBSERVE_URL: $
    SECOBSERVE_API_TOKEN: $
    SECOBSERVE_BRANCH_NAME: $
  run: |
    thothctl inventory iac --check-versions \
      --publish-sbom secobserve \
      --project-name "$"

    thothctl scan iac -t checkov -t trivy -t kics -t opa \
      --publish-to secobserve \
      --gate-source secobserve --enforcement hard \
      -p "$"

Supported scanners (all published via SARIF, one file per tool):

Scanner Uploaded file Notes
Checkov thothctl-checkov.sarif SARIF generated from scan results
Trivy thothctl-trivy.sarif SARIF generated from scan results
KICS kics-results.sarif Native .sarif output used directly
OPA/Conftest thothctl-opa.sarif SARIF generated from policy violations
terraform-compliance thothctl-terraform-compliance.sarif SARIF generated from scan results

Features:

Professional Design

Enhanced Data Visualization

Report Features

Version Checking & Provider Analysis 📊

Unified Version Checking

The --check-versions flag now provides comprehensive analysis:

thothctl inventory iac --check-versions

What it does:

Provider-Only Analysis

If you only want provider information without version checking:

thothctl inventory iac --check-providers

Provider Version Information

The reports now include comprehensive provider data:

Technical Debt Scoring 📊

When --check-versions is enabled, ThothCTL calculates a technical debt score that reflects how outdated your infrastructure is.

Weighted Formula

The debt score uses a weighted approach that separates module health from provider health:

module_debt   = outdated_modules / total_modules       (weight: 70%)
provider_debt = outdated_providers / total_providers   (weight: 30%)

debt_score = (module_debt × 0.7 + provider_debt × 0.3) × 100 + breaking_changes_penalty

Why weighted? Modules define your architecture and are the primary source of risk. Providers are dependencies that may be intentionally pinned (e.g., a latest module tested against a specific provider version). A single outdated provider should not inflate the score disproportionately.

Breaking Changes Penalty

Each module or provider with detected breaking changes adds +5 points to the debt score (capped at 100%).

Risk Levels

Debt Score Risk Level Meaning
≥ 70% Critical Immediate action required
≥ 50% High Plan upgrades soon
≥ 30% Medium Schedule maintenance
< 30% Low Infrastructure is well-maintained

Examples

Scenario Score Risk
2 modules current, 1/2 providers outdated 15% Low
2/4 modules outdated, providers current 35% Medium
All modules and providers outdated 100% Critical
Everything current 0% Low

Recommendations

The system auto-generates actionable recommendations based on the metrics:

CDK Project Support (v0.25.0)

The inventory iac command now supports AWS CDK projects (TypeScript and Python). When cdk.json is detected in your project, ThothCTL automatically switches to CDK inventory mode.

CDK TypeScript

# In a CDK TypeScript project
thothctl inventory iac --check-versions
# Detects constructs: aws-cdk-lib, cdk-nag, @myorg/cdk-patterns, constructs, etc.

Parses package.json and package-lock.json to identify CDK construct libraries, then queries the npm registry for latest versions and release dates.

CDK Python

# In a CDK Python project
thothctl inventory iac --check-versions
# Detects constructs: aws-cdk-lib, cdk-nag, constructs, etc.

Parses requirements.txt or pyproject.toml to identify CDK construct libraries, then queries PyPI for latest versions and release dates.

Framework Type Flag

You can also explicitly select CDK mode:

thothctl inventory iac --framework-type cdkv2 --check-versions

Notes


Framework Type Options

Auto-detect Framework (Default)

thothctl inventory iac --framework-type auto

Automatically detects the framework type based on project files.

Terraform Framework

thothctl inventory iac --framework-type terraform --check-versions

Analyzes Terraform files (.tf) with version checking.

Terragrunt Framework

thothctl inventory iac --framework-type terragrunt --check-versions

Analyzes Terragrunt files (terragrunt.hcl) with comprehensive provider analysis.

Mixed Terraform-Terragrunt Framework

thothctl inventory iac --framework-type terraform-terragrunt --check-versions

Analyzes both Terraform and Terragrunt files with full version checking.

Inventory Actions

1. Create (Default)

thothctl inventory iac --inventory-action create --check-versions

Scans IaC files and creates a new inventory with version analysis.

2. Update

thothctl inventory iac \
  --inventory-action update \
  --inventory-path ./path/to/inventory.json \
  --auto-approve

Updates IaC files based on the inventory.

3. Restore

thothctl inventory iac \
  --inventory-action restore \
  --inventory-path ./path/to/inventory.json

Restores IaC files to the state recorded in the inventory.

Advanced Usage Examples

Comprehensive Infrastructure Audit

thothctl inventory iac \
  --check-versions \
  --report-type all \
  --project-name "Production Infrastructure Audit" \
  --inventory-path ./docs/audit

This generates:

Terragrunt Project Analysis

thothctl inventory iac \
  --framework-type terragrunt \
  --check-versions \
  --project-name "Terragrunt Infrastructure"

CI/CD Integration

# In your CI/CD pipeline
thothctl inventory iac \
  --check-versions \
  --report-type json \
  --inventory-path ./reports/$(date +%Y-%m-%d)

# Post inventory summary as a PR comment
thothctl inventory iac --check-versions --post-to-pr

PR Comment Integration

The --post-to-pr flag posts an inventory summary table directly to the pull request, including component counts, provider stats, and technical debt metrics.

# GitHub Actions example
- run: thothctl inventory iac --check-versions --post-to-pr
  env:
    GITHUB_TOKEN: $

# Azure Pipelines example (uses built-in System.AccessToken, no PAT needed)
- script: thothctl inventory iac --check-versions --post-to-pr
  env:
    AZDO_PERSONAL_ACCESS_TOKEN: $(System.AccessToken)

Platform comment size limits (GitHub: 65K chars, Azure DevOps: 150K chars) are enforced automatically with truncation. See check iac PR comment docs for full platform setup details, including required Azure DevOps build service permissions.

Complete Analysis with All Options

thothctl inventory iac \
  --check-versions \
  --complete \
  --report-type all \
  --project-name "Complete Infrastructure Analysis" \
  --provider-tool tofu \
  --inventory-path ./comprehensive-analysis

Report Structure

HTML Report Sections

  1. Header: Project name, type, and generation timestamp
  2. Summary: Statistics about components, providers, and versions
  3. Stack Details: Organized by stack with:
    • Component tables with version information
    • Provider tables with version analysis
    • Status indicators and latest version information

JSON Report Structure

{
  "version": 2,
  "projectName": "my-project",
  "projectType": "terraform-terragrunt",
  "components": [
    {
      "stack": "./stacks/networking",
      "components": [
        {
          "type": "module",
          "name": "vpc",
          "version": ["5.0.0"],
          "source": ["terraform-aws-modules/vpc/aws"],
          "latest_version": "5.19.0",
          "source_url": "https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws",
          "status": "Outdated"
        }
      ],
      "providers": [
        {
          "name": "aws",
          "version": "6.0.0",
          "source": "registry.opentofu.org/hashicorp/aws",
          "module": "Root",
          "component": "networking",
          "latest_version": "6.2.0",
          "status": "outdated"
        }
      ]
    }
  ],
  "provider_version_stats": {
    "total_providers": 15,
    "outdated_providers": 3,
    "current_providers": 12,
    "unknown_providers": 0
  }
}

Use Cases

1. Infrastructure Auditing

thothctl inventory iac --check-versions --report-type all

Benefits:

2. Version Management

# Create inventory with version analysis
thothctl inventory iac --check-versions --report-type json

# Review the generated report for outdated components
# Update modules based on findings

3. Documentation Generation

thothctl inventory iac \
  --check-versions \
  --project-name "Production Infrastructure Documentation" \
  --report-type html

Generates professional documentation with:

4. Compliance and Security

thothctl inventory iac \
  --check-versions \
  --complete \
  --report-type all

Helps with:

5. CI/CD Integration

# In your pipeline
thothctl inventory iac \
  --check-versions \
  --report-type json \
  --inventory-path ./reports/$(date +%Y-%m-%d)

# Parse JSON output for automated decision making

Best Practices

1. Regular Version Checking

# Run weekly to identify outdated components
thothctl inventory iac --check-versions

2. Comprehensive Analysis

# For thorough audits, use all features
thothctl inventory iac \
  --check-versions \
  --complete \
  --report-type all \
  --project-name "Monthly Infrastructure Audit"

3. Documentation Standards

# Generate consistent documentation
thothctl inventory iac \
  --check-versions \
  --project-name "$(basename $(pwd)) Infrastructure" \
  --inventory-path ./docs/infrastructure

4. Provider Tool Selection

# Use OpenTofu for modern Terraform workflows
thothctl inventory iac --check-versions --provider-tool tofu

# Use Terraform for legacy workflows
thothctl inventory iac --check-versions --provider-tool terraform

5. Report Organization

# Organize reports by date and environment
thothctl inventory iac \
  --check-versions \
  --inventory-path ./reports/$(date +%Y-%m)/production \
  --project-name "Production Infrastructure - $(date +%B\ %Y)"

Troubleshooting

Common Issues

CSS Styling Issues (Fixed)

The recent updates have resolved all CSS variable issues that previously caused HTML report generation failures.

Version Checking Failures

Error: Failed to check versions for module xyz

Solution: Ensure internet connectivity and module source accessibility.

Provider Analysis Failures

Error: Failed to get providers for stack xyz

Solution:

Report Generation Issues

Error: Failed to generate HTML report

Solution: Ensure write permissions to the output directory.

Debugging

For detailed logs:

thothctl --debug inventory iac --check-versions

Migration from Old Flags

Before (Deprecated)

# Old redundant flags
thothctl inventory iac --check-providers --check-provider-versions --check-versions
# New unified approach
thothctl inventory iac --check-versions

Benefits of the new approach:

Summary

The thothctl inventory iac command now provides:

Use thothctl inventory iac --check-versions for the best experience with comprehensive analysis and modern reporting.