move nullable check to variable input evaluation

This commit is contained in:
James Bardin 2021-11-01 09:02:32 -04:00
parent 7b7972ac95
commit b71b393cf6
2 changed files with 16 additions and 12 deletions

View File

@ -277,18 +277,6 @@ func (d *evaluationStateData) GetInputVariable(addr addrs.InputVariable, rng tfd
case val.IsNull() && !config.Nullable && config.Default != cty.NilVal:
// If nullable=false a null value will use the configured default.
val = config.Default
case val.IsNull() && !config.Nullable:
// The value cannot be null, and there is no configured default.
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `Invalid variable value`,
Detail: fmt.Sprintf(`The resolved value of variable %q cannot be null.`, addr.Name),
Subject: &config.DeclRange,
})
// Stub out our return value so that the semantic checker doesn't
// produce redundant downstream errors.
val = cty.UnknownVal(config.Type)
}
var err error

View File

@ -253,7 +253,23 @@ func (n *nodeModuleVariable) evalModuleCallArgument(ctx EvalContext, validateOnl
val = cty.UnknownVal(n.Config.Type)
}
// If there is no default, we have to ensure that a null value is allowed
// for this variable.
if n.Config.Default == cty.NilVal && !n.Config.Nullable && val.IsNull() {
// The value cannot be null, and there is no configured default.
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `Invalid variable value`,
Detail: fmt.Sprintf(`The resolved value of variable %q cannot be null.`, n.Addr),
Subject: &n.Config.DeclRange,
})
// Stub out our return value so that the semantic checker doesn't
// produce redundant downstream errors.
val = cty.UnknownVal(n.Config.Type)
}
vals := make(map[string]cty.Value)
vals[name] = val
return vals, diags.ErrWithWarnings()
}