Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/gruntwork-io/terragrunt/cli"
"github.com/gruntwork-io/terragrunt/cli/commands"
awsproviderpatch "github.com/gruntwork-io/terragrunt/cli/commands/aws-provider-patch"
"github.com/gruntwork-io/terragrunt/cli/commands/hclfmt"
outputmodulegroups "github.com/gruntwork-io/terragrunt/cli/commands/output-module-groups"
"github.com/gruntwork-io/terragrunt/cli/commands/run"
runall "github.com/gruntwork-io/terragrunt/cli/commands/run-all"
Expand Down Expand Up @@ -285,8 +284,8 @@ func TestFilterTerragruntArgs(t *testing.T) {
{[]string{"plan", doubleDashed(global.NonInteractiveFlagName)}, []string{"plan"}},
{[]string{"plan", doubleDashed(run.InputsDebugFlagName)}, []string{"plan"}},
{[]string{"plan", doubleDashed(global.NonInteractiveFlagName), "-bar", doubleDashed(global.WorkingDirFlagName), "/some/path", "--baz", doubleDashed(run.ConfigFlagName), "/some/path/" + config.DefaultTerragruntConfigPath}, []string{"plan", "-bar", "-baz"}},
{[]string{commands.CommandNameApplyAll, "plan", "bar"}, []string{tf.CommandNameApply, "plan", "bar"}},
{[]string{commands.CommandNameDestroyAll, "plan", "-foo", "--bar"}, []string{tf.CommandNameDestroy, "plan", "-foo", "-bar"}},
{[]string{commands.CommandApplyAllName, "plan", "bar"}, []string{tf.CommandNameApply, "plan", "bar"}},
{[]string{commands.CommandDestroyAllName, "plan", "-foo", "--bar"}, []string{tf.CommandNameDestroy, "plan", "-foo", "-bar"}},
}

