Skip to content

Commit 0b64605

Browse files
authored
Merge branch 'main' into feature/modularize-terragrunt
2 parents 6452bdf + ac5ebc1 commit 0b64605

16 files changed

+110
-112
lines changed

modules/terragrunt/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,17 @@ Work with standard terragrunt configurations (dependencies via `dependency` bloc
8888
- `ApplyAll(t, options)` - Apply all modules with dependencies
8989
- `DestroyAll(t, options)` - Destroy all modules with dependencies
9090
- `PlanAllExitCode(t, options)` - Plan all and return exit code (0=no changes, 2=changes)
91-
- `TgInit(t, options)` - Initialize configuration
91+
- `Init(t, options)` - Initialize configuration
9292

9393
### Stack Commands
9494
Work with `terragrunt.stack.hcl` configurations:
9595

96-
- `TgStackGenerate(t, options)` - Generate stack from stack.hcl
97-
- `TgStackRun(t, options)` - Run command on generated stack
98-
- `TgStackClean(t, options)` - Remove .terragrunt-stack directory
99-
- `TgOutput(t, options, key)` - Get stack output value
100-
- `TgOutputJson(t, options, key)` - Get stack output as JSON
101-
- `TgOutputAll(t, options)` - Get all stack outputs as map
102-
103-
> **Note**: Function naming is inconsistent - run-all commands lack the `Tg` prefix while stack commands have it. This is for historical reasons.
96+
- `StackGenerate(t, options)` - Generate stack from stack.hcl
97+
- `StackRun(t, options)` - Run command on generated stack
98+
- `StackClean(t, options)` - Remove .terragrunt-stack directory
99+
- `Output(t, options, key)` - Get stack output value
100+
- `OutputJson(t, options, key)` - Get stack output as JSON
101+
- `OutputAll(t, options)` - Get all stack outputs as map
104102

105103
## Examples
106104

@@ -135,7 +133,7 @@ func TestWithCustomArgs(t *testing.T) {
135133
TerraformArgs: []string{"-upgrade"},
136134
}
137135

138-
terragrunt.TgInit(t, options)
136+
terragrunt.Init(t, options)
139137
}
140138
```
141139

@@ -153,11 +151,11 @@ func TestStackOutput(t *testing.T) {
153151
defer terragrunt.DestroyAll(t, options)
154152

155153
// Get specific output
156-
vpcID := terragrunt.TgOutput(t, options, "vpc_id")
154+
vpcID := terragrunt.Output(t, options, "vpc_id")
157155
assert.NotEmpty(t, vpcID)
158156

159157
// Get all outputs
160-
outputs := terragrunt.TgOutputAll(t, options)
158+
outputs := terragrunt.OutputAll(t, options)
161159
assert.Contains(t, outputs, "vpc_id")
162160
}
163161
```

modules/terragrunt/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/gruntwork-io/terratest/modules/testing"
1111
)
1212

