Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.24.1 to 2.26.0
Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.24.1 to 2.26.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.24.1...v2.26.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
63
vendor/github.com/zclconf/go-cty/cty/convert/conversion.go
generated
vendored
63
vendor/github.com/zclconf/go-cty/cty/convert/conversion.go
generated
vendored
@ -43,7 +43,7 @@ func getConversion(in cty.Type, out cty.Type, unsafe bool) conversion {
|
||||
out = out.WithoutOptionalAttributesDeep()
|
||||
|
||||
if !isKnown {
|
||||
return cty.UnknownVal(dynamicReplace(in.Type(), out)), nil
|
||||
return prepareUnknownResult(in.Range(), dynamicReplace(in.Type(), out)), nil
|
||||
}
|
||||
|
||||
if isNull {
|
||||
@ -199,3 +199,64 @@ func retConversion(conv conversion) Conversion {
|
||||
return conv(in, cty.Path(nil))
|
||||
}
|
||||
}
|
||||
|
||||
// prepareUnknownResult can apply value refinements to a returned unknown value
|
||||
// in certain cases where characteristics of the source value or type can
|
||||
// transfer into range constraints on the result value.
|
||||
func prepareUnknownResult(sourceRange cty.ValueRange, targetTy cty.Type) cty.Value {
|
||||
sourceTy := sourceRange.TypeConstraint()
|
||||
|
||||
ret := cty.UnknownVal(targetTy)
|
||||
if sourceRange.DefinitelyNotNull() {
|
||||
ret = ret.RefineNotNull()
|
||||
}
|
||||
|
||||
switch {
|
||||
case sourceTy.IsObjectType() && targetTy.IsMapType():
|
||||
// A map built from an object type always has the same number of
|
||||
// elements as the source type has attributes.
|
||||
return ret.Refine().CollectionLength(len(sourceTy.AttributeTypes())).NewValue()
|
||||
case sourceTy.IsTupleType() && targetTy.IsListType():
|
||||
// A list built from a typle type always has the same number of
|
||||
// elements as the source type has elements.
|
||||
return ret.Refine().CollectionLength(sourceTy.Length()).NewValue()
|
||||
case sourceTy.IsTupleType() && targetTy.IsSetType():
|
||||
// When building a set from a tuple type we can't exactly constrain
|
||||
// the length because some elements might coalesce, but we can
|
||||
// guarantee an upper limit. We can also guarantee at least one
|
||||
// element if the tuple isn't empty.
|
||||
switch l := sourceTy.Length(); l {
|
||||
case 0, 1:
|
||||
return ret.Refine().CollectionLength(l).NewValue()
|
||||
default:
|
||||
return ret.Refine().
|
||||
CollectionLengthLowerBound(1).
|
||||
CollectionLengthUpperBound(sourceTy.Length()).
|
||||
NewValue()
|
||||
}
|
||||
case sourceTy.IsCollectionType() && targetTy.IsCollectionType():
|
||||
// NOTE: We only reach this function if there is an available
|
||||
// conversion between the source and target type, so we don't
|
||||
// need to repeat element type compatibility checks and such here.
|
||||
//
|
||||
// If the source value already has a refined length then we'll
|
||||
// transfer those refinements to the result, because conversion
|
||||
// does not change length (aside from set element coalescing).
|
||||
b := ret.Refine()
|
||||
if targetTy.IsSetType() {
|
||||
if sourceRange.LengthLowerBound() > 0 {
|
||||
// If the source has at least one element then the result
|
||||
// must always have at least one too, because value coalescing
|
||||
// cannot totally empty the set.
|
||||
b = b.CollectionLengthLowerBound(1)
|
||||
}
|
||||
} else {
|
||||
b = b.CollectionLengthLowerBound(sourceRange.LengthLowerBound())
|
||||
}
|
||||
b = b.CollectionLengthUpperBound(sourceRange.LengthUpperBound())
|
||||
return b.NewValue()
|
||||
default:
|
||||
return ret
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user