hcl variables: return an unknown value in when no default is set

This commit is contained in:
Adrien Delorme 2020-08-27 11:54:06 +02:00
parent 91c5a4613c
commit eb4069a1b7
1 changed files with 3 additions and 7 deletions

View File

@ -72,9 +72,7 @@ func (v *Variable) Value() (cty.Value, *hcl.Diagnostic) {
} }
} }
value := cty.NullVal(cty.DynamicPseudoType) return cty.UnknownVal(v.Type), &hcl.Diagnostic{
return value, &hcl.Diagnostic{
Severity: hcl.DiagError, Severity: hcl.DiagError,
Summary: fmt.Sprintf("Unset variable %q", v.Name), Summary: fmt.Sprintf("Unset variable %q", v.Name),
Detail: "A used variable must be set or have a default value; see " + Detail: "A used variable must be set or have a default value; see " +
@ -93,7 +91,6 @@ func (variables Variables) Values() (map[string]cty.Value, hcl.Diagnostics) {
value, diag := v.Value() value, diag := v.Value()
if diag != nil { if diag != nil {
diags = append(diags, diag) diags = append(diags, diag)
continue
} }
res[k] = value res[k] = value
} }
@ -208,12 +205,11 @@ func (variables *Variables) decodeVariableBlock(block *hcl.Block, ectx *hcl.Eval
res.DefaultValue = defaultValue res.DefaultValue = defaultValue
// It's possible no type attribute was assigned so lets make // It's possible no type attribute was assigned so lets make sure we
// sure we have a valid type otherwise there will be issues parsing the value. // have a valid type otherwise there could be issues parsing the value.
if res.Type == cty.NilType { if res.Type == cty.NilType {
res.Type = res.DefaultValue.Type() res.Type = res.DefaultValue.Type()
} }
} }
if len(attrs) > 0 { if len(attrs) > 0 {
keys := []string{} keys := []string{}