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.
This commit is contained in:
Kristin Laemmert 2019-10-14 15:35:33 -04:00 committed by GitHub
parent 047733d20c
commit 96af863065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -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