for i, tc := range testCases {
Expand All @@ -312,22 +311,22 @@ func TestParseMultiStringArg(t *testing.T) {
expectedVals []string
}{
{
args: []string{commands.CommandNameApplyAll, flagName, "bar"},
args: []string{commands.CommandApplyAllName, flagName, "bar"},
defaultValue: []string{"default_bar"},
expectedVals: []string{"bar"},
},
{
args: []string{commands.CommandNameApplyAll, "--test", "bar"},
args: []string{commands.CommandApplyAllName, "--test", "bar"},
defaultValue: []string{"default_bar"},
expectedVals: []string{"default_bar"},
},
{
args: []string{commands.CommandNamePlanAll, "--test", "value", flagName, "bar1", flagName, "bar2"},
args: []string{commands.CommandPlanAllName, "--test", "value", flagName, "bar1", flagName, "bar2"},
defaultValue: []string{"default_bar"},
expectedVals: []string{"bar1", "bar2"},
},
{
args: []string{commands.CommandNamePlanAll, "--test", "value", flagName, "bar1", flagName},
args: []string{commands.CommandPlanAllName, "--test", "value", flagName, "bar1", flagName},
defaultValue: []string{"default_bar"},
expectedErr: argMissingValueError(run.UnitsThatIncludeFlagName),
},
Expand Down Expand Up @@ -465,10 +464,10 @@ func TestTerragruntHelp(t *testing.T) {
{
args: []string{"terragrunt", awsproviderpatch.CommandName, "-h"},
expected: run.ConfigFlagName,
notExpected: hclfmt.CommandName,
notExpected: commands.CommandHCLFmtName,
},
{
args: []string{"terragrunt", commands.CommandNamePlanAll, "--help"},
args: []string{"terragrunt", commands.CommandPlanAllName, "--help"},
expected: runall.CommandName,
},
}
Expand Down Expand Up @@ -574,7 +573,7 @@ func TestAutocomplete(t *testing.T) { //nolint:paralleltest
}{
{
"",
[]string{"graph-dependencies", "hclfmt", "output-module-groups", "render-json", "run-all", "terragrunt-info", "validate-inputs"},
[]string{"graph-dependencies", "hcl", "output-module-groups", "render-json", "run-all", "terragrunt-info"},
},
{
"--versio",
Expand All @@ -597,7 +596,7 @@ func TestAutocomplete(t *testing.T) { //nolint:paralleltest
opts := options.NewTerragruntOptionsWithWriters(output, os.Stderr)
app := cli.NewApp(opts)

app.Commands = app.Commands.FilterByNames([]string{"graph-dependencies", "hclfmt", "output-module-groups", "render-json", "run-all", "terragrunt-info", "validate-inputs"})
app.Commands = app.Commands.FilterByNames([]string{"graph-dependencies", "hcl", "output-module-groups", "render-json", "run-all", "terragrunt-info"})

err := app.Run([]string{"terragrunt"})
require.NoError(t, err)
Expand Down
6 changes: 0 additions & 6 deletions cli/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/gruntwork-io/terragrunt/options"

"github.com/gruntwork-io/terragrunt/cli/commands/graph"
"github.com/gruntwork-io/terragrunt/cli/commands/hclvalidate"
helpCmd "github.com/gruntwork-io/terragrunt/cli/commands/help"
versionCmd "github.com/gruntwork-io/terragrunt/cli/commands/version"

Expand All @@ -23,13 +22,11 @@ import (
"github.com/gruntwork-io/terragrunt/cli/commands/catalog"
execCmd "github.com/gruntwork-io/terragrunt/cli/commands/exec"
graphdependencies "github.com/gruntwork-io/terragrunt/cli/commands/graph-dependencies"
"github.com/gruntwork-io/terragrunt/cli/commands/hclfmt"
outputmodulegroups "github.com/gruntwork-io/terragrunt/cli/commands/output-module-groups"
renderjson "github.com/gruntwork-io/terragrunt/cli/commands/render-json"
runCmd "github.com/gruntwork-io/terragrunt/cli/commands/run"
runall "github.com/gruntwork-io/terragrunt/cli/commands/run-all"
terragruntinfo "github.com/gruntwork-io/terragrunt/cli/commands/terragrunt-info"
validateinputs "github.com/gruntwork-io/terragrunt/cli/commands/validate-inputs"
"github.com/gruntwork-io/terragrunt/internal/cli"
)

Expand Down Expand Up @@ -87,9 +84,6 @@ func New(opts *options.TerragruntOptions) cli.Commands {
configurationCommands := cli.Commands{
graphdependencies.NewCommand(opts), // graph-dependencies
outputmodulegroups.NewCommand(opts), // output-module-groups
validateinputs.NewCommand(opts), // validate-inputs
hclvalidate.NewCommand(opts), // hclvalidate
hclfmt.NewCommand(opts), // hclfmt
hcl.NewCommand(opts), // hcl
info.NewCommand(opts), // info
dag.NewCommand(opts), // dag
Expand Down
53 changes: 30 additions & 23 deletions cli/commands/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ package commands
import (
"fmt"

"github.com/gruntwork-io/terragrunt/cli/commands/hcl"
"github.com/gruntwork-io/terragrunt/cli/commands/hcl/format"
"github.com/gruntwork-io/terragrunt/cli/commands/hcl/validate"
"github.com/gruntwork-io/terragrunt/cli/commands/run"
runall "github.com/gruntwork-io/terragrunt/cli/commands/run-all"
"github.com/gruntwork-io/terragrunt/internal/cli"
Expand All @@ -14,49 +17,53 @@ import (

// The following commands are DEPRECATED
const (
CommandNameSpinUp = "spin-up"
CommandNameTearDown = "tear-down"
CommandNamePlanAll = "plan-all"
CommandNameApplyAll = "apply-all"
CommandNameDestroyAll = "destroy-all"
CommandNameOutputAll = "output-all"
CommandNameValidateAll = "validate-all"
CommandSpinUpName = "spin-up"
CommandTearDownName = "tear-down"
CommandPlanAllName = "plan-all"
CommandApplyAllName = "apply-all"
CommandDestroyAllName = "destroy-all"
CommandOutputAllName = "output-all"
CommandValidateAllName = "validate-all"

CommandHCLFmtName = "hclfmt"
CommandHCLValidateName = "hclvalidate"
CommandValidateInputsName = "validate-inputs"
)

// deprecatedCommands is a map of deprecated commands to a handler that knows how to convert the command to the known
// alternative. The handler should return the new TerragruntOptions (if any modifications are needed) and command
// string.
var replaceDeprecatedCommandsFuncs = map[string]replaceDeprecatedCommandFuncType{
CommandNameSpinUp: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNameApply),
CommandNameTearDown: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNameDestroy),
CommandNameApplyAll: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNameApply),
CommandNameDestroyAll: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNameDestroy),
CommandNamePlanAll: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNamePlan),
CommandNameValidateAll: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNameValidate),
CommandNameOutputAll: replaceDeprecatedCommandFunc(runall.CommandName, tf.CommandNameOutput),
CommandSpinUpName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNameApply}),
CommandTearDownName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNameDestroy}),
CommandApplyAllName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNameApply}),
CommandDestroyAllName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNameDestroy}),
CommandPlanAllName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNamePlan}),
CommandValidateAllName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNameValidate}),
CommandOutputAllName: replaceDeprecatedCommandFunc(controls.LegacyAll, cli.Args{runall.CommandName, tf.CommandNameOutput}),
CommandHCLFmtName: replaceDeprecatedCommandFunc(controls.CLIRedesign, cli.Args{hcl.CommandName, format.CommandName}),
CommandHCLValidateName: replaceDeprecatedCommandFunc(controls.CLIRedesign, cli.Args{hcl.CommandName, validate.CommandName}),
CommandValidateInputsName: replaceDeprecatedCommandFunc(controls.CLIRedesign, cli.Args{hcl.CommandName, validate.CommandName, "--" + validate.InputsFlagName}),
}

