From 96af8630658e04d64be29dab48b66def3960767a Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Mon, 14 Oct 2019 15:35:33 -0400 Subject: [PATCH] command/validate: warn if unused flags are set on the command line (#22989) * command/validate: output a warning if unused flags are set The -var and -var-file command line flags are accepted, but not used, in `terraform validate`. This PR adds a warning for users who set either of those flags, so they know that setting them has no effect. --- command/validate.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/command/validate.go b/command/validate.go index 5d84cb0ea4..76155df19e 100644 --- a/command/validate.go +++ b/command/validate.go @@ -25,6 +25,8 @@ func (c *ValidateCommand) Run(args []string) int { return 1 } + // TODO: The `var` and `var-file` options are not actually used, and should + // be removed in the next major release. if c.Meta.variableArgs.items == nil { c.Meta.variableArgs = newRawFlags("-var") } @@ -42,12 +44,22 @@ func (c *ValidateCommand) Run(args []string) int { return 1 } + var diags tfdiags.Diagnostics + + // If set, output a warning indicating that these values are not used. + if !varValues.Empty() || !varFiles.Empty() { + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Warning, + "The -var and -var-file flags are not used in validate. Setting them has no effect.", + "These flags will be removed in a future version of Terraform.", + )) + } + // After this point, we must only produce JSON output if JSON mode is // enabled, so all errors should be accumulated into diags and we'll // print out a suitable result at the end, depending on the format // selection. All returns from this point on must be tail-calls into // c.showResults in order to produce the expected output. - var diags tfdiags.Diagnostics args = cmdFlags.Args() var dirPath string