Setting up monorepo support


πŸ“ Monorepo Terraform/CDK Support in Terracotta AI

Terracotta AI now supports monorepos with multiple infrastructure projects in a single repository. Whether you're managing a mix of Terraform and CDK (TypeScript) projects or multiple independent infrastructure stacks, Terracotta AI has you covered.


βš™οΈ Setting Up Monorepo Support

  1. Click into the repository where you want to enable monorepo support.
  2. In the Overview tab, locate the Directories section (default is set to the root directory .).
  3. To configure subdirectories:
    • Edit or delete the root directory first.
    • Click New Directory, then provide a Name and the sub-directory path.

That’s it! Terracotta AI will now automatically detect which directory has a new incoming PR and run specifically on the configured subdirectory.


πŸš€ How It Works

If Terracotta AI is already installed in your repository, no extra configuration is needed. When you open a pull request, Terracotta AI will:

  • Automatically detect which infrastructure projects are affected by the changes.
  • Begin reviewing the changes in parallel across all detected projects.
  • Drop a comment right away to let you know it’s analyzing.
πŸ“

Example PR comment:

Terracotta AI is analyzing your changes… hang tight!


🧠 Project Detection

Terracotta AI intelligently detects the root of each project based on changed files:

Terraform Projects

  • Looks for a main.tf or backend.tf file in the directory tree to identify the project root.

CDK Projects (TypeScript)

  • Supports .ts files.
  • Uses the presence of a cdktf.json file to locate the CDK project root.

If your PR touches both Terraform and CDK projects in the same repo, Terracotta AI will run separate reviews for each and post results accordingly.


βœ… Example Use Case

infrastructure/
β”œβ”€β”€ terraform-ecs/
β”‚   └── main.tf
β”œβ”€β”€ cdk-s3/
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   └── bucket.ts
β”‚   └── cdktf.json

If a PR changes both main.tf and bucket.ts, Terracotta AI will detect the Terraform and CDK projects independently and review each in context within the PR.


🧭 Choosing Between Root . and Sub-Directories

βœ… Mixed Repos (App + Infra Code Together)

If your repository contains both application and Terraform/CDK code, for example:

repo/
β”œβ”€β”€ frontend/
β”œβ”€β”€ backend/
β”œβ”€β”€ infra/        # contains main.tf

And you want Terracotta AI to trigger only when Terraform/CDK code is changed, then:

βœ”οΈ Leave the . (root directory) selected in the Terracotta AI UI.

  • Terracotta AI will only trigger if .tf, .ts, or cdktf.json files are changed.
  • App-only PRs will be skipped.
  • The root directory . acts as a catch-all for infrastructure across the entire repo.

βœ… Infra-Only Monorepos (Multiple Independent Stacks)

If your repository is dedicated to infrastructure, with multiple independent Terraform or CDK subprojects like:

infrastructure/
β”œβ”€β”€ prod-networking/
β”‚   └── main.tf
β”œβ”€β”€ staging-app/
β”‚   └── main.tf
β”œβ”€β”€ shared-databases/
β”‚   └── cdktf.json

Then:

βœ… Remove the . root directory and configure each subdirectory individually in the Terracotta AI UI.

  • Terracotta AI will only run if a PR modifies files in one of the configured subdirectories.
  • This improves performance, limits noise, and provides fine-grained ownership across teams.

πŸ” Behavior Comparison

SetupPR Changes App Code OnlyPR Changes Any TF CodePR Changes TF in Specific Subdir
. (root dir) configured❌ Skippedβœ… Triggersβœ… Triggers
Only subdirs configured❌ Skipped❌ Skippedβœ… Triggers if subdir matches

πŸ§ͺ Real-World Scenario: Mixed Repos with Optional Subdirectory Setup

In a repo where application and Terraform code coexist, if you attach the repo and leave . as the directory level:

Terracotta AI will not trigger unless the PR changes Terraform/CDK files.

This makes the root . a great default for mixed repos β€” it filters out irrelevant app PRs while ensuring infra changes are still reviewed.

However, if you remove the root . and instead add individual subdirectories, Terracotta AI will:

  • Only trigger when a PR modifies one of the listed subdirectories, and
  • Only if the files are Terraform (.tf) or CDK-TK TypeScript (.ts + cdktf.json)

This setup offers tighter control β€” especially useful in large monorepos or repos with multiple isolated infra projects.