Skip to content

Commit

Permalink
gruntwork-io#1944 Updated logic to resolve full path on includes (gru…
Browse files Browse the repository at this point in the history
…ntwork-io#1948)

* Added resolving of canonical path for included configs

* added test for parent inclusion

* Updated test for parent inclusion
  • Loading branch information
denis256 authored Dec 17, 2021
1 parent 5134c62 commit 5cf44f6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion configstack/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ func flagModulesThatDontInclude(modules []*TerraformModule, terragruntOptions *o
// as excluded, and if it includes any path in the set, we set the exclude flag back to false.
module.FlagExcluded = true
for _, includeConfig := range module.Config.ProcessedIncludes {
if util.ListContainsElement(modulesThatIncludeCanonicalPath, includeConfig.Path) {
// resolve include config to canonical path to compare with modulesThatIncludeCanonicalPath
// https://github.com/gruntwork-io/terragrunt/issues/1944
canonicalPath, err := util.CanonicalPath(includeConfig.Path, module.Path)
if err != nil {
return nil, err
}
if util.ListContainsElement(modulesThatIncludeCanonicalPath, canonicalPath) {
module.FlagExcluded = false
}
}
Expand Down
1 change: 1 addition & 0 deletions test/fixture-include-parent/app/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Intentionally empty
3 changes: 3 additions & 0 deletions test/fixture-include-parent/app/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include "parent" {
path = "../parent.hcl"
}
3 changes: 3 additions & 0 deletions test/fixture-include-parent/parent.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
parent_var = run_cmd("echo", "parent_hcl_file")
}
16 changes: 16 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const (
TEST_FIXTURE_PARALLELISM = "fixture-parallelism"
TEST_FIXTURE_SOPS = "fixture-sops"
TEST_FIXTURE_DESTROY_WARNING = "fixture-destroy-warning"
TEST_FIXTURE_INCLUDE_PARENT = "fixture-include-parent"
TERRAFORM_BINARY = "terraform"
TERRAFORM_FOLDER = ".terraform"
TERRAFORM_STATE = "terraform.tfstate"
Expand Down Expand Up @@ -3179,6 +3180,21 @@ func TestTerragruntValidateAllWithVersionChecks(t *testing.T) {
require.NoError(t, err)
}

func TestTerragruntIncludeParentHclFile(t *testing.T) {
t.Parallel()

tmpEnvPath := copyEnvironment(t, TEST_FIXTURE_INCLUDE_PARENT)

stdout := bytes.Buffer{}
stderr := bytes.Buffer{}

err := runTerragruntCommand(t, fmt.Sprintf("terragrunt run-all apply --terragrunt-modules-that-include parent.hcl --terragrunt-non-interactive --terragrunt-working-dir %s", tmpEnvPath), &stdout, &stderr)
require.NoError(t, err)

out := stderr.String()
assert.Equal(t, 1, strings.Count(out, "parent_hcl_file"))
}

func TestTerragruntVersionConstraints(t *testing.T) {
testCases := []struct {
name string
Expand Down

0 comments on commit 5cf44f6

Please sign in to comment.