From 7df9ab44b09dba0faa35d888e68ec298e963468b Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Mon, 26 Jul 2021 18:20:15 -0400 Subject: [PATCH 01/14] Introduce --terragrunt-strict flag for validate-inputs --- cli/args.go | 3 +++ cli/cli_app.go | 3 +++ cli/validate_inputs.go | 8 +++++--- options/options.go | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/args.go b/cli/args.go index 026bf5b45..270168739 100644 --- a/cli/args.go +++ b/cli/args.go @@ -149,6 +149,8 @@ func parseTerragruntOptionsFromArgs(terragruntVersion string, args []string, wri return nil, err } + strictMode := parseBooleanArg(args, OPT_TERRAGRUNT_STRICT, false) + opts, err := options.NewTerragruntOptions(filepath.ToSlash(terragruntConfigPath)) if err != nil { return nil, err @@ -177,6 +179,7 @@ func parseTerragruntOptionsFromArgs(terragruntVersion string, args []string, wri opts.WorkingDir = filepath.ToSlash(workingDir) opts.DownloadDir = filepath.ToSlash(downloadDir) opts.LogLevel = loggingLevel + opts.Strict = strictMode opts.Logger = util.CreateLogEntry("", loggingLevel) opts.Logger.Logger.SetOutput(errWriter) opts.RunTerragrunt = RunTerragrunt diff --git a/cli/cli_app.go b/cli/cli_app.go index c8a2d1dc0..8b615fa4f 100644 --- a/cli/cli_app.go +++ b/cli/cli_app.go @@ -50,6 +50,7 @@ const OPT_TERRAGRUNT_HCLFMT_FILE = "terragrunt-hclfmt-file" const OPT_TERRAGRUNT_DEBUG = "terragrunt-debug" const OPT_TERRAGRUNT_OVERRIDE_ATTR = "terragrunt-override-attr" const OPT_TERRAGRUNT_LOGLEVEL = "terragrunt-log-level" +const OPT_TERRAGRUNT_STRICT = "terragrunt-strict" var ALL_TERRAGRUNT_BOOLEAN_OPTS = []string{ OPT_NON_INTERACTIVE, @@ -79,6 +80,7 @@ var ALL_TERRAGRUNT_STRING_OPTS = []string{ OPT_TERRAGRUNT_HCLFMT_FILE, OPT_TERRAGRUNT_OVERRIDE_ATTR, OPT_TERRAGRUNT_LOGLEVEL, + OPT_TERRAGRUNT_STRICT, } const CMD_INIT = "init" @@ -235,6 +237,7 @@ GLOBAL OPTIONS: terragrunt-override-attr A key=value attribute to override in a provider block as part of the aws-provider-patch command. May be specified multiple times. terragrunt-debug Write terragrunt-debug.tfvars to working folder to help root-cause issues. terragrunt-log-level Sets the logging level for Terragrunt. Supported levels: panic, fatal, error, warn (default), info, debug, trace. + terragrunt-strict Sets strict mode for the validate-inputs command. By default, strict mode is off. When this flag is passed, strict mode is turned on. When strict mode is turned off, the validate-inputs command will only return an error if required inputs are missing from all input sources (env vars, var files, etc). When strict mode is turned on, an error will be returned if required inputs are missing OR if unused variables are passed to Terragrunt. VERSION: {{.Version}}{{if len .Authors}} diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index e73d335e6..00acc714a 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -66,9 +66,11 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work terragruntOptions.Logger.Info("All required inputs are passed in by terragrunt.") } - // Return an error when there are misaligned inputs. - if len(unusedVars) > 0 || len(missingVars) > 0 { - return fmt.Errorf("Terragrunt configuration has misaligned inputs") + // Return an error when there are misaligned inputs. Terragrunt strict mode defaults to false. When it is false, + // an error will only be returned if required inputs are missing. When strict mode is true, an error will be + // returned if required inputs are missing OR if any unused variables are passed + if len(missingVars) > 0 || len(unusedVars) > 0 && terragruntOptions.Strict { + return fmt.Errorf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t", terragruntOptions.Strict) } return nil } diff --git a/options/options.go b/options/options.go index 1a99cce45..a504bb98c 100644 --- a/options/options.go +++ b/options/options.go @@ -86,6 +86,9 @@ type TerragruntOptions struct { // Log level LogLevel logrus.Level + // Strict mode for the validate-inputs command + Strict bool + // Environment variables at runtime Env map[string]string @@ -197,6 +200,7 @@ func NewTerragruntOptions(terragruntConfigPath string) (*TerragruntOptions, erro WorkingDir: workingDir, Logger: logger, LogLevel: DEFAULT_LOG_LEVEL, + Strict: false, Env: map[string]string{}, Source: "", SourceMap: map[string]string{}, From 6e27bec50d03eaa0965d58b9049aae49e0fb004f Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Mon, 26 Jul 2021 18:47:36 -0400 Subject: [PATCH 02/14] Add test cases flexing --terragrunt-strict --- test/integration_debug_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/integration_debug_test.go b/test/integration_debug_test.go index 331af8fbf..a73b0d5ef 100644 --- a/test/integration_debug_test.go +++ b/test/integration_debug_test.go @@ -103,6 +103,30 @@ func TestTerragruntValidateInputsWithCLIVarFile(t *testing.T) { runTerragruntValidateInputs(t, moduleDir, args, true) } +func TestTerragruntValidateInputsWithStrictMode(t *testing.T) { + t.Parallel() + + moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") + args := []string{"--terragrunt-strict"} + runTerragruntValidateInputs(t, moduleDir, args, true) +} + +func TestTerragruntValidateInputsWithStrictModeDisabledAndUnusedVar(t *testing.T) { + t.Parallel() + + moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") + args := []string{"-var=testvariable=testvalue"} + runTerragruntValidateInputs(t, moduleDir, args, true) +} + +func TestTerragruntValidateInputsWithStrictModeEnabledAndUnusedVar(t *testing.T) { + t.Parallel() + + moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") + args := []string{"-var=testvariable=testvalue", "--terragrunt-strict"} + runTerragruntValidateInputs(t, moduleDir, args, false) +} + func runTerragruntValidateInputs(t *testing.T, moduleDir string, extraArgs []string, isSuccessTest bool) { maybeNested := filepath.Join(moduleDir, "module") if util.FileExists(maybeNested) { From eaae8aa2511cdf913bdcbed75b02cebc33d0949f Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Mon, 26 Jul 2021 19:01:38 -0400 Subject: [PATCH 03/14] Add more test cases --- test/integration_debug_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/integration_debug_test.go b/test/integration_debug_test.go index a73b0d5ef..95380ebb3 100644 --- a/test/integration_debug_test.go +++ b/test/integration_debug_test.go @@ -127,6 +127,22 @@ func TestTerragruntValidateInputsWithStrictModeEnabledAndUnusedVar(t *testing.T) runTerragruntValidateInputs(t, moduleDir, args, false) } +func TestTerragruntValidateInputsWithStrictModeEnabledAndUnusedInputs(t *testing.T) { + t.Parallel() + + moduleDir := filepath.Join("fixture-validate-inputs", "fail-unused-inputs") + args := []string{"--terragrunt-strict"} + runTerragruntValidateInputs(t, moduleDir, args, false) +} + +func TestTerragruntValidateInputsWithStrictModeDisabledAndUnusedInputs(t *testing.T) { + t.Parallel() + + moduleDir := filepath.Join("fixture-validate-inputs", "fail-unused-inputs") + args := []string{} + runTerragruntValidateInputs(t, moduleDir, args, true) +} + func runTerragruntValidateInputs(t *testing.T, moduleDir string, extraArgs []string, isSuccessTest bool) { maybeNested := filepath.Join(moduleDir, "module") if util.FileExists(maybeNested) { From 8ff6b3820ae9041b07c333abdc2130edb27ac3ce Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Mon, 26 Jul 2021 19:21:54 -0400 Subject: [PATCH 04/14] Pass --terragrunt-strict to fix test --- test/integration_serial_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration_serial_test.go b/test/integration_serial_test.go index 50e90a607..7ad7b1251 100644 --- a/test/integration_serial_test.go +++ b/test/integration_serial_test.go @@ -205,7 +205,8 @@ func TestTerragruntValidateInputsWithUnusedEnvVar(t *testing.T) { defer os.Unsetenv("TF_VAR_unused") moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") - runTerragruntValidateInputs(t, moduleDir, nil, false) + args := []string{"--terragrunt-strict"} + runTerragruntValidateInputs(t, moduleDir, args, false) } func TestTerragruntSourceMapEnvArg(t *testing.T) { From 9c16e42f04b099c7a6d8746f716192cdc755c9f3 Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Tue, 27 Jul 2021 17:55:20 -0400 Subject: [PATCH 05/14] Pass --terragrunt-strict in TestTerragruntValidateInputs --- test/integration_debug_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration_debug_test.go b/test/integration_debug_test.go index 95380ebb3..7f99348cf 100644 --- a/test/integration_debug_test.go +++ b/test/integration_debug_test.go @@ -150,7 +150,7 @@ func runTerragruntValidateInputs(t *testing.T, moduleDir string, extraArgs []str moduleDir = maybeNested } - cmd := fmt.Sprintf("terragrunt validate-inputs %s --terragrunt-log-level debug --terragrunt-non-interactive --terragrunt-working-dir %s", strings.Join(extraArgs, " "), moduleDir) + cmd := fmt.Sprintf("terragrunt validate-inputs %s --terragrunt-strict --terragrunt-log-level debug --terragrunt-non-interactive --terragrunt-working-dir %s", strings.Join(extraArgs, " "), moduleDir) t.Logf("Command: %s", cmd) _, _, err := runTerragruntCommandWithOutput(t, cmd) if isSuccessTest { From 3dfafaa26f9469627da1baffd393a140d932b4bb Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Tue, 27 Jul 2021 18:15:50 -0400 Subject: [PATCH 06/14] Pass --terragrunt-strict from TestTerragruntValidateInputs --- test/integration_debug_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration_debug_test.go b/test/integration_debug_test.go index 7f99348cf..c148c8c5e 100644 --- a/test/integration_debug_test.go +++ b/test/integration_debug_test.go @@ -79,7 +79,7 @@ func TestTerragruntValidateInputs(t *testing.T) { t.Parallel() nameDashSplit := strings.Split(name, "-") - runTerragruntValidateInputs(t, module, nil, nameDashSplit[0] == "success") + runTerragruntValidateInputs(t, module, []string{"--terragrunt-strict"}, nameDashSplit[0] == "success") }) } } @@ -150,7 +150,7 @@ func runTerragruntValidateInputs(t *testing.T, moduleDir string, extraArgs []str moduleDir = maybeNested } - cmd := fmt.Sprintf("terragrunt validate-inputs %s --terragrunt-strict --terragrunt-log-level debug --terragrunt-non-interactive --terragrunt-working-dir %s", strings.Join(extraArgs, " "), moduleDir) + cmd := fmt.Sprintf("terragrunt validate-inputs %s --terragrunt-log-level debug --terragrunt-non-interactive --terragrunt-working-dir %s", strings.Join(extraArgs, " "), moduleDir) t.Logf("Command: %s", cmd) _, _, err := runTerragruntCommandWithOutput(t, cmd) if isSuccessTest { From 408f2d609b5e290933face7412d14f67a4468b78 Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Fri, 30 Jul 2021 16:26:20 -0400 Subject: [PATCH 07/14] Output --terragrunt-strict state in success messages --- cli/validate_inputs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index 00acc714a..def85b6bf 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -53,7 +53,7 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work } terragruntOptions.Logger.Warn("") } else { - terragruntOptions.Logger.Info("All variables passed in by terragrunt are in use.") + terragruntOptions.Logger.Info(fmt.Sprintf("All variables passed in by terragrunt are in use. Strict mode enabled: %t", terragruntOptions.Strict)) } if len(missingVars) > 0 { @@ -63,7 +63,7 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work } terragruntOptions.Logger.Error("") } else { - terragruntOptions.Logger.Info("All required inputs are passed in by terragrunt.") + terragruntOptions.Logger.Info(fmt.Sprintf("All required inputs are passed in by terragrunt. Strict mode enabled: %t", terragruntOptions.Strict)) } // Return an error when there are misaligned inputs. Terragrunt strict mode defaults to false. When it is false, From 139b8206328cd4bc2714cce5ccc6fff018aacfb1 Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Fri, 30 Jul 2021 16:50:34 -0400 Subject: [PATCH 08/14] Move strict mode status message to DEBUG log level --- cli/validate_inputs.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index def85b6bf..6170a5ff8 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -53,7 +53,8 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work } terragruntOptions.Logger.Warn("") } else { - terragruntOptions.Logger.Info(fmt.Sprintf("All variables passed in by terragrunt are in use. Strict mode enabled: %t", terragruntOptions.Strict)) + terragruntOptions.Logger.Info("All variables passed in by terragrunt are in use.") + terragruntOptions.Logger.Debug(fmt.Sprintf("Strict mode enabled: %t", terragruntOptions.Strict)) } if len(missingVars) > 0 { @@ -63,7 +64,8 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work } terragruntOptions.Logger.Error("") } else { - terragruntOptions.Logger.Info(fmt.Sprintf("All required inputs are passed in by terragrunt. Strict mode enabled: %t", terragruntOptions.Strict)) + terragruntOptions.Logger.Info("All required inputs are passed in by terragrunt") + terragruntOptions.Logger.Debug(fmt.Sprintf("Strict mode enabled: %t", terragruntOptions.Strict)) } // Return an error when there are misaligned inputs. Terragrunt strict mode defaults to false. When it is false, From c4a4a5918719a0b9069ae1f1fc10d8dc2b456965 Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Fri, 30 Jul 2021 17:36:39 -0400 Subject: [PATCH 09/14] Add messaging about ignoring errors in relaxed mode --- cli/validate_inputs.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index 6170a5ff8..ee9132169 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -71,9 +71,13 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work // Return an error when there are misaligned inputs. Terragrunt strict mode defaults to false. When it is false, // an error will only be returned if required inputs are missing. When strict mode is true, an error will be // returned if required inputs are missing OR if any unused variables are passed + if len(missingVars) > 0 || len(unusedVars) > 0 && terragruntOptions.Strict { - return fmt.Errorf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t", terragruntOptions.Strict) + return fmt.Errorf(fmt.Sprintf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t.", terragruntOptions.Strict)) + } else if len(unusedVars) > 0 { + return fmt.Errorf("Terragrunt configuration has misaligned inputs, but running in relaxed mode so ignoring.") } + return nil } From 03bd7fb8d6d27881f9c41eca3ca16f09a788ab6a Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Fri, 30 Jul 2021 17:49:36 -0400 Subject: [PATCH 10/14] Relaxed message should just be logged, not return an err --- cli/validate_inputs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index ee9132169..1266e4254 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -71,11 +71,10 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work // Return an error when there are misaligned inputs. Terragrunt strict mode defaults to false. When it is false, // an error will only be returned if required inputs are missing. When strict mode is true, an error will be // returned if required inputs are missing OR if any unused variables are passed - if len(missingVars) > 0 || len(unusedVars) > 0 && terragruntOptions.Strict { return fmt.Errorf(fmt.Sprintf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t.", terragruntOptions.Strict)) } else if len(unusedVars) > 0 { - return fmt.Errorf("Terragrunt configuration has misaligned inputs, but running in relaxed mode so ignoring.") + terragruntOptions.Logger.Info("Terragrunt configuration has misaligned inputs, but running in relaxed mode so ignoring.") } return nil From 9fc55d6d0a59156c850ebaacdb7d9ec1c4d7070d Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Mon, 2 Aug 2021 08:15:50 -0400 Subject: [PATCH 11/14] --terragrunt-strict -> --terragrunt-strict-validate --- cli/cli_app.go | 4 ++-- docs/_docs/04_reference/cli-options.md | 6 ++++++ test/integration_debug_test.go | 8 ++++---- test/integration_serial_test.go | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cli/cli_app.go b/cli/cli_app.go index 8b615fa4f..22c0a252f 100644 --- a/cli/cli_app.go +++ b/cli/cli_app.go @@ -50,7 +50,7 @@ const OPT_TERRAGRUNT_HCLFMT_FILE = "terragrunt-hclfmt-file" const OPT_TERRAGRUNT_DEBUG = "terragrunt-debug" const OPT_TERRAGRUNT_OVERRIDE_ATTR = "terragrunt-override-attr" const OPT_TERRAGRUNT_LOGLEVEL = "terragrunt-log-level" -const OPT_TERRAGRUNT_STRICT = "terragrunt-strict" +const OPT_TERRAGRUNT_STRICT = "terragrunt-strict-validate" var ALL_TERRAGRUNT_BOOLEAN_OPTS = []string{ OPT_NON_INTERACTIVE, @@ -237,7 +237,7 @@ GLOBAL OPTIONS: terragrunt-override-attr A key=value attribute to override in a provider block as part of the aws-provider-patch command. May be specified multiple times. terragrunt-debug Write terragrunt-debug.tfvars to working folder to help root-cause issues. terragrunt-log-level Sets the logging level for Terragrunt. Supported levels: panic, fatal, error, warn (default), info, debug, trace. - terragrunt-strict Sets strict mode for the validate-inputs command. By default, strict mode is off. When this flag is passed, strict mode is turned on. When strict mode is turned off, the validate-inputs command will only return an error if required inputs are missing from all input sources (env vars, var files, etc). When strict mode is turned on, an error will be returned if required inputs are missing OR if unused variables are passed to Terragrunt. + terragrunt-strict-validate Sets strict mode for the validate-inputs command. By default, strict mode is off. When this flag is passed, strict mode is turned on. When strict mode is turned off, the validate-inputs command will only return an error if required inputs are missing from all input sources (env vars, var files, etc). When strict mode is turned on, an error will be returned if required inputs are missing OR if unused variables are passed to Terragrunt. VERSION: {{.Version}}{{if len .Authors}} diff --git a/docs/_docs/04_reference/cli-options.md b/docs/_docs/04_reference/cli-options.md index a0ca48922..9a5ca189c 100644 --- a/docs/_docs/04_reference/cli-options.md +++ b/docs/_docs/04_reference/cli-options.md @@ -406,6 +406,7 @@ prefix `--terragrunt-` (e.g., `--terragrunt-config`). The currently available op - [terragrunt-exclude-dir](#terragrunt-exclude-dir) - [terragrunt-include-dir](#terragrunt-include-dir) - [terragrunt-strict-include](#terragrunt-strict-include) +- [terragrunt-strict-validate](#terragrunt-strict-validate) - [terragrunt-ignore-dependency-order](#terragrunt-ignore-dependency-order) - [terragrunt-ignore-external-dependencies](#terragrunt-ignore-external-dependencies) - [terragrunt-include-external-dependencies](#terragrunt-include-external-dependencies) @@ -610,6 +611,11 @@ will be included. All dependencies of the included directories will be excluded directories. If no [--terragrunt-include-dir](#terragrunt-include-dir) flags are included, terragrunt will not include any modules during the execution of the commands. +### terragrunt-strict-validate + +**CLI Arg**: `--terragrunt-strict-validate` + +When passed in, and running `terragrunt validate-inputs`, enables strict mode for the `validate-inputs` command. When strict mode is enabled, an error will be returned if any variables required by the underlying Terraform configuration are not passed in, OR if any unused variables are passed in. By default, `terragrunt validate-inputs` runs in relaxed mode. In relaxed mode, an error is only returned when a variable required by the underlying Terraform configuration is not passed in. ### terragrunt-ignore-dependency-order diff --git a/test/integration_debug_test.go b/test/integration_debug_test.go index c148c8c5e..6d6fbe538 100644 --- a/test/integration_debug_test.go +++ b/test/integration_debug_test.go @@ -79,7 +79,7 @@ func TestTerragruntValidateInputs(t *testing.T) { t.Parallel() nameDashSplit := strings.Split(name, "-") - runTerragruntValidateInputs(t, module, []string{"--terragrunt-strict"}, nameDashSplit[0] == "success") + runTerragruntValidateInputs(t, module, []string{"--terragrunt-strict-validate"}, nameDashSplit[0] == "success") }) } } @@ -107,7 +107,7 @@ func TestTerragruntValidateInputsWithStrictMode(t *testing.T) { t.Parallel() moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") - args := []string{"--terragrunt-strict"} + args := []string{"--terragrunt-strict-validate"} runTerragruntValidateInputs(t, moduleDir, args, true) } @@ -123,7 +123,7 @@ func TestTerragruntValidateInputsWithStrictModeEnabledAndUnusedVar(t *testing.T) t.Parallel() moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") - args := []string{"-var=testvariable=testvalue", "--terragrunt-strict"} + args := []string{"-var=testvariable=testvalue", "--terragrunt-strict-validate"} runTerragruntValidateInputs(t, moduleDir, args, false) } @@ -131,7 +131,7 @@ func TestTerragruntValidateInputsWithStrictModeEnabledAndUnusedInputs(t *testing t.Parallel() moduleDir := filepath.Join("fixture-validate-inputs", "fail-unused-inputs") - args := []string{"--terragrunt-strict"} + args := []string{"--terragrunt-strict-validate"} runTerragruntValidateInputs(t, moduleDir, args, false) } diff --git a/test/integration_serial_test.go b/test/integration_serial_test.go index 7ad7b1251..3e573b2c1 100644 --- a/test/integration_serial_test.go +++ b/test/integration_serial_test.go @@ -205,7 +205,7 @@ func TestTerragruntValidateInputsWithUnusedEnvVar(t *testing.T) { defer os.Unsetenv("TF_VAR_unused") moduleDir := filepath.Join("fixture-validate-inputs", "success-inputs-only") - args := []string{"--terragrunt-strict"} + args := []string{"--terragrunt-strict-validate"} runTerragruntValidateInputs(t, moduleDir, args, false) } From 196e01a9a947de995d7d589a50ed8ec6a3375a09 Mon Sep 17 00:00:00 2001 From: Zack Proser Date: Tue, 3 Aug 2021 13:58:17 -0400 Subject: [PATCH 12/14] Update cli/validate_inputs.go Co-authored-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com> --- cli/validate_inputs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index 1266e4254..65bd0883c 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -74,7 +74,7 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work if len(missingVars) > 0 || len(unusedVars) > 0 && terragruntOptions.Strict { return fmt.Errorf(fmt.Sprintf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t.", terragruntOptions.Strict)) } else if len(unusedVars) > 0 { - terragruntOptions.Logger.Info("Terragrunt configuration has misaligned inputs, but running in relaxed mode so ignoring.") + terragruntOptions.Logger.Warn("Terragrunt configuration has misaligned inputs, but running in relaxed mode so ignoring.") } return nil From e3d0b829b35d5bea8057328fdf3e5fe2a7300536 Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Tue, 3 Aug 2021 14:01:37 -0400 Subject: [PATCH 13/14] Rename validate strict variables to be more distinct --- cli/args.go | 4 ++-- cli/cli_app.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/args.go b/cli/args.go index 270168739..855964661 100644 --- a/cli/args.go +++ b/cli/args.go @@ -149,7 +149,7 @@ func parseTerragruntOptionsFromArgs(terragruntVersion string, args []string, wri return nil, err } - strictMode := parseBooleanArg(args, OPT_TERRAGRUNT_STRICT, false) + validateStrictMode := parseBooleanArg(args, OPT_TERRAGRUNT_STRICT_VALIDATE, false) opts, err := options.NewTerragruntOptions(filepath.ToSlash(terragruntConfigPath)) if err != nil { @@ -179,7 +179,7 @@ func parseTerragruntOptionsFromArgs(terragruntVersion string, args []string, wri opts.WorkingDir = filepath.ToSlash(workingDir) opts.DownloadDir = filepath.ToSlash(downloadDir) opts.LogLevel = loggingLevel - opts.Strict = strictMode + opts.Strict = validateStrictMode opts.Logger = util.CreateLogEntry("", loggingLevel) opts.Logger.Logger.SetOutput(errWriter) opts.RunTerragrunt = RunTerragrunt diff --git a/cli/cli_app.go b/cli/cli_app.go index 22c0a252f..8bf2bd3b6 100644 --- a/cli/cli_app.go +++ b/cli/cli_app.go @@ -50,7 +50,7 @@ const OPT_TERRAGRUNT_HCLFMT_FILE = "terragrunt-hclfmt-file" const OPT_TERRAGRUNT_DEBUG = "terragrunt-debug" const OPT_TERRAGRUNT_OVERRIDE_ATTR = "terragrunt-override-attr" const OPT_TERRAGRUNT_LOGLEVEL = "terragrunt-log-level" -const OPT_TERRAGRUNT_STRICT = "terragrunt-strict-validate" +const OPT_TERRAGRUNT_STRICT_VALIDATE = "terragrunt-strict-validate" var ALL_TERRAGRUNT_BOOLEAN_OPTS = []string{ OPT_NON_INTERACTIVE, @@ -80,7 +80,7 @@ var ALL_TERRAGRUNT_STRING_OPTS = []string{ OPT_TERRAGRUNT_HCLFMT_FILE, OPT_TERRAGRUNT_OVERRIDE_ATTR, OPT_TERRAGRUNT_LOGLEVEL, - OPT_TERRAGRUNT_STRICT, + OPT_TERRAGRUNT_STRICT_VALIDATE, } const CMD_INIT = "init" From 2f59cd7d8568276212be7ad44b53e59fdb2dce1f Mon Sep 17 00:00:00 2001 From: Zachary Proser Date: Tue, 3 Aug 2021 15:44:36 -0400 Subject: [PATCH 14/14] Strict -> ValidateStrict --- cli/args.go | 2 +- cli/validate_inputs.go | 8 ++++---- options/options.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/args.go b/cli/args.go index 855964661..0a9748140 100644 --- a/cli/args.go +++ b/cli/args.go @@ -179,7 +179,7 @@ func parseTerragruntOptionsFromArgs(terragruntVersion string, args []string, wri opts.WorkingDir = filepath.ToSlash(workingDir) opts.DownloadDir = filepath.ToSlash(downloadDir) opts.LogLevel = loggingLevel - opts.Strict = validateStrictMode + opts.ValidateStrict = validateStrictMode opts.Logger = util.CreateLogEntry("", loggingLevel) opts.Logger.Logger.SetOutput(errWriter) opts.RunTerragrunt = RunTerragrunt diff --git a/cli/validate_inputs.go b/cli/validate_inputs.go index 65bd0883c..5f078a98b 100644 --- a/cli/validate_inputs.go +++ b/cli/validate_inputs.go @@ -54,7 +54,7 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work terragruntOptions.Logger.Warn("") } else { terragruntOptions.Logger.Info("All variables passed in by terragrunt are in use.") - terragruntOptions.Logger.Debug(fmt.Sprintf("Strict mode enabled: %t", terragruntOptions.Strict)) + terragruntOptions.Logger.Debug(fmt.Sprintf("Strict mode enabled: %t", terragruntOptions.ValidateStrict)) } if len(missingVars) > 0 { @@ -65,14 +65,14 @@ func validateTerragruntInputs(terragruntOptions *options.TerragruntOptions, work terragruntOptions.Logger.Error("") } else { terragruntOptions.Logger.Info("All required inputs are passed in by terragrunt") - terragruntOptions.Logger.Debug(fmt.Sprintf("Strict mode enabled: %t", terragruntOptions.Strict)) + terragruntOptions.Logger.Debug(fmt.Sprintf("Strict mode enabled: %t", terragruntOptions.ValidateStrict)) } // Return an error when there are misaligned inputs. Terragrunt strict mode defaults to false. When it is false, // an error will only be returned if required inputs are missing. When strict mode is true, an error will be // returned if required inputs are missing OR if any unused variables are passed - if len(missingVars) > 0 || len(unusedVars) > 0 && terragruntOptions.Strict { - return fmt.Errorf(fmt.Sprintf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t.", terragruntOptions.Strict)) + if len(missingVars) > 0 || len(unusedVars) > 0 && terragruntOptions.ValidateStrict { + return fmt.Errorf(fmt.Sprintf("Terragrunt configuration has misaligned inputs. Strict mode enabled: %t.", terragruntOptions.ValidateStrict)) } else if len(unusedVars) > 0 { terragruntOptions.Logger.Warn("Terragrunt configuration has misaligned inputs, but running in relaxed mode so ignoring.") } diff --git a/options/options.go b/options/options.go index a504bb98c..390afba58 100644 --- a/options/options.go +++ b/options/options.go @@ -86,8 +86,8 @@ type TerragruntOptions struct { // Log level LogLevel logrus.Level - // Strict mode for the validate-inputs command - Strict bool + // ValidateStrict mode for the validate-inputs command + ValidateStrict bool // Environment variables at runtime Env map[string]string @@ -200,7 +200,7 @@ func NewTerragruntOptions(terragruntConfigPath string) (*TerragruntOptions, erro WorkingDir: workingDir, Logger: logger, LogLevel: DEFAULT_LOG_LEVEL, - Strict: false, + ValidateStrict: false, Env: map[string]string{}, Source: "", SourceMap: map[string]string{},