@ -431,7 +431,7 @@ func (runner *TestFileRunner) run(run *moduletest.Run, file *moduletest.File, st
return state , false
}
variables , variableDiags := runner . GetVariables ( config , run , references )
variables , variableDiags := runner . GetVariables ( config , run , references , true )
run . Diagnostics = run . Diagnostics . Append ( variableDiags )
if variableDiags . HasErrors ( ) {
run . Status = moduletest . Error
@ -544,12 +544,6 @@ func (runner *TestFileRunner) run(run *moduletest.Run, file *moduletest.File, st
resetVariables := runner . AddVariablesToConfig ( config , variables )
defer resetVariables ( )
run . Diagnostics = run . Diagnostics . Append ( variableDiags )
if variableDiags . HasErrors ( ) {
run . Status = moduletest . Error
return updated , true
}
if runner . Suite . Verbose {
schemas , diags := tfCtx . Schemas ( config , updated )
@ -637,7 +631,7 @@ func (runner *TestFileRunner) destroy(config *configs.Config, state *states.Stat
var diags tfdiags . Diagnostics
variables , variableDiags := runner . GetVariables ( config , run , nil )
variables , variableDiags := runner . GetVariables ( config , run , nil , false )
diags = diags . Append ( variableDiags )
if diags . HasErrors ( ) {
@ -1004,7 +998,7 @@ func (runner *TestFileRunner) cleanup(file *moduletest.File) {
// more variables than are required by the config. FilterVariablesToConfig
// should be called before trying to use these variables within a Terraform
// plan, apply, or destroy operation.
func ( runner * TestFileRunner ) GetVariables ( config * configs . Config , run * moduletest . Run , references [ ] * addrs . Reference ) ( terraform . InputValues , tfdiags . Diagnostics ) {
func ( runner * TestFileRunner ) GetVariables ( config * configs . Config , run * moduletest . Run , references [ ] * addrs . Reference , includeWarnings bool ) ( terraform . InputValues , tfdiags . Diagnostics ) {
var diags tfdiags . Diagnostics
// relevantVariables contains the variables that are of interest to this
@ -1071,13 +1065,15 @@ func (runner *TestFileRunner) GetVariables(config *configs.Config, run *modulete
// wrote in the variable expression. But, we don't want to actually use
// it if it's not actually relevant.
if _ , exists := relevantVariables [ name ] ; ! exists {
diags = diags . Append ( & hcl . Diagnostic {
Severity : hcl . DiagWarning ,
Summary : "Value for undeclared variable" ,
Detail : fmt . Sprintf ( "The module under test does not declare a variable named %q, but it is declared in run block %q." , name , run . Name ) ,
Subject : expr . Range ( ) . Ptr ( ) ,
} )
// Do not display warnings during cleanup phase
if includeWarnings {
diags = diags . Append ( & hcl . Diagnostic {
Severity : hcl . DiagWarning ,
Summary : "Value for undeclared variable" ,
Detail : fmt . Sprintf ( "The module under test does not declare a variable named %q, but it is declared in run block %q." , name , run . Name ) ,
Subject : expr . Range ( ) . Ptr ( ) ,
} )
}
continue // Don't add it to our final set of variables.
}