| name | terraform-validate |
| description | Validate Terraform modules and configurations across CP infrastructure repos. Use when checking Terraform code, reviewing infrastructure changes, or verifying module consistency. |
Terraform Validate
Validates Terraform modules and configurations across CP infrastructure repositories for consistency, security, and best practices.
When to Use
- User asks to "validate terraform", "check this module", "review infrastructure changes"
- User is modifying a
cpp-terraform-* or cpp-module-terraform-* repo
- User wants to verify state backend configuration
- User wants to check variable naming conventions across modules
Process
Step 1: Identify Module Type
| Prefix | Type | Purpose |
|---|
cpp-module-terraform-azurerm-* | Reusable module | Shared building blocks consumed by other Terraform repos |
cpp-terraform-azurerm-* | Root module | Environment-specific infrastructure provisioning |
cpp-terraform-network | Network | VNet, subnet, NSG, peering configuration |
cpp-automation-terraform | Automation | Terraform automation and orchestration |
Step 2: Validate Structure
Every Terraform repo should have:
├── main.tf # Primary resource definitions
├── variables.tf # Input variable declarations
├── outputs.tf # Output value declarations
├── versions.tf # Provider and Terraform version constraints
├── README.md # Auto-generated by terraform-docs
├── .pre-commit-config.yaml # Pre-commit hooks
├── .terraform-version # tfversion pinning
└── vars/ # Environment-specific tfvars (root modules only)
├── dev.tfvars
├── sit.tfvars
├── ste.tfvars
├── nft.tfvars
├── prp.tfvars
└── prd.tfvars
Step 3: Validation Checks
Variable Declarations
Resource Configuration
State Backend
Security
Pre-commit Hooks
Step 4: Environment Consistency
For root modules with per-environment tfvars:
- Read all
vars/*.tfvars files
- Verify each environment defines the same set of variables
- Flag any environment-specific variables missing from other environments
- Check that production values are appropriately different from non-prod (e.g., larger SKUs, more replicas)
Step 5: Module Dependency Check
For root modules that consume reusable modules:
- Check
module blocks for source references
- Verify module versions are pinned (not
ref=main)
- Check if newer versions of consumed modules are available
- Verify required input variables are provided
Step 6: Generate Report
## Terraform Validation Report: [module-name]
### Structure
- [✅/❌] Standard file layout
- [✅/❌] Pre-commit hooks configured
- [✅/❌] README auto-generated
### Variables
| Name | Type | Description | Sensitive | Default | Status |
|------|------|-------------|-----------|---------|--------|
### Security
- [✅/❌] No hardcoded secrets
- [✅/❌] Private endpoints used
- [✅/❌] Managed identities preferred
### Environment Consistency
| Variable | dev | sit | ste | nft | prp | prd |
|----------|-----|-----|-----|-----|-----|-----|
### Issues
- [severity] [description] — suggested fix
CP-Specific Infrastructure Patterns
AKS Clusters
- System + Worker + Prometheus node pools
- Azure CNI networking with Calico network policy
- OIDC issuer enabled for workload identity
- Cluster naming:
{env}-cs{stack}cl{cluster}
PostgreSQL
- Flexible Server (not single server)
- Per-context databases (hearing_db, resulting_db, etc.)
- Admin credentials from Key Vault
- Read-only user for reporting (
pgreadonly)
Service Bus
- Per-environment namespace
- Topics per bounded context
- Dead-letter queues configured
- Max delivery count and TTL set per subscription
Key Vault
- Per-environment vaults
- CSI driver for pod secret injection
- Secret rotation enabled