terramate-io / terramate

Terramate CLI is an open-source Infrastructure as Code (IaC) Orchestration and Code Generation tool for Terraform, OpenTofu and Terragrunt.
https://terramate.io
Mozilla Public License 2.0
3.28k stars 92 forks source link

[BUG] no changes detected in stack if base Terraform module is changed in previous commit #1959

Open AJCandfield opened 3 days ago

AJCandfield commented 3 days ago

Describe the bug

terramate doesn't detect changes to a base module while calculating changed terragrunt stacks.

To Reproduce

While using terramate with terragrunt, if there are changes to files in the directory of a base module, I would like a deployment to be triggered where said module is used.

For example, if I modify files in the directory ~/code/iac/terraform/modules/gcp/artifact-registry-repository and generate a commit with those changes, the following deployment should be listed in the terramate list --changed command.

# ~/code/iac/terraform/clouds/gcp/dev/dev0/europe-west1/project0/_resources/gar/iac/terragrunt.hcl

terraform { source = "${get_repo_root()}/terraform//modules/gcp/artifact-registry-repository" }

include "root" { path = find_in_parent_folders() }

#...
# ~/code/iac/terraform/clouds/gcp/dev/dev0/europe-west1/projec0/_resources/gar/iac/stack.tm.hcl

stack {
  name        = "iac"
  description = "iac"
  id          = "4c9c7bd4-7538-4f30-9c98-e7bcf1a999e8"
}

Expected behavior

I would like to see the following output from terramate list --changed:

terraform/clouds/gcp/dev/dev0/europe-west1/service0-poc/_resources/gar/iac

Log Output

terramate list -c --log-level debug -v
2024-11-19T10:34:00Z DBG Get git version. action=Version() workingDir=/Users/user/code/iac
2024-11-19T10:34:00Z DBG Set defaults. action=setDefaults() workingDir=/Users/user/code/iac
2024-11-19T10:34:00Z DBG Handle command. action=run() cmd=list workingDir=/Users/user/code/iac
2024-11-19T10:34:00Z DBG `git status --porcelain` output action=ListDirtyFiles() stdout= workingDir=/Users/user/code/iac
2024-11-19T10:34:00Z DBG untracked files action=ListDirtyFiles() untracked=[] workingDir=/Users/user/code/iac
2024-11-19T10:34:00Z DBG uncommitted files action=ListDirtyFiles() uncommitted=[] workingDir=/Users/user/code/iac

Environment (please complete the following information):

Additional context

Changes in current branch:

git diff --name-only main
terraform/modules/gcp/artifact-registry-repository/main.tf

If I change the path to plain (below) instead of using the terragrunt function, the change detection works:

  source = "../../../../../../../../..//modules/gcp/artifact-registry-repository"