type replaceDeprecatedCommandFuncType func(opts *options.TerragruntOptions, deprecatedCommandName string) cli.ActionFunc

// replaceDeprecatedCommandFunc returns the `Action` function of the replacement command that is assigned to the deprecated command.
func replaceDeprecatedCommandFunc(terragruntCommandName, terraformCommandName string) replaceDeprecatedCommandFuncType {
func replaceDeprecatedCommandFunc(strictControlName string, args cli.Args) replaceDeprecatedCommandFuncType {
return func(opts *options.TerragruntOptions, deprecatedCommandName string) cli.ActionFunc {
newCommandFriendly := fmt.Sprintf("terragrunt %s %s", terragruntCommandName, terraformCommandName)
newCommandName := fmt.Sprintf("terragrunt %s", args)

control := controls.NewDeprecatedCommand(deprecatedCommandName, newCommandFriendly)
opts.StrictControls.FilterByNames(controls.DeprecatedCommands, controls.LegacyAll, deprecatedCommandName).AddSubcontrolsToCategory(controls.RunAllCommandsCategoryName, control)
control := controls.NewDeprecatedCommand(deprecatedCommandName, newCommandName)
opts.StrictControls.FilterByNames(controls.DeprecatedCommands, strictControlName, deprecatedCommandName).AddSubcontrolsToCategory(controls.RunAllCommandsCategoryName, control)

return func(ctx *cli.Context) error {
command := ctx.App.Commands.Get(terragruntCommandName)
args := append([]string{terraformCommandName}, ctx.Args().Slice()...)

if err := control.Evaluate(ctx); err != nil {
return cli.NewExitError(err, cli.ExitCodeGeneralError)
}

err := command.Run(ctx, args)
args := append(args, ctx.Args().Slice()...)

return err
return ctx.App.NewRootCommand().Run(ctx, args)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions cli/commands/graph/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
awsproviderpatch "github.com/gruntwork-io/terragrunt/cli/commands/aws-provider-patch"
"github.com/gruntwork-io/terragrunt/cli/commands/common/graph"
graphdependencies "github.com/gruntwork-io/terragrunt/cli/commands/graph-dependencies"
"github.com/gruntwork-io/terragrunt/cli/commands/hclfmt"
renderjson "github.com/gruntwork-io/terragrunt/cli/commands/render-json"
"github.com/gruntwork-io/terragrunt/cli/commands/run"
terragruntinfo "github.com/gruntwork-io/terragrunt/cli/commands/terragrunt-info"
validateinputs "github.com/gruntwork-io/terragrunt/cli/commands/validate-inputs"
"github.com/gruntwork-io/terragrunt/internal/cli"
"github.com/gruntwork-io/terragrunt/options"
)
Expand Down Expand Up @@ -49,9 +47,7 @@ func action(opts *options.TerragruntOptions) cli.ActionFunc {
func subCommands(opts *options.TerragruntOptions) cli.Commands {
cmds := cli.Commands{
terragruntinfo.NewCommand(opts), // terragrunt-info
validateinputs.NewCommand(opts), // validate-inputs
graphdependencies.NewCommand(opts), // graph-dependencies
hclfmt.NewCommand(opts), // hclfmt
renderjson.NewCommand(opts), // render-json
awsproviderpatch.NewCommand(opts), // aws-provider-patch
}
Expand Down
20 changes: 15 additions & 5 deletions cli/commands/hcl/format/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,49 @@ func NewFlags(opts *options.TerragruntOptions, prefix flags.Prefix) cli.Flags {
Destination: &opts.HclFile,
Usage: "The path to a single HCL file that the command should run on.",
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-file"), terragruntPrefixControl)),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-file"), terragruntPrefixControl), // `TG_HCLFMT_FILE`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-file"), terragruntPrefixControl), // `--terragrunt-hclfmt-file`, `TERRAGRUNT_HCLFMT_FILE`
),

flags.NewFlag(&cli.SliceFlag[string]{
Name: ExcludeDirFlagName,
EnvVars: tgPrefix.EnvVars(ExcludeDirFlagName),
Destination: &opts.HclExclude,
Usage: "Skip HCL formatting in given directories.",
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-exclude-dir"), terragruntPrefixControl)),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-exclude-dir"), terragruntPrefixControl), // `TG_HCLFMT_EXCLUDE_DIR`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-exclude-dir"), terragruntPrefixControl), // `--terragrunt-hclfmt-exclude-dir`, `TERRAGRUNT_EXCLUDE_DIR`
),

flags.NewFlag(&cli.BoolFlag{
Name: CheckFlagName,
EnvVars: tgPrefix.EnvVars(CheckFlagName),
Destination: &opts.Check,
Usage: "Return a status code of zero when all files are formatted correctly, and a status code of one when they aren't.",
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("check"), terragruntPrefixControl)),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-check"), terragruntPrefixControl), // `TG_HCLFMT_CHECK`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("check"), terragruntPrefixControl), // `--terragrunt-check`, `TERRAGRUNT_CHECK`
),

flags.NewFlag(&cli.BoolFlag{
Name: DiffFlagName,
EnvVars: tgPrefix.EnvVars(DiffFlagName),
Destination: &opts.Diff,
Usage: "Print diff between original and modified file versions.",
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("diff"), terragruntPrefixControl)),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl), // `TG_HCLFMT_DIFF`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("diff"), terragruntPrefixControl), // `--terragrunt-diff`, `TERRAGRUNT_DIFF`
),

