Filters Configuration
Filter modules using include and exclude patterns.
Options
exclude
Type: string[]Default: []
Glob patterns for modules to exclude.
exclude:
- "*/test/*"
- "*/sandbox/*"
- "*/.terraform/*"include
Type: string[]Default: [] (all modules)
Glob patterns for modules to include. If empty, all modules are included (after excludes).
include:
- "platform/*/*/*"
- "analytics/*/*/*"Pattern Syntax
TerraCi uses glob patterns with these special characters:
| Pattern | Matches |
|---|---|
* | Any characters except / |
** | Any characters including / (any depth) |
? | Single character |
[abc] | Character class |
[!abc] | Negated character class |
Examples
Exclude Test Modules
exclude:
- "*/test/*"
- "*/tests/*"
- "*-test/*/*/*"Exclude Specific Environment
exclude:
- "*/sandbox/*"
- "*/development/*"Exclude Specific Region
exclude:
- "*/*/eu-north-1/*"Only Production
include:
- "*/production/*/*"Only Specific Service
include:
- "platform/*/*/*"Exclude Submodules
exclude:
- "*/*/*/*/*" # Exclude depth 5Only Submodules
include:
- "*/*/*/*/*" # Include only depth 5CLI Overrides
Override filters from command line:
# Add excludes
terraci generate --exclude "*/test/*" --exclude "*/sandbox/*"
# Add includes
terraci generate --include "platform/*/*/*"
# Filter by field
terraci generate --service platform
terraci generate --environment production
terraci generate --region us-east-1Filter Order
Filters are applied in this order:
- Discovery - Find all modules at correct depth
- Exclude - Remove modules matching exclude patterns
- Include - If set, keep only modules matching include patterns
- CLI Filters - Apply service/environment/region filters
Field-Based Filters
Filter by module fields via CLI:
# By service
terraci generate --service platform
# By environment
terraci generate --environment production
# By region
terraci generate --region us-east-1
# Combined
terraci generate --service platform --environment production --region us-east-1Combining Filters
Filters can be combined:
exclude:
- "*/sandbox/*"
- "*/test/*"
include:
- "platform/*/*/*"
- "analytics/*/*/*"This:
- Excludes all sandbox and test modules
- Then includes only platform and analytics modules
Use Cases
Production Pipeline
exclude:
- "*/sandbox/*"
- "*/test/*"
- "*/development/*"
include:
- "*/production/*/*"Regional Deployment
Generate pipeline for specific region:
terraci generate --region us-east-1Or in config:
include:
- "*/*/us-east-1/*"Service-Specific Pipeline
terraci generate --service platformExclude Specific Modules
exclude:
- "platform/production/us-east-1/legacy-vpc"
- "analytics/*/*/deprecated-*"Debugging Filters
See which modules are included:
terraci validate -vOutput:
Discovered 20 modules
After exclude patterns: 15 modules
After include patterns: 10 modules
Final module count: 10
Modules:
- platform/production/us-east-1/vpc
- platform/production/us-east-1/eks
...Wildcards in Paths
Single Level (*)
include:
- "platform/*/us-east-1/*" # Any environment, only us-east-1Matches:
platform/production/us-east-1/vpcplatform/staging/us-east-1/vpc
Multi-Level (**)
include:
- "platform/**" # All platform modules at any depthMatches:
platform/production/us-east-1/vpcplatform/production/us-east-1/ec2/rabbitmq
Library Modules
Library modules (also called shared modules) are reusable Terraform modules that don't have their own providers or remote state - they are used by executable modules via the module block.
Configuration
library_modules:
paths:
- "_modules"
- "shared/modules"How It Works
When you configure library_modules.paths, TerraCi:
- Parses module blocks in executable modules to find local module calls (
source = "../_modules/kafka") - Tracks library dependencies in the dependency graph
- Detects library changes when using
--changed-onlymode - Includes affected modules when a library module is modified
Example Structure
terraform/
├── _modules/ # Library modules
│ ├── kafka/ # Reusable Kafka configuration
│ │ └── main.tf
│ └── kafka_acl/ # Kafka ACL module (depends on kafka)
│ └── main.tf
├── platform/
│ └── production/
│ └── eu-north-1/
│ └── msk/ # Executable module using _modules/kafka
│ └── main.tfIn platform/production/eu-north-1/msk/main.tf:
module "kafka" {
source = "../../../../_modules/kafka"
# ...
}
module "kafka_acl" {
source = "../../../../_modules/kafka_acl"
# ...
}Change Detection
When you modify _modules/kafka/main.tf:
terraci generate --changed-onlyTerraCi will include platform/production/eu-north-1/msk in the pipeline because it uses the kafka library module.
Transitive Dependencies
If kafka_acl library module uses kafka module internally, and you modify kafka, all modules using kafka_acl will also be detected as affected.
Verbose Output
Use verbose mode to see library module detection:
terraci generate --changed-only -vOutput:
Changed library modules: 1
- /project/_modules/kafka
Affected modules (including dependents): 3
- platform/production/eu-north-1/msk
- platform/production/eu-north-1/streaming
- platform/production/eu-west-1/mskExample
See the library-modules example for a complete working example.