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
- Click into the repository where you want to enable monorepo support.
- In the Overview tab, locate the Directories section (default is set to the root directory
.). - 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.tforbackend.tffile in the directory tree to identify the project root.
CDK Projects (TypeScript)
- Supports
.tsfiles. - Uses the presence of a
cdktf.jsonfile 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.jsonIf 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
. 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.tfAnd 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, orcdktf.jsonfiles 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.jsonThen:
β
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
| Setup | PR Changes App Code Only | PR Changes Any TF Code | PR 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.
Updated 9 days ago