flags.NewFlag(&cli.BoolFlag{
Name: StdinFlagName,
EnvVars: tgPrefix.EnvVars(StdinFlagName),
Destination: &opts.HclFromStdin,
Usage: "Format HCL from stdin and print result to stdout.",
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl)),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl), // `TG_HCLFMT_STDIN`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN`
),
Comment on lines +73 to +75
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect environment variable name for stdin flag

There's an error in the environment variable name for the stdin flag: it's using "hclfmt-diff" instead of "hclfmt-stdin".

Apply this correction:

- flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl),          // `TG_HCLFMT_STDIN`
+ flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-stdin"), terragruntPrefixControl),         // `TG_HCLFMT_STDIN`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-diff"), terragruntPrefixControl), // `TG_HCLFMT_STDIN`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN`
),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclfmt-stdin"), terragruntPrefixControl), // `TG_HCLFMT_STDIN`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclfmt-stdin"), terragruntPrefixControl), // `--terragrunt-hclfmt-stdin`, `TERRAGRUNT_HCLFMT_STDIN`
),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you my friend. You are the best!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levkohimins You're welcome! Glad I could help. Always happy to spot these small details to ensure everything works correctly. Let me know if you need any other assistance with your PR.

}

return flags
Expand Down
25 changes: 17 additions & 8 deletions cli/commands/hcl/validate/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ func NewFlags(opts *options.TerragruntOptions, prefix flags.Prefix) cli.Flags {
Destination: &opts.HCLValidateStrict,
Usage: "Enables strict mode. When used in combination with the `--inputs` flag, any inputs defined in Terragrunt that are _not_ used in OpenTofu/Terraform will trigger an error.",
},
flags.WithDeprecatedNames(tgPrefix.FlagNames("strict-validate"), terragruntPrefixControl),
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("strict-validate"), terragruntPrefixControl)),
flags.WithDeprecatedFlagName("strict-validate", terragruntPrefixControl), // `--strict-validate`
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars(
"strict-validate", // `TG_STRICT_VALIDATE`
"hclvalidate-strict-validate", // `TG_HCLVALIDATE_STRICT_VALIDATE`
), terragruntPrefixControl),
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("strict-validate"), terragruntPrefixControl), // `--terragrunt-strict-validate`, `TERRAGRUNT_STRICT_VALIDATE`
),

