variable types should always be populated

This commit is contained in:
James Bardin 2021-09-10 11:11:06 -04:00
parent 53a73a8ab6
commit 7f26531d4f
1 changed files with 6 additions and 21 deletions

View File

@ -237,21 +237,6 @@ func (d *evaluationStateData) GetInputVariable(addr addrs.InputVariable, rng tfd
})
return cty.DynamicVal, diags
}
// wantType is the concrete value type to be returned.
wantType := cty.DynamicPseudoType
// converstionType is the type used for conversion, which may include
// optional attributes.
conversionType := cty.DynamicPseudoType
if config.ConstraintType != cty.NilType {
conversionType = config.ConstraintType
}
if config.Type != cty.NilType {
wantType = config.Type
}
d.Evaluator.VariableValuesLock.Lock()
defer d.Evaluator.VariableValuesLock.Unlock()
@ -271,15 +256,15 @@ func (d *evaluationStateData) GetInputVariable(addr addrs.InputVariable, rng tfd
if d.Operation == walkValidate {
// Ensure variable sensitivity is captured in the validate walk
if config.Sensitive {
return cty.UnknownVal(wantType).Mark(marks.Sensitive), diags
return cty.UnknownVal(config.Type).Mark(marks.Sensitive), diags
}
return cty.UnknownVal(wantType), diags
return cty.UnknownVal(config.Type), diags
}
moduleAddrStr := d.ModulePath.String()
vals := d.Evaluator.VariableValues[moduleAddrStr]
if vals == nil {
return cty.UnknownVal(wantType), diags
return cty.UnknownVal(config.Type), diags
}
val, isSet := vals[addr.Name]
@ -287,11 +272,11 @@ func (d *evaluationStateData) GetInputVariable(addr addrs.InputVariable, rng tfd
if config.Default != cty.NilVal {
return config.Default, diags
}
return cty.UnknownVal(wantType), diags
return cty.UnknownVal(config.Type), diags
}
var err error
val, err = convert.Convert(val, conversionType)
val, err = convert.Convert(val, config.ConstraintType)
if err != nil {
// We should never get here because this problem should've been caught
// during earlier validation, but we'll do something reasonable anyway.
@ -303,7 +288,7 @@ func (d *evaluationStateData) GetInputVariable(addr addrs.InputVariable, rng tfd
})
// Stub out our return value so that the semantic checker doesn't
// produce redundant downstream errors.
val = cty.UnknownVal(wantType)
val = cty.UnknownVal(config.Type)
}
// Mark if sensitive