diff --git a/go.mod b/go.mod index e41ea1a2..04d7e99e 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/hashicorp/terraform-provider-kubernetes-alpha go 1.14 require ( - github.com/alexsomesan/openapi-cty v0.0.5-0.20200613004155-675c849b43f4 + github.com/alexsomesan/openapi-cty v0.0.5 github.com/davecgh/go-spew v1.1.1 github.com/golang/protobuf v1.3.3 github.com/google/go-cmp v0.4.0 // indirect github.com/googleapis/gnostic v0.4.0 // indirect - github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 + github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 github.com/hashicorp/go-plugin v1.0.1 github.com/hashicorp/terraform-json v0.4.0 github.com/hashicorp/terraform-plugin-sdk v1.4.1 diff --git a/go.sum b/go.sum index a89584c1..7c46f7b2 100644 --- a/go.sum +++ b/go.sum @@ -234,6 +234,8 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= +github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 h1:Ud/6/AdmJ1R7ibdS0Wo5MWPj0T1R0fkpaD087bBaW8I= +github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-getter v1.4.0 h1:ENHNi8494porjD0ZhIrjlAHnveSFhY7hvOJrV/fsKkw= github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs= diff --git a/vendor/github.com/hashicorp/go-cty/cty/json/unmarshal.go b/vendor/github.com/hashicorp/go-cty/cty/json/unmarshal.go index 5ad190d3..3dcd02f5 100644 --- a/vendor/github.com/hashicorp/go-cty/cty/json/unmarshal.go +++ b/vendor/github.com/hashicorp/go-cty/cty/json/unmarshal.go @@ -10,7 +10,12 @@ import ( "github.com/hashicorp/go-cty/cty/convert" ) -func unmarshal(buf []byte, t cty.Type, path cty.Path) (cty.Value, error) { +// unmarshalOptions configures options for the JSON to CTY decoder. +type unmarshalOptions struct { + ImpliedDynamic bool +} + +func unmarshal(buf []byte, t cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) tok, err := dec.Token() @@ -22,35 +27,37 @@ func unmarshal(buf []byte, t cty.Type, path cty.Path) (cty.Value, error) { return cty.NullVal(t), nil } - if t == cty.DynamicPseudoType { - return unmarshalDynamic(buf, path) - } - switch { case t.IsPrimitiveType(): - val, err := unmarshalPrimitive(tok, t, path) + val, err := unmarshalPrimitive(tok, t, path, opt) if err != nil { return cty.NilVal, err } return val, nil case t.IsListType(): - return unmarshalList(buf, t.ElementType(), path) + return unmarshalList(buf, t.ElementType(), path, opt) case t.IsSetType(): - return unmarshalSet(buf, t.ElementType(), path) + return unmarshalSet(buf, t.ElementType(), path, opt) case t.IsMapType(): - return unmarshalMap(buf, t.ElementType(), path) + return unmarshalMap(buf, t.ElementType(), path, opt) case t.IsTupleType(): - return unmarshalTuple(buf, t.TupleElementTypes(), path) + return unmarshalTuple(buf, t.TupleElementTypes(), path, opt) case t.IsObjectType(): - return unmarshalObject(buf, t.AttributeTypes(), path) + return unmarshalObject(buf, t.AttributeTypes(), path, opt) case t.IsCapsuleType(): - return unmarshalCapsule(buf, t, path) + return unmarshalCapsule(buf, t, path, opt) + case t.Equals(cty.DynamicPseudoType): + if opt.ImpliedDynamic { + return unmarshalIntoDynamic(buf, path, opt) + } else { + return unmarshalDynamic(buf, path, opt) + } default: return cty.NilVal, path.NewErrorf("unsupported type %s", t.FriendlyName()) } } -func unmarshalPrimitive(tok json.Token, t cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalPrimitive(tok json.Token, t cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { switch t { case cty.Bool: @@ -101,7 +108,7 @@ func unmarshalPrimitive(tok json.Token, t cty.Type, path cty.Path) (cty.Value, e } } -func unmarshalList(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalList(buf []byte, ety cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) if err := requireDelim(dec, '['); err != nil { return cty.NilVal, path.NewError(err) @@ -124,7 +131,7 @@ func unmarshalList(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { return cty.NilVal, path.NewErrorf("failed to read list value: %s", err) } - el, err := unmarshal(rawVal, ety, path) + el, err := unmarshal(rawVal, ety, path, opt) if err != nil { return cty.NilVal, err } @@ -144,7 +151,7 @@ func unmarshalList(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { return cty.ListVal(vals), nil } -func unmarshalSet(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalSet(buf []byte, ety cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) if err := requireDelim(dec, '['); err != nil { return cty.NilVal, path.NewError(err) @@ -165,7 +172,7 @@ func unmarshalSet(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { return cty.NilVal, path.NewErrorf("failed to read set value: %s", err) } - el, err := unmarshal(rawVal, ety, path) + el, err := unmarshal(rawVal, ety, path, opt) if err != nil { return cty.NilVal, err } @@ -185,7 +192,7 @@ func unmarshalSet(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { return cty.SetVal(vals), nil } -func unmarshalMap(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalMap(buf []byte, ety cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) if err := requireDelim(dec, '{'); err != nil { return cty.NilVal, path.NewError(err) @@ -217,7 +224,7 @@ func unmarshalMap(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { return cty.NilVal, path.NewErrorf("failed to read map value: %s", err) } - el, err := unmarshal(rawVal, ety, path) + el, err := unmarshal(rawVal, ety, path, opt) if err != nil { return cty.NilVal, err } @@ -237,7 +244,7 @@ func unmarshalMap(buf []byte, ety cty.Type, path cty.Path) (cty.Value, error) { return cty.MapVal(vals), nil } -func unmarshalTuple(buf []byte, etys []cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalTuple(buf []byte, etys []cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) if err := requireDelim(dec, '['); err != nil { return cty.NilVal, path.NewError(err) @@ -265,7 +272,7 @@ func unmarshalTuple(buf []byte, etys []cty.Type, path cty.Path) (cty.Value, erro return cty.NilVal, path.NewErrorf("failed to read tuple value: %s", err) } - el, err := unmarshal(rawVal, ety, path) + el, err := unmarshal(rawVal, ety, path, opt) if err != nil { return cty.NilVal, err } @@ -289,7 +296,7 @@ func unmarshalTuple(buf []byte, etys []cty.Type, path cty.Path) (cty.Value, erro return cty.TupleVal(vals), nil } -func unmarshalObject(buf []byte, atys map[string]cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalObject(buf []byte, atys map[string]cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) if err := requireDelim(dec, '{'); err != nil { return cty.NilVal, path.NewError(err) @@ -324,7 +331,7 @@ func unmarshalObject(buf []byte, atys map[string]cty.Type, path cty.Path) (cty.V return cty.NilVal, path.NewErrorf("failed to read object value: %s", err) } - el, err := unmarshal(rawVal, aty, path) + el, err := unmarshal(rawVal, aty, path, opt) if err != nil { return cty.NilVal, err } @@ -351,7 +358,7 @@ func unmarshalObject(buf []byte, atys map[string]cty.Type, path cty.Path) (cty.V return cty.ObjectVal(vals), nil } -func unmarshalCapsule(buf []byte, t cty.Type, path cty.Path) (cty.Value, error) { +func unmarshalCapsule(buf []byte, t cty.Type, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { rawType := t.EncapsulatedType() ptrPtr := reflect.New(reflect.PtrTo(rawType)) ptrPtr.Elem().Set(reflect.New(rawType)) @@ -364,7 +371,7 @@ func unmarshalCapsule(buf []byte, t cty.Type, path cty.Path) (cty.Value, error) return cty.CapsuleVal(t, ptr), nil } -func unmarshalDynamic(buf []byte, path cty.Path) (cty.Value, error) { +func unmarshalDynamic(buf []byte, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { dec := bufDecoder(buf) if err := requireDelim(dec, '{'); err != nil { return cty.NilVal, path.NewError(err) @@ -411,7 +418,7 @@ func unmarshalDynamic(buf []byte, path cty.Path) (cty.Value, error) { return cty.NilVal, path.NewErrorf("missing value in dynamically-typed value") } - val, err := Unmarshal([]byte(valBody), t) + val, err := unmarshal([]byte(valBody), t, cty.Path{}, opt) if err != nil { return cty.NilVal, path.NewError(err) } @@ -457,3 +464,27 @@ func bufDecoder(buf []byte) *json.Decoder { dec.UseNumber() return dec } + +func unmarshalIntoDynamic(buf []byte, path cty.Path, opt *unmarshalOptions) (cty.Value, error) { + var t cty.Type + var err error + + if buf == nil { + return cty.NilVal, path.NewErrorf("missing value in dynamically-typed value") + } + + t, err = ImpliedType(buf) + if err != nil { + return cty.NilVal, path.NewErrorf("failed to imply dynamic type: %s", err) + } + + if t == cty.NilType { + return cty.NilVal, path.NewErrorf("missing type in dynamically-typed value") + } + + val, err := unmarshal(buf, t, path, opt) + if err != nil { + return cty.NilVal, path.NewError(err) + } + return val, nil +} diff --git a/vendor/github.com/hashicorp/go-cty/cty/json/value.go b/vendor/github.com/hashicorp/go-cty/cty/json/value.go index 50748f70..1739386c 100644 --- a/vendor/github.com/hashicorp/go-cty/cty/json/value.go +++ b/vendor/github.com/hashicorp/go-cty/cty/json/value.go @@ -61,5 +61,21 @@ func Marshal(val cty.Value, t cty.Type) ([]byte, error) { // may be a cty.PathError. func Unmarshal(buf []byte, t cty.Type) (cty.Value, error) { var path cty.Path - return unmarshal(buf, t, path) + return unmarshal(buf, t, path, &unmarshalOptions{}) +} + +// UnmarshalDynamicWithImpliedType decodes a JSON representation of the +// given value into a cty.Value conforming to the given type while replacing +// dynamicPseudoType attributes with their implied type. +// +// Implied types are a best-effort deduction of the type from the structure +// of the input JSON. +// +// While decoding, type conversions will be done where possible to make +// the result conformant even if the types given in JSON are not exactly +// correct. If conversion isn't possible then an error is returned, which +// may be a cty.PathError. +func UnmarshalDynamicWithImpliedType(buf []byte, t cty.Type) (cty.Value, error) { + var path cty.Path + return unmarshal(buf, t, path, &unmarshalOptions{ImpliedDynamic: true}) } diff --git a/vendor/modules.txt b/vendor/modules.txt index fc48dfc1..2ccdd9cf 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -17,7 +17,7 @@ github.com/Azure/go-autorest/autorest/date github.com/Azure/go-autorest/logger # github.com/Azure/go-autorest/tracing v0.5.0 github.com/Azure/go-autorest/tracing -# github.com/alexsomesan/openapi-cty v0.0.5-0.20200613004155-675c849b43f4 => /Users/alex/workspace/openapi-cty +# github.com/alexsomesan/openapi-cty v0.0.5 => /Users/alex/workspace/openapi-cty ## explicit github.com/alexsomesan/openapi-cty/foundry # github.com/aws/aws-sdk-go v1.25.3 @@ -103,7 +103,7 @@ github.com/gophercloud/gophercloud/openstack/utils github.com/gophercloud/gophercloud/pagination # github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-cleanhttp -# github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 +# github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 ## explicit github.com/hashicorp/go-cty/cty github.com/hashicorp/go-cty/cty/convert