lang: EvalExpr only convert if wantType is not dynamic

This actually seems to be a bug in the underlying cty Convert function
since converting to cty.DynamicPseudoType should always just return the
input verbatim, but it seems like it's actually converting unknown values
of any type to be cty.DynamicVal, losing the type information.

We should eventually fix this in cty too, but having this extra check in
the Terraform layer is harmless and allows us to make progress without
context-switching.
This commit is contained in:
Martin Atkins 2018-12-05 18:14:17 -08:00
parent bf25e12792
commit e63a1dfb96
1 changed files with 12 additions and 10 deletions

View File

@ -88,6 +88,7 @@ func (s *Scope) EvalExpr(expr hcl.Expression, wantType cty.Type) (cty.Value, tfd
val, evalDiags := expr.Value(ctx)
diags = diags.Append(evalDiags)
if wantType != cty.DynamicPseudoType {
var convErr error
val, convErr = convert.Convert(val, wantType)
if convErr != nil {
@ -99,6 +100,7 @@ func (s *Scope) EvalExpr(expr hcl.Expression, wantType cty.Type) (cty.Value, tfd
Subject: expr.Range().Ptr(),
})
}
}
return val, diags
}