Open tony-kerz opened 1 year ago
It seems the expression.go
in the hashicorp/hcl
file is maybe the root cause of this:
switch {
// If either case is a dynamic null value (which would result from a
// literal null in the config), we know that it can convert to the expected
// type of the opposite case, and we don't need to speculatively reduce the
// final result type to DynamicPseudoType.
// If we know that either Type is a DynamicPseudoType, we can be certain
// that the other value can convert since it's a pass-through, and we don't
// need to unify the types. If the final evaluation results in the dynamic
// value being returned, there's no conversion we can do, so we return the
// value directly.
case trueResult.RawEquals(cty.NullVal(cty.DynamicPseudoType)):
resultType = falseResult.Type()
convs[0] = convert.GetConversionUnsafe(cty.DynamicPseudoType, resultType)
case falseResult.RawEquals(cty.NullVal(cty.DynamicPseudoType)):
resultType = trueResult.Type()
convs[1] = convert.GetConversionUnsafe(cty.DynamicPseudoType, resultType)
case trueResult.Type() == cty.DynamicPseudoType, falseResult.Type() == cty.DynamicPseudoType:
// the final resultType type is still unknown
// we don't need to get the conversion, because both are a noop.
default:
// Try to find a type that both results can be converted to.
resultType, convs = convert.UnifyUnsafe([]cty.Type{trueResult.Type(), falseResult.Type()})
}
It is going to get into the second case
statement and the resultType
will not match null
, because the true result type has the a
key in it. e.g.: merge(false ? {a={}} : null)
Also, it seems to me that if the resultType
is falseResult.Type()
then this should not through the error anymore. Not sure if this approach would cause undesired side-effects.
I was just looking for the codebase to learn more Golang. @jbardin If you think this could be a issue for outsiders of Core Team, just let me know more context so I can try to help.
Terraform Version
Terraform Configuration Files
Debug Output
see output below
Expected Behavior
Actual Behavior
Steps to Reproduce
Additional Context
No response
References
No response