The thothctl check project iac command validates Infrastructure as Code source code structure and organization. This command ensures your IaC projects follow defined standards, have required files, and maintain proper folder hierarchies.
Usage: thothctl check project iac [OPTIONS]
Check Infrastructure as Code project structure and configuration
Options:
-m, --mode [soft|strict] Validation mode [default: soft]
-t, --check-type [structure|metadata|compliance]
Type of IaC check to perform [default: structure]
-p, --project-type [stack|module]
Project type: stack or module [default: stack]
--org-policy TEXT Organization policy source (Git URL or local path)
--enforcement [soft|hard] Enforcement mode: soft (report) or hard (fail pipeline)
--skip-org-policy Skip organizational policy check (project exceptions)
--help Show this message and exit.
ThothCTL can enforce organizational standards that projects cannot override. This ensures all projects in your organization follow the same structure, naming, and tagging rules โ regardless of what individual .thothcf.toml files contain.
ThothCTL resolves the org policy source in this order:
| Priority | Source | Example |
|---|---|---|
| 1 | --org-policy flag |
--org-policy https://github.com/myorg/policies.git |
| 2 | THOTH_ORG_POLICY env var |
export THOTH_ORG_POLICY=https://github.com/myorg/policies.git |
| 3 | Active spaceโs governance.policy_repo |
Set via thothctl space update <name> --policy-repo <url> |
| 4 | None (skip org policy) | No org rules applied |
When a space is active and has a policy_repo configured, organizational rules are loaded automatically โ no flags or env vars needed:
# 1. Configure your space with the org policy repo
thothctl space update platform-team --policy-repo https://github.com/myorg/org-policies.git
# 2. Activate the space
thothctl space activate platform-team
# 3. Run check โ org rules load automatically
thothctl check project iac -p stack
# Output:
# ๐ Loading org policy from: /home/user/.thothcf/.policy_cache/abc123
# โ
Organization policy check passed
Projects that have explicit exceptions from organizational rules can skip the check:
thothctl check project iac -p stack --skip-org-policy
This is useful for:
rules/base.toml + rules/<project_type>.toml# Automatic via active space (preferred)
thothctl space activate platform-team
thothctl check project iac --enforcement hard
# Via env var (CI/CD)
export THOTH_ORG_POLICY=https://github.com/myorg/org-policies.git
thothctl check project iac --enforcement hard
# Pin to a version
export THOTH_ORG_POLICY=https://github.com/myorg/org-policies.git@v1.0
thothctl check project iac --enforcement hard
# Via flag (explicit override)
thothctl check project iac --org-policy /path/to/org-policies --enforcement hard
| Level | Behavior | Project Can Override? |
|---|---|---|
mandatory |
Fails pipeline with --enforcement hard |
โ No |
recommended |
Warning only | โ ๏ธ Can opt-out |
informational |
Report only | โ Yes |
org-policies/
โโโ rules/ # ThothCTL structural rules
โ โโโ base.toml # All project types
โ โโโ terraform-terragrunt.toml
โ โโโ terraform_module.toml
โ โโโ cdkv2.toml
โโโ shared/policy/ # OPA/Rego policies (used by scan iac -t opa)
โ โโโ naming.rego
โ โโโ tagging.rego
โ โโโ regions.rego
โโโ README.md
The same repo serves both:
thothctl check project iac โ reads rules/thothctl scan iac -t opa โ reads shared/policy/ (auto-discovered via THOTH_ORG_POLICY)๐ Loading org policy from: https://github.com/myorg/org-policies.git
โ Mandatory Violations
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโ
โ Rule โ Expected โ Found โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโผโโโโโโโโโโค
โ project_structure.folders.docs โ docs/ exists โ missing โ
โ project_structure.root_files โ .pre-commit... โ missing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโดโโโโโโโโโโ
โ ๏ธ Recommendations
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโ
โ Rule โ Expected โ Found โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโผโโโโโโโโโโค
โ project_structure.folders.common โ common/ exists โ missing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโดโโโโโโโโโโ
# GitHub Actions
- name: Check org compliance
run: thothctl check project iac --enforcement hard
env:
THOTH_ORG_POLICY: https://github.com/myorg/org-policies.git@v1.0
-p stack)Full infrastructure projects with modules, environments, and complete project structure.
Typical Structure:
project/
โโโ .gitignore
โโโ .pre-commit-config.yaml
โโโ README.md
โโโ root.hcl
โโโ modules/
โ โโโ networking/
โ โ โโโ main.tf
โ โ โโโ variables.tf
โ โ โโโ outputs.tf
โ โ โโโ README.md
โ โโโ compute/
โโโ environments/
โ โโโ dev/
โ โโโ staging/
โ โโโ prod/
โโโ common/
Usage:
thothctl check project iac -p stack
thothctl check project iac -p stack -m strict
-p module)Single reusable Terraform modules with examples and documentation.
Typical Structure:
module/
โโโ .gitignore
โโโ .pre-commit-config.yaml
โโโ README.md
โโโ main.tf
โโโ variables.tf
โโโ outputs.tf
โโโ docs/
โโโ examples/
โ โโโ complete/
โ โโโ main.tf
โ โโโ variables.tf
โ โโโ outputs.tf
โ โโโ terraform.tfvars
โโโ test/
Usage:
cd modules/networking
thothctl check project iac -p module
-t structure)Validates folder and file structure against templates.
What it checks:
Example:
thothctl check project iac -t structure -p stack
-t metadata)Validates project metadata and configuration files.
What it checks:
Example:
thothctl check project iac -t metadata -p stack
-t compliance)Validates compliance with organizational standards.
What it checks:
Example:
thothctl check project iac -t compliance -p stack
-m soft)Reports issues but doesnโt fail the command (exit code 0).
Use cases:
thothctl check project iac -m soft
-m strict)Reports issues and fails with non-zero exit code if any issues found.
Use cases:
thothctl check project iac -m strict
Structure validation uses template files to define requirements:
Stack Template: src/thothctl/common/.thothcf_project.toml
[project_structure]
root_files = [
".gitignore",
".pre-commit-config.yaml",
"README.md",
"root.hcl"
]
[[project_structure.folders]]
name = "modules"
mandatory = true
type = "root"
content = [
"variables.tf",
"main.tf",
"outputs.tf",
"README.md"
]
Module Template: src/thothctl/common/.thothcf_module.toml
[project_structure]
root_files = [
".gitignore",
".pre-commit-config.yaml",
"README.md"
]
[[project_structure.folders]]
name = "examples"
mandatory = true
type = "child"
parent = "modules"
Override defaults by creating .thothcf.toml in your project root:
[thothcf]
project_type = "stack" # or "module"
[project_structure]
root_files = [
".gitignore",
"README.md",
"custom-file.txt"
]
[[project_structure.folders]]
name = "custom-folder"
mandatory = true
type = "root"
# Basic validation
thothctl check project iac -p stack
# Strict validation for CI/CD
thothctl check project iac -p stack -m strict
# Check specific aspect
thothctl check project iac -p stack -t compliance
# Navigate to module directory
cd modules/networking
# Validate module structure
thothctl check project iac -p module
# Strict validation
thothctl check project iac -p module -m strict
# During development (soft mode)
thothctl check project iac -p stack -m soft
# Before committing
thothctl check project iac -p stack -m strict
# Check specific module
cd modules/compute
thothctl check project iac -p module
The command provides rich formatted output with clear status indicators:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐๏ธ Infrastructure as Code Stack Structure Check โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
๐๏ธ Root Structure
โญโโโโโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโฎ
โ Item โ Type โ Required โ Status โ Details โ
โโโโโโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโค
โ modules โ ๐ โ Required โ โ
Pass โ . โ
โ environments โ ๐ โ Required โ โ
Pass โ . โ
โ README.md โ ๐ โ Required โ โ
Pass โ . โ
โฐโโโโโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโฏ
๐ Module Structure
โญโโโโโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโฎ
โ Item โ Type โ Required โ Status โ Details โ
โโโโโโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโค
โ main.tf โ ๐ โ Required โ โ
Pass โ modules/networking โ
โ variables.tf โ ๐ โ Required โ โ
Pass โ modules/networking โ
โ outputs.tf โ ๐ โ Required โ โ
Pass โ modules/networking โ
โฐโโโโโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโฏ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
IaC project structure validation passed โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
name: Validate IaC Structure
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install ThothCTL
run: pip install thothctl
- name: Validate Stack Structure
run: thothctl check project iac -p stack -m strict
validate-structure:
stage: validate
script:
- pip install thothctl
- thothctl check project iac -p stack -m strict
only:
- merge_requests
- main
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: thothctl-check-structure
name: Validate IaC Structure
entry: thothctl check project iac -p stack -m strict
language: system
pass_filenames: false
check iac| Aspect | check project iac |
check iac |
|---|---|---|
| Focus | Source code structure | Generated artifacts |
| Validates | Folders, files, organization | Plans, costs, dependencies |
| Input | Source .tf files | tfplan.json, graphs |
| When to use | Development, CI/CD | Pre-deployment analysis |
| Output | Structure validation | Analysis reports |
| Validation mode | --mode soft/strict |
N/A (informational only) |
| Exit on failure | Yes (in strict mode) | No (always informational) |
Use both commands together:
# 1. Validate source structure
thothctl check project iac -p stack -m strict
# 2. Generate plan
tofu plan -out=tfplan.bin
tofu show -json tfplan.bin > tfplan.json
# 3. Analyze artifacts
thothctl check iac -type tfplan
thothctl check iac -type cost-analysis
thothctl check iac -type blast-radius
โ - Required file main.tf missing in modules/networking
Solution: Add the missing file or update your .thothcf.toml configuration.
Error: Project type must be 'stack' or 'module'
Solution: Use -p stack or -p module option.
Using default options
Solution: This is informational. Create .thothcf.toml for custom configuration.
.thothcf.toml for project-specific requirements-p modulecheck project iac and check iac for comprehensive validation