Skip to content

Commit 861ec5b

Browse files
authored
Merge pull request #1633 from gruntwork-io/fix/terragrunt-cli-redesign
Upgrade Go to 1.24.0 and update terragrunt module for CLI redesign
2 parents 11fb9e7 + 45ba645 commit 861ec5b

File tree

12 files changed

+28
-36
lines changed

12 files changed

+28
-36
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env: &env
1010
TERRAGRUNT_VERSION: v0.80.4
1111
TERRAGRUNT_TEST_VERSION: v0.93.10 # Version used for terragrunt module tests
1212
OPA_VERSION: v1.1.0
13-
GO_VERSION: 1.21.1
13+
GO_VERSION: 1.24.0
1414
GO111MODULE: auto
1515
K8S_VERSION: v1.20.0 # Same as EKS
1616
MINIKUBE_VERSION: v1.22.0

modules/terraform/apply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ func ApplyE(t testing.TestingT, options *Options) (string, error) {
4949
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Apply, "apply", "-input=false", "-auto-approve")...)...)
5050
}
5151

52-
// TgApplyAllE runs terragrunt apply-all with the given options and return stdout/stderr. Note that this method does NOT call destroy and
52+
// TgApplyAllE runs terragrunt apply --all with the given options and return stdout/stderr. Note that this method does NOT call destroy and
5353
// assumes the caller is responsible for cleaning up any resources created by running apply.
5454
func TgApplyAllE(t testing.TestingT, options *Options) (string, error) {
5555
if options.TerraformBinary != "terragrunt" {
5656
return "", TgInvalidBinary(options.TerraformBinary)
5757
}
5858

59-
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Apply, "run-all", "apply", "-input=false", "-auto-approve")...)...)
59+
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Apply, "apply", "--all", "-input=false", "-auto-approve")...)...)
6060
}
6161

6262
// ApplyAndIdempotent runs terraform apply with the given options and return stdout/stderr from the apply command. It then runs

modules/terraform/cmd.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var commandsWithParallelism = []string{
3131
"apply",
3232
"destroy",
3333
"plan-all",
34-
"run-all",
3534
"apply-all",
3635
"destroy-all",
3736
}
@@ -55,17 +54,18 @@ func GetCommonOptions(options *Options, args ...string) (*Options, []string) {
5554
options.TerraformBinary = DefaultExecutable
5655
}
5756

57+
if options.Parallelism > 0 && len(args) > 0 && collections.ListContains(commandsWithParallelism, args[0]) {
58+
args = append(args, fmt.Sprintf("--parallelism=%d", options.Parallelism))
59+
}
60+
5861
if options.TerraformBinary == TerragruntDefaultPath {
59-
args = append(args, "--terragrunt-non-interactive")
62+
// Prepend --non-interactive as a global flag (must come before subcommand)
63+
args = append([]string{"--non-interactive"}, args...)
6064

6165
// for newer Terragrunt version, setting simplified log formatting
6266
setTerragruntLogFormatting(options)
6367
}
6468

