A tool that analyzes Terraform configurations and identifies directories that need to be executed based on Git changes.
tftargets
scans your repository for Terraform configurations and determines which directories contain changes that require Terraform execution. It:
- Finds all directories containing
.tf
files withterraform
blocks - Analyzes module dependencies within those directories
- Compares against Git changes from a base branch
- Outputs a JSON array of directories that need attention
This is particularly useful in CI/CD pipelines where you want to run Terraform only on changed modules rather than all modules.
go install github.com/takaishi/tftargets/cmd/tftargets@latest
- uses: takaishi/tftargets@v1
with:
version: latest
tftargets
tftargets --base-branch main --base-dir . --search-path .
--base-branch
: Base branch for Git comparison (default: "main")--base-dir
: Base directory for the repository (default: ".")--search-path
: Path to search for Terraform files (default: ".")--version
: Show version information
LOG_LEVEL
: Set logging level (DEBUG, INFO, WARN, ERROR)
["/path/to/terraform/module1", "/path/to/terraform/module2"]
- CI/CD Optimization: Only run Terraform on changed modules
- Selective Planning: Generate plans only for affected infrastructure
- Module Dependency Analysis: Understand which modules are impacted by changes