Skip to content

Monorepos

Using TerraTidy in repositories with multiple Terraform modules.

Setup

Initialize a monorepo configuration:

terratidy init --monorepo

This creates a .terratidy.yaml with:

  • Central ./policies directory for shared OPA policies
  • ci profile (all engines enabled)
  • development profile (lint and policy disabled for speed)

Config Placement

Place .terratidy.yaml at the repository root. TerraTidy processes files relative to the current working directory:

repo/
  .terratidy.yaml          # Root config
  policies/                # Shared OPA policies
  modules/
    networking/
      main.tf
      variables.tf
    compute/
      main.tf
      variables.tf
  environments/
    staging/
      main.tf
    production/
      main.tf

Running Checks

Specific modules

terratidy check ./modules/networking
terratidy check ./modules/compute

All modules

terratidy check ./modules ./environments

Changed files only

terratidy check --changed

This checks all modified .tf/.hcl/.tfvars files across the entire repo.

Profile-Based Workflows

Local development (fast)

terratidy check --profile development

CI/CD (thorough)

terratidy check --profile ci --parallel

Production deployment gate

terratidy check --profile ci --severity-threshold error

Module Overrides

Override rules for specific modules using config imports:

# .terratidy.yaml
version: 1

imports:
  - ./modules/networking/.terratidy-overrides.yaml

engines:
  style:
    enabled: true
# modules/networking/.terratidy-overrides.yaml
overrides:
  rules:
    style.terraform-files-structure:
      enabled: false  # Networking module uses a different structure

CI Integration

Run checks per module in parallel CI jobs:

# GitHub Actions
strategy:
  matrix:
    module: [networking, compute, database, iam]

steps:
  - uses: actions/checkout@v4
  - uses: santosr2/terratidy@v0
    with:
      working-directory: modules/${{ matrix.module }}
      profile: ci