65-
if options.Parallelism > 0 && len(args) > 0 && collections.ListContains(commandsWithParallelism, args[0]) {
66-
args = append(args, fmt.Sprintf("--parallelism=%d", options.Parallelism))
67-
}
68-
6969
// if SshAgent is provided, override the local SSH agent with the socket of our in-process agent
7070
if options.SshAgent != nil {
7171
// Initialize EnvVars, if it hasn't been set yet
@@ -217,8 +217,8 @@ func hasWarning(opts *Options, out string) error {
217217
// if it is not already set in options.EnvVars or OS environment vars
218218
func setTerragruntLogFormatting(options *Options) {
219219
const (
220-
tgLogFormatKey = "TERRAGRUNT_LOG_FORMAT"
221-
tgLogCustomFormatKey = "TERRAGRUNT_LOG_CUSTOM_FORMAT"
220+
tgLogFormatKey = "TG_LOG_FORMAT"
221+
tgLogCustomFormatKey = "TG_LOG_CUSTOM_FORMAT"
222222
)
223223

224224
if options.EnvVars == nil {

modules/terraform/destroy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func DestroyE(t testing.TestingT, options *Options) (string, error) {
2424
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Destroy, "destroy", "-auto-approve", "-input=false")...)...)
2525
}
2626

27-
// TgDestroyAllE runs terragrunt destroy with the given options and return stdout.
27+
// TgDestroyAllE runs terragrunt destroy --all with the given options and return stdout.
2828
func TgDestroyAllE(t testing.TestingT, options *Options) (string, error) {
2929
if options.TerraformBinary != "terragrunt" {
3030
return "", TgInvalidBinary(options.TerraformBinary)
3131
}
3232

33-
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Destroy, "run-all", "destroy", "-auto-approve", "-input=false")...)...)
33+
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Destroy, "destroy", "--all", "-auto-approve", "-input=false")...)...)
3434
}

modules/terraform/format.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/gruntwork-io/terratest/modules/collections"
1111
)
1212

13-
const runAllCmd = "run-all"
14-
1513
// TerraformCommandsWithLockSupport is a list of all the Terraform commands that
1614
// can obtain locks on Terraform state
1715
var TerraformCommandsWithLockSupport = []string{
@@ -42,12 +40,6 @@ var TerraformCommandsWithPlanFileSupport = []string{
4240
func FormatArgs(options *Options, args ...string) []string {
4341
var terraformArgs []string
4442
commandType := args[0]
45-
// If the user is trying to run with run-all, then we need to make sure the command based args are based on the
46-
// actual terraform command. E.g., we want to base the logic on `plan` when `run-all plan` is passed in, not
47-
// `run-all`.
48-
if commandType == runAllCmd {
49-
commandType = args[1]
50-
}
5143
lockSupported := collections.ListContains(TerraformCommandsWithLockSupport, commandType)
5244
planFileSupported := collections.ListContains(TerraformCommandsWithPlanFileSupport, commandType)
5345

modules/terraform/format_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func TestFormatArgsAppliesLockCorrectly(t *testing.T) {
9999
{[]string{"plan"}, []string{"plan", "-lock=false"}},
100100
{[]string{"validate"}, []string{"validate"}},
101101
{[]string{"plan-all"}, []string{"plan-all", "-lock=false"}},
102-
{[]string{"run-all", "validate"}, []string{"run-all", "validate"}},
103-
{[]string{"run-all", "plan"}, []string{"run-all", "plan", "-lock=false"}},
102+
{[]string{"validate", "--all"}, []string{"validate", "--all"}},
103+
{[]string{"plan", "--all"}, []string{"plan", "--all", "-lock=false"}},
104104
}
105105

106106
for _, testCase := range testCases {

modules/terraform/options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestExtraArgsHelp(t *testing.T) {
7878
},
7979
},
8080
{
81-
name: "validate-inputs",
81+
name: "hcl validate",
8282
fn: func() (string, error) {
8383
return ValidateInputsE(t, &Options{
8484
ExtraArgs: ExtraArgs{ValidateInputs: []string{"-help"}}, TerraformBinary: "terragrunt"})

modules/terraform/plan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ func TgPlanAllExitCode(t testing.TestingT, options *Options) int {
134134
return exitCode
135135
}
136136

137-
// TgPlanAllExitCodeE runs terragrunt plan-all with the given options and returns the detailed exitcode.
137+
// TgPlanAllExitCodeE runs terragrunt plan --all with the given options and returns the detailed exitcode.
138138
func TgPlanAllExitCodeE(t testing.TestingT, options *Options) (int, error) {
139139
if options.TerraformBinary != "terragrunt" {
140140
return 1, fmt.Errorf("terragrunt must be set as TerraformBinary to use this method")
141141
}
142142

143-
return GetExitCodeForTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Plan, "run-all", "plan", "--input=false",
143+
return GetExitCodeForTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Plan, "plan", "--all", "--input=false",
144144
"--lock=true", "--detailed-exitcode")...)...)
145145
}
146146

147-
// AssertTgPlanAllExitCode asserts the succuess (or failure) of a terragrunt run-all plan.
147+
// AssertTgPlanAllExitCode asserts the success (or failure) of a terragrunt plan --all.
148148
// On success, terragrunt will exit 0 on a plan that has previously been applied (has state)
149149
// and exit with 2 for plans that have never been applied when ran with `-detailed-exitcode`.
150150
func AssertTgPlanAllExitCode(t testing.TestingT, exitCode int, assertTrue bool) {

modules/terraform/validate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func Validate(t testing.TestingT, options *Options) string {
1212
return out
1313
}
1414

15-
// ValidateInputs calls terragrunt validate and returns stdout/stderr.
15+
// ValidateInputs calls terragrunt hcl validate and returns stdout/stderr.
1616
func ValidateInputs(t testing.TestingT, options *Options) string {
1717
out, err := ValidateInputsE(t, options)
1818
require.NoError(t, err)
@@ -24,12 +24,12 @@ func ValidateE(t testing.TestingT, options *Options) (string, error) {
2424
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.Validate, "validate")...)...)
2525
}
2626

27-
// ValidateInputsE calls terragrunt validate-inputs and returns stdout/stderr
27+
// ValidateInputsE calls terragrunt hcl validate and returns stdout/stderr
2828
func ValidateInputsE(t testing.TestingT, options *Options) (string, error) {
2929
if options.TerraformBinary != "terragrunt" {
3030
return "", TgInvalidBinary(options.TerraformBinary)
3131
}
32-
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.ValidateInputs, "validate-inputs")...)...)
32+
return RunTerraformCommandE(t, options, FormatArgs(options, prepend(options.ExtraArgs.ValidateInputs, "hcl", "validate")...)...)
3333
}
3434