flags.NewFlag(&cli.BoolFlag{
Name: InputsFlagName,
Expand All @@ -44,26 +49,30 @@ func NewFlags(opts *options.TerragruntOptions, prefix flags.Prefix) cli.Flags {
Usage: "Emit a list of files with invalid configurations after validating all configurations.",
Destination: &opts.HCLValidateShowConfigPath,
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclvalidate-show-config-path"), terragruntPrefixControl)),

flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclvalidate-strict-validate"), terragruntPrefixControl), // `TG_HCLVALIDATE_STRICT_VALIDATE`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclvalidate-show-config-path"), terragruntPrefixControl), // `--terragrunt-hclvalidate-show-config-path`, `TERRAGRUNT_HCLVALIDATE_SHOW_CONFIG_PATH`
),

flags.NewFlag(&cli.BoolFlag{
Name: JSONFlagName,
EnvVars: tgPrefix.EnvVars(JSONFlagName),
Destination: &opts.HCLValidateJSONOutput,
Usage: "Format results in JSON format.",
},
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclvalidate-json"), terragruntPrefixControl)),
flags.WithDeprecatedEnvVars(tgPrefix.EnvVars("hclvalidate-json"), terragruntPrefixControl), // `TG_HCLVALIDATE_JSON`
flags.WithDeprecatedNames(terragruntPrefix.FlagNames("hclvalidate-json"), terragruntPrefixControl), // `--terragrunt-hclvalidate-json`, `TERRAGRUNT_HCLVALIDATE_JSON`
),
}

return flagSet
}

func NewCommand(opts *options.TerragruntOptions) *cli.Command {
cmd := &cli.Command{
Name: CommandName,
Usage: "Recursively find HashiCorp Configuration Language (HCL) files and validate them.",
Flags: NewFlags(opts, nil),
ErrorOnUndefinedFlag: true,
Name: CommandName,
Usage: "Recursively find HashiCorp Configuration Language (HCL) files and validate them.",
Flags: NewFlags(opts, nil),
Action: func(ctx *cli.Context) error {
return Run(ctx, opts.OptionsFromContext(ctx))
},
Expand Down
32 changes: 0 additions & 32 deletions cli/commands/hclfmt/cli.go

This file was deleted.

Loading
Loading