ThothCTL Inventory Command¶
Overview¶
The thothctl inventory command creates, manages, and updates inventories of your infrastructure components. This command helps you track modules, their versions, sources, and dependencies, providing valuable insights into your infrastructure composition and enabling version management.
Available Inventory Commands¶
inventory iac¶
Creates an inventory of Infrastructure as Code (IaC) components in your project.
Options:
- -ft, --framework-type [auto|terraform|terragrunt|terraform-terragrunt]: Framework type to analyze (default: auto)
- -iph, --inventory-path PATH: Path for saving inventory reports (default: ./Reports/Inventory)
- -ch, --check-versions: Check remote versions
- -updep, --update-dependencies-path: Pass the inventory json file path for updating dependencies
- -auto, --auto-approve: Use with --update_dependencies option for auto approve updating dependencies
- -iact, --inventory-action [create|update|restore]: Action for inventory tasks (default: create)
- --report-type, -r [html|json|all]: Type of report to generate (default: html)
Detailed documentation for inventory iac
Basic Usage¶
Create an Inventory¶
This creates an inventory of all IaC components in the current directory and generates an HTML report in the default location (./Reports/Inventory).
Create an Inventory with Version Checking¶
This creates an inventory and checks if the modules are using the latest available versions.
Generate Different Report Types¶
This creates an inventory and generates a JSON report.
This creates an inventory and generates both HTML and JSON reports.
Framework Type Options¶
The command supports different IaC frameworks:
Auto-detect Framework (Default)¶
This automatically detects the framework type based on the files in your project.
Terraform Framework¶
This analyzes only Terraform files (.tf) in your project.
Terragrunt Framework¶
This analyzes only Terragrunt files (terragrunt.hcl) in your project, excluding .terragrunt-cache directories.
Mixed Terraform-Terragrunt Framework¶
This analyzes both Terraform and Terragrunt files in your project.
Inventory Actions¶
The command supports three main actions:
1. Create (Default)¶
This action scans your IaC files and creates a new inventory.
2. Update¶
This action updates your IaC files based on the inventory. It can be used to apply version updates or other changes.
3. Restore¶
This action restores your IaC files to the state recorded in the inventory.
Inventory Reports¶
The command generates detailed reports about your infrastructure components:
HTML Report¶
The HTML report includes: - Project overview and framework type - Module list with versions and sources - Dependency graph visualization - Version status (latest vs. current) - File locations
JSON Report¶
The JSON report contains structured data about your infrastructure:
{
"version": 2,
"projectName": "my-project",
"projectType": "terragrunt",
"components": [
{
"path": "./modules",
"components": [
{
"type": "terragrunt_module",
"name": "vpc",
"version": ["3.14.0"],
"source": ["terraform-aws-modules/vpc/aws"],
"file": "modules/terragrunt.hcl",
"latest_version": "5.19.0",
"source_url": "https://registry.terraform.io/v1/modules/terraform-aws-modules/vpc/aws",
"status": "Outdated"
}
]
}
]
}
Use Cases¶
Infrastructure Auditing¶
Create an inventory to audit your infrastructure components:
Version Management¶
Identify outdated modules and update them:
# First create an inventory with version checking
thothctl inventory iac --check-versions --report-type json
# Then update modules to latest versions
thothctl inventory iac --inventory-action update --inventory-path ./Reports/Inventory/InventoryIaC_20250602_121227.json
Documentation¶
Generate documentation about your infrastructure:
Disaster Recovery¶
Create regular inventories for disaster recovery purposes:
Examples¶
Basic Inventory Creation¶
Terragrunt Project Inventory¶
Comprehensive Inventory with Version Checking¶
Update Infrastructure to Latest Versions¶
# First create an inventory with version checking
thothctl inventory iac --check-versions --report-type json
# Then update modules to latest versions
thothctl inventory iac --inventory-action update --inventory-path ./Reports/Inventory/InventoryIaC_20250602_121227.json
Restore Infrastructure from Backup¶
thothctl inventory iac --inventory-action restore --inventory-path ./backups/2023-01-01/inventory.json
Best Practices¶
- Regular Inventories: Create inventories regularly to track changes over time
- Version Checking: Use
--check-versionsto identify outdated modules - Multiple Report Types: Use
--report-type allto generate both HTML and JSON reports - Backup Inventories: Store inventories in a version-controlled location
- CI/CD Integration: Add inventory creation to your CI/CD pipeline
- Framework Specification: Explicitly specify the framework type for more accurate results
Troubleshooting¶
Common Issues¶
No Components Found¶
Solution: Ensure you're running the command in a directory containing Terraform (.tf) or Terragrunt (terragrunt.hcl) files.
Version Checking Failures¶
Solution: Ensure you have internet connectivity and the module source is accessible.
Report Generation Failures¶
Solution: Ensure you have write permissions to the output directory.
Debugging¶
For more detailed logs, run ThothCTL with the --debug flag:
Related Commands¶
- thothctl check iac: Check IaC components against best practices
- thothctl scan: Scan infrastructure code for security issues