mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Make sure test vars are only processed during test commands (#2040)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
parent
1e61ce1bfd
commit
37e1085f73
@ -1,3 +1,8 @@
|
|||||||
|
## 1.8.3
|
||||||
|
|
||||||
|
BUG FIXES:
|
||||||
|
* Fixed autoloaded test tfvar files being used in non-test scenarios ([#2039](https://github.com/opentofu/opentofu/pull/2039))
|
||||||
|
|
||||||
## 1.8.2
|
## 1.8.2
|
||||||
|
|
||||||
SECURITY:
|
SECURITY:
|
||||||
|
@ -25,6 +25,15 @@ import (
|
|||||||
// for root module input variables.
|
// for root module input variables.
|
||||||
const VarEnvPrefix = "TF_VAR_"
|
const VarEnvPrefix = "TF_VAR_"
|
||||||
|
|
||||||
|
// collectVariableValuesWithTests inspects the same sources of variables as
|
||||||
|
// collectVariableValues, but also includes any autoloaded variables from the
|
||||||
|
// given tests directory.
|
||||||
|
func (m *Meta) collectVariableValuesWithTests(testDir string) (map[string]backend.UnparsedVariableValue, tfdiags.Diagnostics) {
|
||||||
|
values, diags := m.collectVariableValues()
|
||||||
|
diags = diags.Append(m.addVarsFromDir(testDir, values))
|
||||||
|
return values, diags
|
||||||
|
}
|
||||||
|
|
||||||
// collectVariableValues inspects the various places that root module input variable
|
// collectVariableValues inspects the various places that root module input variable
|
||||||
// values can come from and constructs a map ready to be passed to the
|
// values can come from and constructs a map ready to be passed to the
|
||||||
// backend as part of a backend.Operation.
|
// backend as part of a backend.Operation.
|
||||||
@ -73,7 +82,6 @@ func (m *Meta) collectVariableValues() (map[string]backend.UnparsedVariableValue
|
|||||||
// There's the original terraform.tfvars (DefaultVarsFilename) along with the later-added
|
// There's the original terraform.tfvars (DefaultVarsFilename) along with the later-added
|
||||||
// search for all files ending in .auto.tfvars.
|
// search for all files ending in .auto.tfvars.
|
||||||
diags = diags.Append(m.addVarsFromDir(".", ret))
|
diags = diags.Append(m.addVarsFromDir(".", ret))
|
||||||
diags = diags.Append(m.addVarsFromDir("tests", ret))
|
|
||||||
|
|
||||||
// Finally we process values given explicitly on the command line, either
|
// Finally we process values given explicitly on the command line, either
|
||||||
// as individual literal settings or as additional files to read.
|
// as individual literal settings or as additional files to read.
|
||||||
|
@ -125,7 +125,7 @@ func (c *TestCommand) Run(rawArgs []string) int {
|
|||||||
}
|
}
|
||||||
c.variableArgs = rawFlags{items: &items}
|
c.variableArgs = rawFlags{items: &items}
|
||||||
|
|
||||||
variables, variableDiags := c.collectVariableValues()
|
variables, variableDiags := c.collectVariableValuesWithTests(args.TestDirectory)
|
||||||
diags = diags.Append(variableDiags)
|
diags = diags.Append(variableDiags)
|
||||||
if variableDiags.HasErrors() {
|
if variableDiags.HasErrors() {
|
||||||
view.Diagnostics(nil, nil, diags)
|
view.Diagnostics(nil, nil, diags)
|
||||||
|
Loading…
Reference in New Issue
Block a user