3535
// InitAndValidate runs terraform init and validate with the given options and returns stdout/stderr from the validate command.
@@ -40,7 +40,7 @@ func InitAndValidate(t testing.TestingT, options *Options) string {
4040
return out
4141
}
4242

43-
// InitAndValidateInputs runs terragrunt init and validate-inputs with the given options and returns stdout/stderr from the validate command.
43+
// InitAndValidateInputs runs terragrunt init and hcl validate with the given options and returns stdout/stderr from the validate command.
4444
func InitAndValidateInputs(t testing.TestingT, options *Options) string {
4545
out, err := InitAndValidateInputsE(t, options)
4646
require.NoError(t, err)
@@ -56,7 +56,7 @@ func InitAndValidateE(t testing.TestingT, options *Options) (string, error) {
5656
return ValidateE(t, options)
5757
}
5858

59-
// InitAndValidateInputsE runs terragrunt init and validate with the given options and returns stdout/stderr
59+
// InitAndValidateInputsE runs terragrunt init and hcl validate with the given options and returns stdout/stderr
6060
func InitAndValidateInputsE(t testing.TestingT, options *Options) (string, error) {
6161
if _, err := InitE(t, options); err != nil {
6262
return "", err

modules/test-structure/test_structure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func ValidateAllTerraformModules(t *go_test.T, opts *ValidationOptions) {
157157
tfOpts.TerraformBinary = "terragrunt"
158158
// First call init and terraform validate
159159
terraform.InitAndValidate(t, tfOpts)
160-
// Next, call terragrunt validate-inputs which will catch mis-aligned inputs provided via Terragrunt
160+
// Next, call terragrunt hcl validate which will catch mis-aligned inputs provided via Terragrunt
161161
terraform.ValidateInputs(t, tfOpts)
162162
} else if fileType == TF {
163163
terraform.InitAndValidate(t, tfOpts)

0 commit comments

Comments
 (0)