command: Don't allow -var and -var-file when applying saved plan
This reinstates an old behavior that was lost in the reorganization of how we deal with the -var and -var-file options. This fix is verified by TestApply_planVars now passing.
This commit is contained in:
parent
7abf81d8da
commit
8e51363f04
|
@ -56,6 +56,8 @@ func (c *ApplyCommand) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
// Get the args. The "maybeInit" flag tracks whether we may need to
|
// Get the args. The "maybeInit" flag tracks whether we may need to
|
||||||
// initialize the configuration from a remote path. This is true as long
|
// initialize the configuration from a remote path. This is true as long
|
||||||
// as we have an argument.
|
// as we have an argument.
|
||||||
|
@ -112,9 +114,17 @@ func (c *ApplyCommand) Run(args []string) int {
|
||||||
if planFile != nil {
|
if planFile != nil {
|
||||||
// Reset the config path for backend loading
|
// Reset the config path for backend loading
|
||||||
configPath = ""
|
configPath = ""
|
||||||
}
|
|
||||||
|
|
||||||
var diags tfdiags.Diagnostics
|
if !c.variableArgs.Empty() {
|
||||||
|
diags = diags.Append(tfdiags.Sourceless(
|
||||||
|
tfdiags.Error,
|
||||||
|
"Can't set variables when applying a saved plan",
|
||||||
|
"The -var and -var-file options cannot be used when applying a saved plan file, because a saved plan includes the variable values that were set when it was created.",
|
||||||
|
))
|
||||||
|
c.showDiagnostics(diags)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load the backend
|
// Load the backend
|
||||||
var be backend.Enhanced
|
var be backend.Enhanced
|
||||||
|
|
|
@ -384,6 +384,13 @@ func newRawFlags(flagName string) rawFlags {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f rawFlags) Empty() bool {
|
||||||
|
if f.items == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return len(*f.items) == 0
|
||||||
|
}
|
||||||
|
|
||||||
func (f rawFlags) AllItems() []rawFlag {
|
func (f rawFlags) AllItems() []rawFlag {
|
||||||
return *f.items
|
return *f.items
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue