Skip to content

Commit dfaff13

Browse files
committed
fix get_terragrunt_dir when using stack
1 parent d291c0c commit dfaff13

File tree

7 files changed

+201
-201
lines changed

7 files changed

+201
-201
lines changed

config/config_helpers.go

Lines changed: 88 additions & 106 deletions
Large diffs are not rendered by default.

config/stack.go

Lines changed: 71 additions & 69 deletions
Large diffs are not rendered by default.

test/fixtures/stacks/terragrunt-dir/live/root.hcl

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
unit "unit_a" {
2+
source = "../../unit_a"
3+
path = "unit_a"
4+
values = {
5+
terragrunt_dir = get_terragrunt_dir()
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "terragrunt_dir" {}
2+
3+
output "terragrunt_dir" {
4+
value = var.terragrunt_dir
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
include "root" {
3+
path = find_in_parent_folders("root.hcl")
4+
}
5+
6+
terraform {
7+
source = "."
8+
}
9+
10+
inputs = {
11+
terragrunt_dir = values.terragrunt_dir
12+
}

test/integration_stacks_test.go

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
testFixtureStackSelfInclude = "fixtures/stacks/self-include"
4848
testFixtureStackNestedOutputs = "fixtures/stacks/nested-outputs"
4949
testFixtureStackNoValidation = "fixtures/stacks/no-validation"
50+
testFixtureStackTerragruntDir = "fixtures/stacks/terragrunt-dir"
5051
)
5152

5253
func TestStacksGenerateBasic(t *testing.T) {
@@ -249,32 +250,6 @@ func TestStacksApplyClean(t *testing.T) {
249250
assert.NoDirExists(t, path)
250251
}
251252

252-
func TestStackCleanRecursively(t *testing.T) {
253-
t.Parallel()
254-
255-
helpers.CleanupTerraformFolder(t, testFixtureNestedStacks)
256-
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureNestedStacks)
257-
gitPath := util.JoinPath(tmpEnvPath, testFixtureNestedStacks)
258-
helpers.CreateGitRepo(t, gitPath)
259-
live := util.JoinPath(gitPath, "live")
260-
261-
_, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt stack generate --working-dir "+live)
262-
require.NoError(t, err)
263-
264-
liveV2 := util.JoinPath(gitPath, "live-v2")
265-
_, _, err = helpers.RunTerragruntCommandWithOutput(t, "terragrunt stack generate --working-dir "+liveV2)
266-
require.NoError(t, err)
267-
268-
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt stack clean --working-dir "+gitPath)
269-
require.NoError(t, err)
270-
271-
assert.NoDirExists(t, util.JoinPath(live, ".terragrunt-stack"))
272-
assert.NoDirExists(t, util.JoinPath(liveV2, ".terragrunt-stack"))
273-
274-
assert.Contains(t, stderr, "Deleting stack directory: live/.terragrunt-stack")
275-
assert.Contains(t, stderr, "Deleting stack directory: live-v2/.terragrunt-stack")
276-
}
277-
278253
func TestStacksDestroy(t *testing.T) {
279254
t.Parallel()
280255

@@ -1275,3 +1250,20 @@ func validateStackDir(t *testing.T, path string) {
12751250

12761251
assert.True(t, hasSubdirectories, "The .terragrunt-stack directory should contain at least one subdirectory")
12771252
}
1253+
1254+
func TestStackTerragruntDir(t *testing.T) {
1255+
t.Parallel()
1256+
1257+
helpers.CleanupTerraformFolder(t, testFixtureStackTerragruntDir)
1258+
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureStackTerragruntDir)
1259+
gitPath := util.JoinPath(tmpEnvPath, testFixtureStackTerragruntDir)
1260+
helpers.CreateGitRepo(t, gitPath)
1261+
rootPath := util.JoinPath(gitPath, "live")
1262+
1263+
_, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt stack generate --no-stack-validate --working-dir "+rootPath)
1264+
require.NoError(t, err)
1265+
1266+
out, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply --all --non-interactive --working-dir "+rootPath)
1267+
require.NoError(t, err)
1268+
assert.Contains(t, out, `terragrunt_dir = "./tennant_1"`)
1269+
}

0 commit comments

Comments
 (0)