13-
// runTerragruntStackCommandE executes tg stack commands
13+
// runTerragruntStackCommandE executes terragrunt stack commands
1414
// It handles argument construction, retry logic, and error handling for all stack commands
1515
func runTerragruntStackCommandE(
1616
t testing.TestingT, opts *Options, subCommand string, additionalArgs ...string) (string, error) {

modules/terragrunt/cmd_args_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestTerragruntArgsIncluded(t *testing.T) {
2525
}
2626

2727
// Run init - if TerragruntArgs work, we should only see error-level logs
28-
output, err := TgInitE(t, options)
28+
output, err := InitE(t, options)
2929
require.NoError(t, err)
3030

3131
// With --log-level error, we shouldn't see info-level messages
@@ -51,7 +51,7 @@ func TestTerraformArgsIncluded(t *testing.T) {
5151
}
5252

5353
// Run init with -backend=false flag
54-
output, err := TgInitE(t, options)
54+
output, err := InitE(t, options)
5555
require.NoError(t, err)
5656

5757
// With -backend=false, we should NOT see backend initialization messages
@@ -112,7 +112,7 @@ func TestCombinedArgsOrdering(t *testing.T) {
112112
}
113113

114114
// Run init - both args should be passed in the correct order
115-
output, err := TgInitE(t, options)
115+
output, err := InitE(t, options)
116116
require.NoError(t, err)
117117

118118
// Verify TerragruntArgs effect: should not see info-level logs
@@ -258,7 +258,7 @@ func TestEnvVarsPropagation(t *testing.T) {
258258
}
259259

260260
// Run init - should succeed with env vars set
261-
output, err := TgInitE(t, options)
261+
output, err := InitE(t, options)
262262
require.NoError(t, err)
263263
require.NotEmpty(t, output)
264264
// With TG_LOG_LEVEL=error, should not see info logs

modules/terragrunt/init.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import (
55
"github.com/gruntwork-io/terratest/modules/testing"
66
)
77

8-
// TgInit calls tg init and return stdout/stderr
9-
func TgInit(t testing.TestingT, options *Options) string {
10-
out, err := TgInitE(t, options)
8+
// Init calls terragrunt init and return stdout/stderr
9+
func Init(t testing.TestingT, options *Options) string {
10+
out, err := InitE(t, options)
1111
if err != nil {
1212
t.Fatal(err)
1313
}
1414
return out
1515
}
1616

17-
// TgInitE calls tg init and return stdout/stderr
18-
func TgInitE(t testing.TestingT, options *Options) (string, error) {
19-
// Use regular tg init command (not tg stack init)
17+
// InitE calls terragrunt init and return stdout/stderr
18+
func InitE(t testing.TestingT, options *Options) (string, error) {
19+
// Use regular terragrunt init command (not terragrunt stack init)
2020
return runTerragruntCommandE(t, options, "init", initArgs(options)...)
2121
}
2222

23-
// initArgs builds the argument list for tg init command.
23+
// initArgs builds the argument list for terragrunt init command.
2424
// This function handles complex configuration that requires special formatting.
2525
func initArgs(options *Options) []string {
2626
var args []string

modules/terragrunt/init_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
func TestTgInit(t *testing.T) {
11+
func TestInit(t *testing.T) {
1212
t.Parallel()
1313

1414
testFolder, err := files.CopyTerraformFolderToTemp(
1515
"../../test/fixtures/terragrunt/terragrunt-no-error", t.Name())
1616
require.NoError(t, err)
1717

18-
out, err := TgInitE(t, &Options{
18+
out, err := InitE(t, &Options{
1919
TerragruntDir: testFolder,
2020
TerragruntBinary: "terragrunt",
2121
TerraformArgs: []string{"-upgrade=true"}, // Common terraform init flag
@@ -24,15 +24,15 @@ func TestTgInit(t *testing.T) {
2424
require.Contains(t, out, "Terraform has been successfully initialized!")
2525
}
2626

27-
func TestTgInitWithInvalidConfig(t *testing.T) {
27+
func TestInitWithInvalidConfig(t *testing.T) {
2828
t.Parallel()
2929
// Test error handling when tg.hcl has invalid HCL syntax
3030
testFolder, err := files.CopyTerraformFolderToTemp(
3131
"../../test/fixtures/terragrunt/terragrunt-stack-init-error", t.Name())
3232
require.NoError(t, err)
3333

3434
// This should fail due to invalid HCL syntax in tg.hcl
35-
_, err = TgInitE(t, &Options{
35+
_, err = InitE(t, &Options{
3636
TerragruntDir: testFolder,
3737
TerragruntBinary: "terragrunt",
3838
TerraformArgs: []string{"-upgrade=true"}, // Common terraform init flag
@@ -42,8 +42,8 @@ func TestTgInitWithInvalidConfig(t *testing.T) {
4242
require.Contains(t, err.Error(), "Missing expression")
4343
}
4444

45-
// TestTgInitWithBothArgTypes verifies init works with both TerragruntArgs and TerraformArgs
46-
func TestTgInitWithBothArgTypes(t *testing.T) {
45+
// TestInitWithBothArgTypes verifies init works with both TerragruntArgs and TerraformArgs
46+
func TestInitWithBothArgTypes(t *testing.T) {
4747
t.Parallel()
4848

4949
testFolder, err := files.CopyTerraformFolderToTemp(
@@ -57,7 +57,7 @@ func TestTgInitWithBothArgTypes(t *testing.T) {
5757
TerraformArgs: []string{"-upgrade"},
5858
}
5959

60-
output, err := TgInitE(t, options)
60+
output, err := InitE(t, options)
6161
require.NoError(t, err)
6262
// Verify TerragruntArgs: no info logs
6363
require.NotContains(t, output, "level=info")

modules/terragrunt/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// Example:
1818
//
1919
// // For init with terraform flags
20-
// TgInitE(t, &Options{
20+
// InitE(t, &Options{
2121
// TerragruntDir: "/path/to/config",
2222
// TerragruntArgs: []string{"--log-level", "info"},
2323
// TerraformArgs: []string{"-upgrade=true"},

modules/terragrunt/plan_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestTgPlanAllNoError(t *testing.T) {
3030
t.Fatal(errExitCode)
3131
}
3232

33-
// Since PlanAllExitCodeTgE returns error codes, we want to compare against 1
33+
// Since PlanAllExitCodeE returns error codes, we want to compare against 1
3434
require.Equal(t, 0, getExitCode)
3535
}
3636

@@ -52,7 +52,7 @@ func TestTgPlanAllWithError(t *testing.T) {
5252
require.Equal(t, 1, getExitCode)
5353
}
5454

55-
func TestAssertTgPlanAllExitCodeNoError(t *testing.T) {
55+
func TestAssertPlanAllExitCodeNoError(t *testing.T) {
5656
t.Parallel()
5757

5858
testFolder, err := files.CopyTerragruntFolderToTemp("../../test/fixtures/terragrunt/terragrunt-multi-plan", t.Name())
@@ -84,7 +84,7 @@ func TestAssertTgPlanAllExitCodeNoError(t *testing.T) {
8484
assertPlanAllExitCode(t, getExitCode, true)
8585
}
8686

87-
func TestAssertTgPlanAllExitCodeWithError(t *testing.T) {
87+
func TestAssertPlanAllExitCodeWithError(t *testing.T) {
8888
t.Parallel()
8989

9090
testFolder, err := files.CopyTerragruntFolderToTemp("../../test/fixtures/terragrunt/terragrunt-with-plan-error", t.Name())

modules/terragrunt/stack_clean.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import (
44
"github.com/gruntwork-io/terratest/modules/testing"
55
)
66

7-
// TgStackClean calls tg stack clean to remove the .terragrunt-stack directory
7+
// StackClean calls terragrunt stack clean to remove the .terragrunt-stack directory
88
// This command cleans up the generated stack files created by stack generate or stack run
9-
func TgStackClean(t testing.TestingT, options *Options) string {
10-
out, err := TgStackCleanE(t, options)
9+
func StackClean(t testing.TestingT, options *Options) string {
10+
out, err := StackCleanE(t, options)
1111
if err != nil {
1212
t.Fatal(err)
1313
}
1414
return out
1515
}
1616

17-
// TgStackCleanE calls tg stack clean to remove the .terragrunt-stack directory
17+
// StackCleanE calls terragrunt stack clean to remove the .terragrunt-stack directory
1818
// This command cleans up the generated stack files created by stack generate or stack run
19-
func TgStackCleanE(t testing.TestingT, options *Options) (string, error) {
19+
func StackCleanE(t testing.TestingT, options *Options) (string, error) {
2020
return runTerragruntStackCommandE(t, options, "clean")
2121
}

modules/terragrunt/stack_clean_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
func TestTgStackClean(t *testing.T) {
11+
func TestStackClean(t *testing.T) {
1212
t.Parallel()
1313

1414
testFolder, err := files.CopyTerraformFolderToTemp(
@@ -18,7 +18,7 @@ func TestTgStackClean(t *testing.T) {
1818
stackDir := path.Join(testFolder, "live", ".terragrunt-stack")
1919

2020
// First generate the stack to create .terragrunt-stack directory
21-
_, err = TgStackGenerateE(t, &Options{
21+
_, err = StackGenerateE(t, &Options{
2222
TerragruntDir: path.Join(testFolder, "live"),
2323
TerragruntBinary: "terragrunt",
2424
})
@@ -28,7 +28,7 @@ func TestTgStackClean(t *testing.T) {
2828
require.DirExists(t, stackDir)
2929

3030
// Clean the stack
31-
out, err := TgStackCleanE(t, &Options{
31+
out, err := StackCleanE(t, &Options{
3232
TerragruntDir: path.Join(testFolder, "live"),
3333
TerragruntBinary: "terragrunt",
3434
})
@@ -41,7 +41,7 @@ func TestTgStackClean(t *testing.T) {
4141
require.NoDirExists(t, stackDir)
4242
}
4343

44-
func TestTgStackCleanNonExistentStack(t *testing.T) {
44+
func TestStackCleanNonExistentStack(t *testing.T) {
4545
t.Parallel()
4646

4747
testFolder, err := files.CopyTerraformFolderToTemp(
@@ -54,14 +54,14 @@ func TestTgStackCleanNonExistentStack(t *testing.T) {
5454
require.NoDirExists(t, stackDir)
5555

5656
// Clean should succeed even if .terragrunt-stack doesn't exist
57-
_, err = TgStackCleanE(t, &Options{
57+
_, err = StackCleanE(t, &Options{
5858
TerragruntDir: path.Join(testFolder, "live"),
5959
TerragruntBinary: "terragrunt",
6060
})
6161
require.NoError(t, err)
6262
}
6363

64-
func TestTgStackCleanAfterRun(t *testing.T) {
64+
func TestStackCleanAfterRun(t *testing.T) {
6565
t.Parallel()
6666

6767
testFolder, err := files.CopyTerraformFolderToTemp(
@@ -71,15 +71,15 @@ func TestTgStackCleanAfterRun(t *testing.T) {
7171
stackDir := path.Join(testFolder, "live", ".terragrunt-stack")
7272

7373
// Initialize the stack
74-
_, err = TgInitE(t, &Options{
74+
_, err = InitE(t, &Options{
7575
TerragruntDir: path.Join(testFolder, "live"),
7676
TerragruntBinary: "terragrunt",
7777
TerraformArgs: []string{"-upgrade=true"},
7878
})
7979
require.NoError(t, err)
8080

8181
// Run plan to generate the stack
82-
_, err = TgStackRunE(t, &Options{
82+
_, err = StackRunE(t, &Options{
8383
TerragruntDir: path.Join(testFolder, "live"),
8484
TerragruntBinary: "terragrunt",
8585
TerraformArgs: []string{"plan"},
@@ -90,7 +90,7 @@ func TestTgStackCleanAfterRun(t *testing.T) {
9090
require.DirExists(t, stackDir)
9191

9292
// Clean the stack
93-
out, err := TgStackCleanE(t, &Options{
93+
out, err := StackCleanE(t, &Options{
9494
TerragruntDir: path.Join(testFolder, "live"),
9595
TerragruntBinary: "terragrunt",
9696
})

modules/terragrunt/stack_generate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"github.com/gruntwork-io/terratest/modules/testing"
55
)
66

7-
// TgStackGenerate calls tg stack generate and returns stdout/stderr
8-
func TgStackGenerate(t testing.TestingT, options *Options) string {
9-
out, err := TgStackGenerateE(t, options)
7+
// StackGenerate calls terragrunt stack generate and returns stdout/stderr
8+
func StackGenerate(t testing.TestingT, options *Options) string {
9+
out, err := StackGenerateE(t, options)
1010
if err != nil {
1111
t.Fatal(err)
1212
}
1313
return out
1414
}
1515

16-
// TgStackGenerateE calls tg stack generate and returns stdout/stderr
17-
func TgStackGenerateE(t testing.TestingT, options *Options) (string, error) {
16+
// StackGenerateE calls terragrunt stack generate and returns stdout/stderr
17+
func StackGenerateE(t testing.TestingT, options *Options) (string, error) {
1818
return runTerragruntStackCommandE(t, options, "generate")
1919
}

0 commit comments

Comments
 (0)