diff --git a/README.md b/README.md index 74181c0..c95326f 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ protoc \ types.proto ``` -This command will generate `types_terraform.go` in `tfschema` folder. +This command will generate `types_terraform.go` in `tfschema` folder. See [Makefile](Makefile) for details. @@ -109,7 +109,7 @@ validators: plan_modifiers: "Role.Options": - - "github.com/hashicorp/terraform-plugin-framework/tfsdk.RequiresReplace()" + - "github.com/hashicorp/terraform-plugin-framework/resource.RequiresReplace()" ``` ## UseStateForUnknown by default @@ -120,7 +120,7 @@ The following setting: use_state_for_unknown_by_default: true ``` -will add `tfsdk.UseStateForUnknown()` PlanModifier to all computed fields. +will add `resource.UseStateForUnknown()` PlanModifier to all computed fields. ## Injecting fields into schema @@ -143,7 +143,7 @@ If you need to rename field in schema, use `name_overrides` option: ```yaml name_overrides: - "Role.Spec.AWSRoleARNs": aws_arns + "Role.Spec.AWSRoleARNs": aws_arns ``` ## Custom fields @@ -187,7 +187,7 @@ The signatures for `Test` resource would be the following: ```go // CopyTestFromTerraform copies Terraform object fields to obj -// tf must have all the object attrs present (including null and unknown). +// tf must have all the object attrs present (including null and unknown). // Hence, tf must be the result of req.Plan.Get or similar Terraform method. // Otherwise, error would be returned. func CopyTestFromTerraform(tf types.Object, obj *Test) diag.Diagnostics @@ -197,7 +197,7 @@ They can be used as following: ```go // Create template resource create method -func (r resource) Create(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) { +func (r resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var plan types.Object diags := req.Plan.Get(ctx, &plan) resp.Diagnostics.Append(diags...) @@ -206,8 +206,8 @@ func (r resource) Create(ctx context.Context, req tfsdk.CreateResourceRequest, r } obj := types.Object{} - diags := tfschema.CopyObjFromTerraform(plan, &obj) - resp.Diagnostics.Append(diags...) + diags := tfschema.CopyObjFromTerraform(plan, &obj) + resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } diff --git a/config.go b/config.go index 5fa7008..be73b83 100644 --- a/config.go +++ b/config.go @@ -57,6 +57,13 @@ type SchemaType struct { Type string `yaml:"type,omitempty"` // ValueType is a Go attr.Value struct name ValueType string `yaml:"value_type,omitempty"` + // ValueFromMethod is the method on attr.Value that will be called to get + // the underlying value + ValueFromMethod string `yaml:"value_from_method,omitempty"` + // ValueToMethod is the method that will be called to create the attr.Value + ValueToMethod string `yaml:"value_to_method,omitempty"` + // NullValueMethod is the method that will be called to create a null attr.Value + NullValueMethod string `yaml:"null_value_method,omitempty"` // CastToType is a Go attr.Value .Value member type CastToType string `yaml:"cast_to_type,omitempty"` // CastToType is a go type of the object field @@ -81,6 +88,9 @@ type InjectedField struct { PlanModifiers []string `yaml:"plan_modifiers,omitempty"` // PlanModifiers is the array of Validators Validators []string `yaml:"validators,omitempty"` + // ValueMethod is the method that will be called to construct a placeholder + // value for the field in Copy*ToTerraform methods + ValueMethod string `yaml:"value_method,omitempty"` } // Config represents the plugin config diff --git a/config_test.go b/config_test.go index 3ee0607..5fdc593 100644 --- a/config_test.go +++ b/config_test.go @@ -24,29 +24,36 @@ func TestConfig(t *testing.T) { require.Equal(t, cfg.Suffixes, map[string]string{"BoolCustom": "BoolSpecial"}) require.Equal(t, cfg.NameOverrides, map[string]string{"Test.Str": "str"}) - require.Equal(t, cfg.PlanModifiers, map[string][]string{"Test.Str": {"github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"}}) + require.Equal(t, cfg.PlanModifiers, map[string][]string{"Test.Str": {"github.com/hashicorp/terraform-plugin-framework/resource.UseStateForUnknown()"}}) require.Equal(t, cfg.Validators, map[string][]string{"Test.Str": {"UseMockValidator()"}}) require.Equal(t, cfg.TimeType, &SchemaType{ Type: "TimeType", ValueType: "TimeValue", + ValueFromMethod: "ValueTime", + ValueToMethod: "ValueTime", + NullValueMethod: "NullTime", CastToType: "time.Time", CastFromType: "time.Time", TypeConstructor: "UseRFC3339Time()", }) require.Equal(t, cfg.DurationType, &SchemaType{ - Type: "DurationType", - ValueType: "DurationValue", - CastToType: "time.Duration", - CastFromType: "time.Duration", + Type: "DurationType", + ValueType: "DurationValue", + ValueFromMethod: "ValueDuration", + ValueToMethod: "ValueDuration", + NullValueMethod: "NullDuration", + CastToType: "time.Duration", + CastFromType: "time.Duration", }) require.Equal(t, cfg.InjectedFields, map[string][]InjectedField{ "Test": {{ - Name: "id", - Type: "github.com/hashicorp/terraform-plugin-framework/types.StringType", - Computed: true, + Name: "id", + Type: "github.com/hashicorp/terraform-plugin-framework/types.StringType", + Computed: true, + ValueMethod: "github.com/hashicorp/terraform-plugin-framework/types.StringUnknown", }}, }) diff --git a/field.go b/field.go index e0c2182..d25bfa3 100644 --- a/field.go +++ b/field.go @@ -50,14 +50,18 @@ type TerraformType struct { Type string // ValueType represents Terraform attr.Value name ValueType string + // ValueFromMethod is the method called on an attr.Value to get the underlying value + ValueFromMethod string + // ValueToMethod is the method called to construct an attr.Value + ValueToMethod string + // NullValueMethod is the method called to construct a null attr.Value + NullValueMethod string // ElemType represents Terraform attr.Type name for list/map Elem, equals Type by default ElemType string // ElemValueType represents Terraform attr.Value name for list/map Elem, equals ValueType by default ElemValueType string // IsTypeScalar is true when Type is not a real struct and is represented with numeric constant on Terraform side IsTypeScalar bool - // IsTypeScalar is true when ElemType is not a real struct and is represented with numeric constant on Terraform side - IsElemTypeScalar bool // ValueCastToType represents Go type of either ValueType.Value or ElemValueType.Value ValueCastToType string // ValueCastFromType represents Go type of a counterpart object field or field elem to cast from .Value @@ -322,6 +326,9 @@ func (f *Field) setMapValues(c *FieldBuildContext) error { f.ElemValueType = f.MapValueField.ElemValueType f.ValueCastToType = f.MapValueField.ValueCastToType f.ValueCastFromType = f.MapValueField.ValueCastFromType + f.ValueFromMethod = f.MapValueField.ValueFromMethod + f.ValueToMethod = f.MapValueField.ValueToMethod + f.NullValueMethod = f.MapValueField.NullValueMethod f.GoElemType = f.MapValueField.GoElemType @@ -409,6 +416,9 @@ func (f *Field) setTerraformTypeOverride(c *FieldBuildContext) { if o != nil { f.Type = o.Type f.ValueType = o.ValueType + f.ValueFromMethod = o.ValueFromMethod + f.ValueToMethod = o.ValueToMethod + f.NullValueMethod = o.NullValueMethod f.ValueCastToType = o.CastToType f.ValueCastFromType = o.CastFromType f.TypeConstructor = o.TypeConstructor diff --git a/field_build_context.go b/field_build_context.go index 59ee317..a36ac55 100644 --- a/field_build_context.go +++ b/field_build_context.go @@ -29,47 +29,55 @@ import ( var ( float64Type = TerraformType{ - Type: Types + ".Float64Type", - ValueType: Types + ".Float64", - ElemType: Types + ".Float64Type", - ElemValueType: Types + ".Float64", - ValueCastToType: "float64", - ZeroValue: "0", - IsTypeScalar: true, - IsElemTypeScalar: true, + Type: Types + ".Float64Type", + ValueType: Types + ".Float64", + ValueFromMethod: "ValueFloat64", + ValueToMethod: Types + ".Float64Value", + NullValueMethod: Types + ".Float64Null", + ElemType: Types + ".Float64Type", + ElemValueType: Types + ".Float64", + ValueCastToType: "float64", + ZeroValue: "0", + IsTypeScalar: true, } int64Type = TerraformType{ - Type: Types + ".Int64Type", - ValueType: Types + ".Int64", - ElemType: Types + ".Int64Type", - ElemValueType: Types + ".Int64", - ValueCastToType: "int64", - ZeroValue: "0", - IsTypeScalar: true, - IsElemTypeScalar: true, + Type: Types + ".Int64Type", + ValueType: Types + ".Int64", + ValueFromMethod: "ValueInt64", + ValueToMethod: Types + ".Int64Value", + NullValueMethod: Types + ".Int64Null", + ElemType: Types + ".Int64Type", + ElemValueType: Types + ".Int64", + ValueCastToType: "int64", + ZeroValue: "0", + IsTypeScalar: true, } stringType = TerraformType{ - Type: Types + ".StringType", - ValueType: Types + ".String", - ElemType: Types + ".StringType", - ElemValueType: Types + ".String", - ValueCastToType: "string", - ZeroValue: `""`, - IsTypeScalar: true, - IsElemTypeScalar: true, + Type: Types + ".StringType", + ValueType: Types + ".String", + ValueFromMethod: "ValueString", + ValueToMethod: Types + ".StringValue", + NullValueMethod: Types + ".StringNull", + ElemType: Types + ".StringType", + ElemValueType: Types + ".String", + ValueCastToType: "string", + ZeroValue: `""`, + IsTypeScalar: true, } boolType = TerraformType{ - Type: Types + ".BoolType", - ValueType: Types + ".Bool", - ElemType: Types + ".BoolType", - ElemValueType: Types + ".Bool", - ValueCastToType: "bool", - ZeroValue: "false", - IsTypeScalar: true, - IsElemTypeScalar: true, + Type: Types + ".BoolType", + ValueType: Types + ".Bool", + ValueFromMethod: "ValueBool", + ValueToMethod: Types + ".BoolValue", + NullValueMethod: Types + ".BoolNull", + ElemType: Types + ".BoolType", + ElemValueType: Types + ".Bool", + ValueCastToType: "bool", + ZeroValue: "false", + IsTypeScalar: true, } objectType = TerraformType{ @@ -200,6 +208,9 @@ func (c *FieldBuildContext) GetTerraformType() (TerraformType, error) { t = TerraformType{ Type: c.config.TimeType.Type, ValueType: c.config.TimeType.ValueType, + ValueFromMethod: c.config.TimeType.ValueFromMethod, + ValueToMethod: c.config.TimeType.ValueToMethod, + NullValueMethod: c.config.TimeType.NullValueMethod, ElemType: c.config.TimeType.Type, ElemValueType: c.config.TimeType.ValueType, ValueCastToType: c.config.TimeType.CastToType, @@ -213,6 +224,9 @@ func (c *FieldBuildContext) GetTerraformType() (TerraformType, error) { t = TerraformType{ Type: c.config.DurationType.Type, ValueType: c.config.DurationType.ValueType, + ValueFromMethod: c.config.DurationType.ValueFromMethod, + ValueToMethod: c.config.DurationType.ValueToMethod, + NullValueMethod: c.config.DurationType.NullValueMethod, ElemType: c.config.DurationType.Type, ElemValueType: c.config.DurationType.ValueType, ValueCastToType: c.config.DurationType.CastToType, @@ -221,13 +235,11 @@ func (c *FieldBuildContext) GetTerraformType() (TerraformType, error) { } case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_DOUBLE) || gogoproto.IsStdDouble(p): t = float64Type - t.ValueCastFromType = "float64" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_FLOAT) || gogoproto.IsStdFloat(p): t = float64Type t.ValueCastFromType = "float32" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_INT64) || gogoproto.IsStdInt64(p): t = int64Type - t.ValueCastFromType = "int64" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_UINT64) || gogoproto.IsStdUInt64(p): t = int64Type t.ValueCastFromType = "uint64" @@ -248,19 +260,15 @@ func (c *FieldBuildContext) GetTerraformType() (TerraformType, error) { t.ValueCastFromType = "int32" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_SFIXED64): t = int64Type - t.ValueCastFromType = "int64" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_SINT32): t = int64Type t.ValueCastFromType = "int32" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_SINT64): t = int64Type - t.ValueCastFromType = "int64" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_BOOL) || gogoproto.IsStdBool(p): t = boolType - t.ValueCastFromType = "bool" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_STRING) || gogoproto.IsStdString(p): t = stringType - t.ValueCastFromType = "string" case c.field.IsTypeEq(descriptor.FieldDescriptorProto_TYPE_BYTES) || gogoproto.IsStdBytes(p): t = stringType t.ValueCastFromType = "[]byte" @@ -442,7 +450,7 @@ func (c *FieldBuildContext) GetPlanModifiers() []string { } if c.config.UseStateForUnknownByDefault && c.IsComputed() { - return []string{"github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"} + return []string{"github.com/hashicorp/terraform-plugin-framework/resource.UseStateForUnknown()"} } return []string{} diff --git a/gen_copy_from.go b/gen_copy_from.go index 7a653a9..97412ff 100644 --- a/gen_copy_from.go +++ b/gen_copy_from.go @@ -101,8 +101,8 @@ func (f *FieldCopyFromGenerator) errAttrConversionFailure(path string, typ strin // nextField reads current field value from Terraform object and asserts it's type against expected func (f *FieldCopyFromGenerator) nextField(g func(g *j.Group)) *j.Statement { return j.Block( - // a, ok := ft.Attrs["key"] - j.List(j.Id("a"), j.Id("ok")).Op(":=").Id("tf.Attrs").Index(j.Lit(f.NameSnake)), + // a, ok := ft.Attributes()["key"] + j.List(j.Id("a"), j.Id("ok")).Op(":=").Id("tf.Attributes").Call().Index(j.Lit(f.NameSnake)), j.If(j.Id("!ok")).BlockFunc(f.errAttrMissingDiag).Else().Block( // v, ok := a.(types.Int64) j.List(j.Id("v"), j.Id("ok")).Op(":=").Id("a").Assert(j.Id(f.i.WithType(f.ValueType))), @@ -118,13 +118,25 @@ func (f *FieldCopyFromGenerator) genPrimitiveBody(g *j.Group) { // var t float32 || *float32, acts as zero value if needed g.Var().Id("t").Id(f.i.WithType(f.GoElemType)) // if !v.Null { - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { + val := j.Id("v." + f.ValueFromMethod).Call() + if !f.IsNullable { - // obj.Float = float32(v.Value) - g.Id("t").Op("=").Id(f.i.WithType(f.ValueCastFromType)).Parens(j.Id("v.Value")) + if f.ValueCastFromType == "" { + // obj.Float = v.ValueFloat64() + g.Id("t").Op("=").Add(val) + } else { + // obj.Float = float32(v.ValueFloat64()) + g.Id("t").Op("=").Id(f.i.WithType(f.ValueCastFromType)).Parens(val) + } } else { - // c := float32(v.Value) - g.Id("c").Op(":=").Id(f.i.WithType(f.ValueCastFromType)).Parens(j.Id("v.Value")) + if f.ValueCastFromType == "" { + // c := v.ValueFloat64() + g.Id("c").Op(":=").Add(val) + } else { + // c := float32(v.ValueFloat64()) + g.Id("c").Op(":=").Id(f.i.WithType(f.ValueCastFromType)).Parens(val) + } // obj.Float = &c g.Id("t").Op("=&").Id("c") } @@ -135,13 +147,13 @@ func (f *FieldCopyFromGenerator) genPrimitiveBody(g *j.Group) { func (f *FieldCopyFromGenerator) genListOrMapIterator(g *j.Group, typ *j.Statement, els func(g *j.Group)) { objFieldName := "obj." + f.Name - // obj.List = make([]string, len(v.Elems)) - same for maps - g.Id(objFieldName).Op("=").Make(j.Id(f.i.WithType(f.GoType)), j.Len(j.Id("v.Elems"))) + // obj.List = make([]string, len(v.Elements())) - same for maps + g.Id(objFieldName).Op("=").Make(j.Id(f.i.WithType(f.GoType)), j.Len(j.Id("v.Elements").Call())) // if !v.Null - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { - // for k, el := range v.Elems - where k is either index or map key - g.For(j.List(j.Id("k"), j.Id("a"))).Op(":=").Range().Id("v.Elems").BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { + // for k, el := range v.Elements() - where k is either index or map key + g.For(j.List(j.Id("k"), j.Id("a"))).Op(":=").Range().Id("v.Elements").Call().BlockFunc(func(g *j.Group) { // v, ok := a.(types.String) g.List(j.Id("v"), j.Id("ok")).Op(":=").Id("a").Assert(typ) g.If(j.Id("!ok")).BlockFunc( @@ -158,7 +170,7 @@ func (f *FieldCopyFromGenerator) genPrimitive() *j.Statement { if f.OneOfName != "" { // Do not set empty oneOf value to not override values possibly set by other branches - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { g.Id("obj." + f.OneOfName).Op("=").Id("&" + f.i.WithType(f.OneOfType)).Values(j.Dict{ j.Id(f.Name): j.Id("t"), }) @@ -168,7 +180,7 @@ func (f *FieldCopyFromGenerator) genPrimitive() *j.Statement { if f.ParentIsOptionalEmbed { // If the current value is Null or Unknown, we should not set the parent field, otherwise we will get the default values for all the inner fields. - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { g.If(j.Id("obj." + f.ParentIsOptionalEmbedFieldName).Op("==").Nil()).Block( j.Id("obj." + f.ParentIsOptionalEmbedFieldName).Op("=").Id("&" + f.ParentIsOptionalEmbedFullType + "{}"), ) @@ -196,7 +208,7 @@ func (f *FieldCopyFromGenerator) genObject() *j.Statement { g.Id(objFieldName).Op("=").Id(f.i.WithType(f.GoElemType)).Values() } // if !v.Null - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { if !m.IsEmpty { // tf := v g.Id("tf").Op(":=").Id("v") @@ -217,7 +229,7 @@ func (f *FieldCopyFromGenerator) genObject() *j.Statement { } else { // We do not need nullable checks because all oneOf branches are nullable by design // We do not need to assign OneOf explicitly to not overrite other OneOf branch values - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { g.Id("b").Op(":=&").Id(f.i.WithType(f.GoElemTypeIndirect)).Values() g.Id("obj." + f.OneOfName).Op("=").Id("&" + f.i.WithType(f.OneOfType)).Values(j.Dict{ @@ -271,7 +283,7 @@ func (f *FieldCopyFromGenerator) genObjectListOrMap() *j.Statement { // var t Nested || *Nested g.Var().Id("t").Id(f.i.WithType(f.GoElemType)) - g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(func(g *j.Group) { + g.If(j.Id("!v.IsNull() && !v.IsUnknown()")).BlockFunc(func(g *j.Group) { // tf := v g.Id("tf").Op(":=").Id("v") @@ -296,8 +308,8 @@ func (f *FieldCopyFromGenerator) genObjectListOrMap() *j.Statement { // genCustom generates statement representing custom type func (f *FieldCopyFromGenerator) genCustom() *j.Statement { return j.Block( - // a, ok := ft.Attrs["key"] - j.List(j.Id("a"), j.Id("ok")).Op(":=").Id("tf.Attrs").Index(j.Lit(f.NameSnake)), + // a, ok := ft.Attributes()["key"] + j.List(j.Id("a"), j.Id("ok")).Op(":=").Id("tf.Attributes").Call().Index(j.Lit(f.NameSnake)), j.If(j.Id("!ok")).BlockFunc(f.errAttrMissingDiag), j.Id("CopyFrom"+f.Suffix).Params(j.Id("diags"), j.Id("a"), j.Id("&obj."+f.Name)), ) diff --git a/gen_copy_to.go b/gen_copy_to.go index c733c4e..9648afb 100644 --- a/gen_copy_to.go +++ b/gen_copy_to.go @@ -20,27 +20,77 @@ func NewMessageCopyToGenerator(m *Message, i *Imports) *MessageCopyToGenerator { // Generate generates CopyToTF method func (m *MessageCopyToGenerator) Generate(writer io.Writer) (int, error) { methodName := "Copy" + m.Name + "ToTerraform" - tf := j.Id("tf").Op("*").Id(m.i.WithPackage(Types, "Object")) - obj := j.Id("obj").Op("*").Id(m.i.WithType(m.GoType)) - diags := j.Var().Id("diags").Id(m.i.WithPackage(Diag, "Diagnostics")) - ctx := j.Id("ctx").Id(m.i.WithPackage("context", "Context")) - // func CopyToTerraform(ctx context.Context, tf types.Object, obj *apitypes.) + // func CopyToTerraform(ctx context.Context, obj *apitypes.) (*types.Object, diag.Diagnostics) // ... statements for a fields method := - j.Commentf("// %v copies contents of the source Terraform object into a target struct\n", methodName). + j.Commentf("// %v copies contents of source struct into a Terraform object.\n", methodName). Func().Id(methodName). - Params(ctx, obj, tf). - Id(m.i.WithPackage(Diag, "Diagnostics")). + Params( + j.Id("ctx").Id(m.i.WithPackage("context", "Context")), + j.Id("obj").Op("*").Id(m.i.WithType(m.GoType)), + j.Id("curr").Op("*").Id(m.i.WithPackage(Types, "Object")), + ). + Parens( + j.List( + j.Id(m.i.WithPackage(Types, "Object")), + j.Id(m.i.WithPackage(Diag, "Diagnostics")), + ), + ). BlockFunc(func(g *j.Group) { - g.Add(diags) - g.Id("tf.Null").Op("=").False() - g.Id("tf.Unknown").Op("=").False() - g.If(j.Id("tf.Attrs").Op("==").Nil()).Block( - j.Id("tf.Attrs").Op("=").Make(j.Map(j.String()).Id(m.i.WithPackage(Attr, "Value"))), + // schema, diags := GenSchemaFoo(ctx) + g.List(j.Id("schema"), j.Id("diags")).Op(":=").Id("GenSchema" + m.Name).Call(j.Id("ctx")) + + // if diags.HasError() { + // return types.Object{}, diags + // } + g.If(j.Id("diags.HasError").Call()).Block( + j.Return( + j.Id(m.i.WithPackage(Types, "Object")).Values(), + j.Id("diags"), + ), + ) + + // schemaObj := schema.Type().(types.ObjectType) + g.Id("schemaObj").Op(":="). + Id("schema.Type").Call(). + Assert(j.Id(m.i.WithPackage(Types, "ObjectType"))) + + // if obj == nil { + // return types.ObjectNull(schemaObj.AttrTypes), diags + // } + g.If(j.Id("obj").Op("==").Nil()).Block( + j.Return( + j.Id(m.i.WithPackage(Types, "ObjectNull")).Call(j.Id("schemaObj.AttrTypes")), + j.Id("diags"), + ), ) + + // var attrs map[string]attr.Value + // if curr == nil || curr.Attributes() == nil { + // attrs = make(map[string]attr.Value) + // } + g.Var().Id("attrs").Map(j.String()).Id(m.i.WithPackage(Attr, "Value")) + g.If(j.Id("curr").Op("==").Nil().Op("||").Id("curr.Attributes").Call().Op("==").Nil()). + Block( + j.Id("attrs").Op("=").Make(j.Map(j.String()).Id(m.i.WithPackage(Attr, "Value"))), + ). + Else(). + Block( + j.Id("attrs").Op("=").Id("curr.Attributes").Call(), + ) + m.GenerateFields(g) - g.Return(j.Id("diags")) + + // result, resultDiags := types.ObjectValue(schemaObj.AttrTypes, attrs) + g.List(j.Id("result"), j.Id("resultDiags")).Op(":="). + Id(m.i.WithPackage(Types, "ObjectValue")).Call(j.Id("schemaObj.AttrTypes"), j.Id("attrs")) + + // diags.Append(resultDiags) + g.Id("diags.Append").Call(j.Id("resultDiags").Op("...")) + + // return result, diags + g.Return(j.Id("result"), j.Id("diags")) }) return writer.Write([]byte(method.GoString() + "\n")) @@ -51,6 +101,20 @@ func (m *MessageCopyToGenerator) GenerateFields(g *j.Group) { for _, f := range m.Fields { g.Add(NewFieldCopyToGenerator(f, m.i).Generate()) } + for _, f := range m.InjectedFields { + // if _, ok := attrs["foo"]; !ok { + // attrs["foo"] = types.NullString() + // } + g.If( + j.List(j.Id("_"), j.Id("ok")).Op(":="). + Id("attrs").Index(j.Lit(f.Name))).Op(";"). + Op("!").Id("ok"). + Block( + j.Id("attrs").Index(j.Lit(f.Name)). + Op("="). + Id(m.i.WithType(f.ValueMethod)).Call(), + ) + } } // FieldCopyToGenerator is a visitor for a field @@ -95,135 +159,120 @@ func (f *FieldCopyToGenerator) Generate() *j.Statement { return nil } -// nextField reads current field value from Terraform object and asserts it's type against expected -func (f *FieldCopyToGenerator) nextField(v string, g func(g *j.Group)) *j.Statement { - return j.Block( - // _, ok := ft.AttrsTypes["key"] - j.List(j.Id(v), j.Id("ok")).Op(":=").Id("tf.AttrTypes").Index(j.Lit(f.NameSnake)), - j.If(j.Id("!ok")).BlockFunc(f.errAttrMissingDiag).Else().BlockFunc(g), - ) -} - -// getAttr v, ok := tf.Attrs["name"] -func (f *FieldCopyToGenerator) getAttr(v string, typ string, g *j.Group) { - g.List( - j.Id(v), j.Id("ok"), - ).Op(":=").Id("tf.Attrs").Index( - j.Lit(f.Field.NameSnake), - ).Assert(j.Id(f.i.WithType(typ))) -} - -// genZeroValue generates zero value from an empty AttrType -func (f *FieldCopyToGenerator) genZeroValue(fieldName string) func(*j.Group) { - return func(g *j.Group) { - // This generates an empty attr.Value from a Terraform type - // v, err = t.ValueFromTerraform(ctx, tftypes.NewValue(t.TerraformType(ctx, nil))) - g.List(j.Id("i"), j.Id("err")).Op(":=").Id("t.ValueFromTerraform").Call( - j.Id("ctx"), - j.Id(f.i.WithPackage(TFTypes, "NewValue")).Call( - j.Id("t.TerraformType").Call(j.Id("ctx")), j.Nil(), - ), - ) - - // if err != nil { diags.AddError } - g.If(j.Id("err != nil")).Block( - j.Id("diags.Append").Call(j.Id("attrWriteGeneralError").Values(j.Lit(f.Path), j.Id("err"))), - ) - - // v, ok = i.(types.Time) - g.List(j.Id("v"), j.Id("ok")).Op("=").Id("i").Assert(j.Id(f.i.WithType(f.ElemValueType))) - - // if !ok { diags.AddError } - g.If(j.Id("!ok")).BlockFunc(f.errAttrConversionFailure(f.Path, f.ElemValueType)) - - if f.IsPlaceholder { - g.Id("v.Null").Op("=").True() - return - } - - // v.Null = v.Value == "" - if f.ZeroValue != "" { - g.Id("v.Null").Op("=").Id(f.i.WithType(f.ValueCastToType)).Parens(j.Id(fieldName)).Op("==").Id(f.ZeroValue) - } else { - g.Id("v.Null").Op("=").False() - } - } -} - // genPrimitiveBody generates block which reads object field into v func (f *FieldCopyToGenerator) genPrimitiveBody(fieldName string, g *j.Group) { - f.getAttr("v", f.i.WithType(f.Field.ElemValueType), g) - g.If(j.Id("!ok")).BlockFunc(f.genZeroValue(fieldName)) - - if !f.IsPlaceholder { - if f.ParentIsOptionalEmbed { - g.If(j.Id("obj." + f.ParentIsOptionalEmbedFieldName).Op("==").Nil()).Block( - j.Id("v.Null").Op("=").True(), - ).Else().Block(f.genAssignValue(fieldName)) - } else { - g.Add(f.genAssignValue(fieldName)) - } + // var v attr.Value + g.Var().Id("v").Id(f.i.WithPackage(Attr, "Value")) + + if f.IsPlaceholder { + // Set placeholder fields (for empty structs) to their null value. + g.Id("v").Op("=").Id(f.i.WithType(f.NullValueMethod)).Call() + return } - g.Id("v.Unknown").Op("=").False() + if f.ParentIsOptionalEmbed { + g.If(j.Id("obj." + f.ParentIsOptionalEmbedFieldName).Op("==").Nil()).Block( + j.Id("v").Op("=").Id(f.i.WithType(f.NullValueMethod)).Call(), + ).Else().BlockFunc(func(g *j.Group) { + f.genAssignValue(g, fieldName) + }) + } else { + f.genAssignValue(g, fieldName) + } } -func (f *FieldCopyToGenerator) genAssignValue(fieldName string) *j.Statement { +func (f *FieldCopyToGenerator) genAssignValue(g *j.Group, fieldName string) { if f.IsNullable { - return j.If(j.Id(fieldName).Op("==").Nil()).Block( - j.Id("v.Null").Op("=").True(), + // if obj.Foo == nil { + // v = types.NullString() + // } else { + // v = types.StringValue(string(*obj.Foo)) + // } + g.If(j.Id(fieldName).Op("==").Nil()).Block( + j.Id("v").Op("=").Id(f.i.WithType(f.NullValueMethod)).Call(), ).Else().Block( - j.Id("v.Null").Op("=").False(), - j.Id("v.Value").Op("=").Id(f.i.WithType(f.GoElemTypeIndirect)).Parens(j.Op("*").Add(j.Id(fieldName))), + j.Id("v").Op("="). + Id(f.i.WithType(f.ValueToMethod)). + Call( + j.Id(f.i.WithType(f.GoElemTypeIndirect)).Parens(j.Op("*").Add(j.Id(fieldName))), + ), ) + return + } + + // val := string(obj.Foo) + g.Id("val").Op(":="). + Id(f.i.WithType(f.ValueCastToType)).Parens(j.Id(fieldName)) + + if f.ZeroValue == "" { + // v = types.StringValue(val) + g.Id("v").Op("=").Id(f.i.WithType(f.ValueToMethod)).Call(j.Id("val")) + } else { + // For non-nullable fields, treat the zero value as null. + // + // if val == "" { + g.If(j.Id("val").Op("==").Id(f.ZeroValue)). + Block( + // v = types.StringNull() + j.Id("v").Op("=").Id(f.i.WithType(f.NullValueMethod)).Call(), + ). + // } else { + Else(). + Block( + // v = types.StringValue(val) + j.Id("v").Op("=").Id(f.i.WithType(f.ValueToMethod)).Call(j.Id("val")), + ) } - return j.Id("v.Value").Op("=").Id(f.i.WithType(f.ValueCastToType)).Parens(j.Id(fieldName)) } // genObjectBody generates block which reads message into v func (f *FieldCopyToGenerator) genObjectBody(m *MessageCopyToGenerator, fieldName string, typ string, g *j.Group) { - copyObj := func(g *j.Group) { - if len(m.Fields) > 0 { - if !m.IsEmpty { - g.Id("obj").Op(":=").Id(fieldName) + // Wrap object conversion in an anonymous function so we don't shadow the + // parent object's attrs map etc. + // + // v := func() attr.Value { ... }() + g.Id("v").Op(":=").Func(). + Params(). + Id(f.i.WithPackage(Attr, "Value")). + BlockFunc(func(g *j.Group) { + if f.OneOfName != "" { + f.genOneOfStub(g) } - g.Id("tf").Op(":=").Id("&v") - m.GenerateFields(g) - } - } - f.getAttr("v", f.Field.ElemValueType, g) - g.If(j.Id("!ok")).Block( - // v := types.Object{Attrs: make(map[string]attr.Value, len(o.AttrTypes)), AttrTypes: o.AttrTypes} - j.Id("v").Op("=").Id(f.i.WithType(typ)).Block(j.Dict{ - j.Id("Attrs"): j.Make(j.Map(j.String()).Id(f.i.WithPackage(Attr, "Value")), j.Len(j.Id("o.AttrTypes"))), - j.Id("AttrTypes"): j.Id("o.AttrTypes"), - }), - ).Else().Block( - j.If(j.Id("v.Attrs").Op("==").Nil()).Block( - j.Id("v.Attrs").Op("=").Make(j.Map(j.String()).Id(f.i.WithPackage(Attr, "Value")), j.Len(j.Id("tf.AttrTypes"))), - ), - ) - if f.IsNullable { - // if obj.Nested == nil - g.If(j.Id(fieldName).Op("==").Nil()).Block( - j.Id("v.Null").Op("=").True(), - ).Else().BlockFunc( - copyObj, - ) - } else { - g.BlockFunc(copyObj) - } - g.Id("v.Unknown").Op("=").False() -} + if f.IsNullable { + // if obj.Nested == nil + g.If(j.Id(fieldName).Op("==").Nil()).Block( + // return types.ObjectNull(schemaObj.AttrTypes) + j.Return(j.Id(f.i.WithPackage(Types, "ObjectNull")).Call(j.Id("schemaObj.AttrTypes"))), + ) + } -// assertTo asserts a to typ -func (f *FieldCopyToGenerator) assertTo(typ string, g *j.Group, els func(g *j.Group)) { - // v, ok := a.(types.ListType) - g.List(j.Id("o"), j.Id("ok")).Op(":=").Id("a").Assert(j.Id(f.i.WithType(typ))) - g.If(j.Id("!ok")).BlockFunc( - f.errAttrConversionFailure(f.Path, f.Field.Type), - ).Else().BlockFunc(els) + // attrs := make(map[string]attr.Value) + g.Id("attrs").Op(":=").Make(j.Map(j.String()).Id(f.i.WithPackage(Attr, "Value"))) + if len(m.Fields) > 0 { + g.BlockFunc(func(g *j.Group) { + if !m.IsEmpty { + g.Id("obj").Op(":=").Id(fieldName) + } + m.GenerateFields(g) + }) + } + + // result, objDiags := types.ObjectValue(schema.AttrTypes, attrs) + g.List( + j.Id("result"), + j.Id("objDiags"), + ).Op(":=").Id( + f.i.WithPackage(Types, "ObjectValue"), + ).Call(j.Id("schemaObj.AttrTypes"), j.Id("attrs")) + + // diags.Append(objDiags...) + g.Id("diags.Append").Call(j.Id("objDiags").Op("...")) + + // return result + g.Return(j.Id("result")) + }). + Call() } // getValueField returns list/map value field @@ -239,13 +288,13 @@ func (f *FieldCopyToGenerator) getValueField() *Field { func (f *FieldCopyToGenerator) genPrimitive() *j.Statement { fieldName := "obj." + f.Name - return f.nextField("t", func(g *j.Group) { + return j.BlockFunc(func(g *j.Group) { if f.OneOfName != "" { f.genOneOfStub(g) } f.genPrimitiveBody(fieldName, g) - g.Id("tf.Attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") + g.Id("attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") }) } @@ -254,15 +303,15 @@ func (f *FieldCopyToGenerator) genObject() *j.Statement { m := NewMessageCopyToGenerator(f.Message, f.i) fieldName := "obj." + f.Name - return f.nextField("a", func(g *j.Group) { - if f.OneOfName != "" { - f.genOneOfStub(g) - } + return j.BlockFunc(func(g *j.Group) { + // schemaObj := schemaObj.Attributes["foo"].Type.(types.ObjectType) + g.Id("schemaObj").Op(":="). + Id("schemaObj.AttrTypes"). + Index(j.Lit(f.NameSnake)). + Assert(j.Id(f.i.WithPackage(Types, "ObjectType"))) - f.assertTo(f.Field.ElemType, g, func(g *j.Group) { - f.genObjectBody(m, fieldName, f.Field.ValueType, g) - g.Id("tf.Attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") - }) + f.genObjectBody(m, fieldName, f.Field.ValueType, g) + g.Id("attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") }) } @@ -280,48 +329,65 @@ func (f *FieldCopyToGenerator) genOneOfStub(g *j.Group) { func (f *FieldCopyToGenerator) genListOrMap() *j.Statement { fieldName := "obj." + f.Name - var mk j.Code + var makeElems, constructor, nullValue, elemType j.Code if f.IsMap { + // elemType := schemaObj.AttrTypes["foo"].(types.MapType).ElemType + elemType = j.Id("elemType").Op(":="). + Id("schemaObj.AttrTypes"). + Index(j.Lit(f.NameSnake)). + Assert(j.Id(f.i.WithPackage(Types, "MapType"))). + Dot("ElemType") + // make(map[string]attr.Value, len(obj.Map)) - mk = j.Make(j.Map(j.String()).Id(f.i.WithPackage(Attr, "Value")), j.Len(j.Id(fieldName))) + makeElems = j.Make(j.Map(j.String()).Id(f.i.WithPackage(Attr, "Value")), j.Len(j.Id(fieldName))) + + // types.MapValue + constructor = j.Id(f.i.WithPackage(Types, "MapValue")) + + // types.MapNull + nullValue = j.Id(f.i.WithPackage(Types, "MapNull")) } + if f.IsRepeated { - // make(map[string]attr.Value, len(obj.List)) - mk = j.Make(j.Index().Id(f.i.WithPackage(Attr, "Value")), j.Len(j.Id(fieldName))) + // elemType := schemaObj.AttrTypes["foo"].(types.ListType).ElemType + elemType = j.Id("elemType").Op(":="). + Id("schemaObj.AttrTypes"). + Index(j.Lit(f.NameSnake)). + Assert(j.Id(f.i.WithPackage(Types, "ListType"))). + Dot("ElemType") + + // make([]attr.Value, len(obj.List)) + makeElems = j.Make(j.Index().Id(f.i.WithPackage(Attr, "Value")), j.Len(j.Id(fieldName))) + + // types.ListValue + constructor = j.Id(f.i.WithPackage(Types, "ListValue")) + + // types.ListNull + nullValue = j.Id(f.i.WithPackage(Types, "ListNull")) } - return f.nextField("a", func(g *j.Group) { - f.assertTo(f.Field.Type, g, func(g *j.Group) { - f.getAttr("c", f.Field.ValueType, g) - - g.If(j.Id("!ok")).Block( - // c := types.Object{Elems: make([]attr.Value, ElemType: o.ElemType} - j.Id("c").Op("=").Id(f.i.WithType(f.Field.ValueType)).Block(j.Dict{ - j.Id("Elems"): mk, - j.Id("ElemType"): j.Id("o.ElemType"), - j.Id("Null"): j.True(), - }), - ).Else().Block( - j.If(j.Id("c.Elems").Op("==").Nil()).Block( - j.Id("c.Elems").Op("=").Add(mk), - ), - ) + return j.BlockFunc(func(g *j.Group) { + g.Add(elemType) - g.If(j.Id(fieldName)).Op("!=").Nil().BlockFunc(func(g *j.Group) { - if (f.Kind == PrimitiveListKind) || (f.Kind == PrimitiveMapKind) { - g.Id("t").Op(":=").Id("o.ElemType") - } else { - g.Id("o").Op(":=").Id("o.ElemType").Assert(j.Id(f.i.WithType(f.ElemType))) - } + // var v attr.Value + g.Var().Id("v").Id(f.i.WithPackage(Attr, "Value")) - if f.IsRepeated { - // It might happen that we changed the number of elements. - // This check creates a new array if that's the case. - // Otherwise, we would have a panic at the last line in the For loop or extra elements. - g.If(j.Len(j.Id(fieldName)).Op("!=").Len(j.Id("c.Elems"))).Block( - j.Id("c.Elems").Op("=").Add(mk), - ) + // if len(obj.Foo) == 0 { + g.If(j.Id("len").Call(j.Id(fieldName)).Op("==").Lit(0)).Block( + j.Id("v").Op("=").Add(nullValue).Call(j.Id("elemType")), + ). + Else(). + BlockFunc(func(g *j.Group) { + g.Id("elems").Op(":=").Add(makeElems) + + if f.Kind == ObjectListKind || f.Kind == ObjectMapKind { + // Schema of the objects inside the list or map, referred to + // by genObjectBody. + // + // schemaObj := elemType.(types.ObjectType) + g.Id("schemaObj").Op(":="). + Id("elemType").Assert(j.Id(f.i.WithPackage(Types, "ObjectType"))) } // for k, a := range obj.List @@ -332,27 +398,31 @@ func (f *FieldCopyToGenerator) genListOrMap() *j.Statement { m := NewMessageCopyToGenerator(f.getValueField().Message, f.i) f.genObjectBody(m, "a", f.i.WithType(f.Field.ElemValueType), g) } - g.Id("c.Elems").Index(j.Id("k")).Op("=").Id("v") + g.Id("elems").Index(j.Id("k")).Op("=").Id("v") }) - // if len(obj.Test) > 0 - g.If(j.Len(j.Id(fieldName))).Op(">").Lit(0).Block( - j.Id("c.Null").Op("=").False(), - ) + // result, resultDiags := types.ListValue(elemType, elems) + g.List(j.Id("result"), j.Id("resultDiags")).Op(":="). + Add(constructor). + Call(j.Id("elemType"), j.Id("elems")) + + // diags.Append(resultDiags...) + g.Id("diags.Append").Call(j.Id("resultDiags").Op("...")) + + // v = result + g.Id("v").Op("=").Id("result") }) - g.Id("c.Unknown").Op("=").False() - g.Id("tf.Attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("c") - }) + g.Id("attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") }) } // genCustom generates statement representing custom type func (f *FieldCopyToGenerator) genCustom() *j.Statement { - return f.nextField("t", func(g *j.Group) { + return j.BlockFunc(func(g *j.Group) { g.Id("v").Op(":=").Id("CopyTo"+f.Suffix).Params( - j.Id("diags"), j.Id("obj."+f.Name), j.Id("t"), j.Id("tf.Attrs").Index(j.Lit(f.NameSnake)), + j.Id("diags"), j.Id("obj."+f.Name), ) - g.Id("tf.Attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") + g.Id("attrs").Index(j.Lit(f.NameSnake)).Op("=").Id("v") }) } diff --git a/go.mod b/go.mod index 174f5fc..a747be2 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,13 @@ require ( github.com/dave/jennifer v1.4.1 github.com/gogo/protobuf v1.3.2 github.com/gravitational/trace v1.2.1 - github.com/hashicorp/terraform-plugin-framework v0.10.0 - github.com/hashicorp/terraform-plugin-go v0.12.0 + github.com/hashicorp/terraform-plugin-framework v0.16.0 + github.com/hashicorp/terraform-plugin-go v0.14.1 github.com/sirupsen/logrus v1.9.0 github.com/stoewer/go-strcase v1.2.0 github.com/stretchr/testify v1.7.2 golang.org/x/tools v0.1.7 - google.golang.org/protobuf v1.28.0 + google.golang.org/protobuf v1.28.1 gopkg.in/yaml.v3 v3.0.1 ) @@ -20,9 +20,9 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.13.0 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/google/go-cmp v0.5.8 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/hashicorp/go-hclog v1.2.1 // indirect - github.com/hashicorp/terraform-plugin-log v0.6.0 // indirect + github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect github.com/jonboulle/clockwork v0.3.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/go.sum b/go.sum index 02444a9..bfaa9c7 100644 --- a/go.sum +++ b/go.sum @@ -52,20 +52,20 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gravitational/trace v1.2.1 h1:Iaf43aqbKV5H8bdiRs1qByjEHgAfADJ0lt0JwRyu+q8= github.com/gravitational/trace v1.2.1/go.mod h1:n0ijrq6psJY0sOI/NzLp+xdd8xl79jjwzVOFHDY6+kQ= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/go-hclog v1.2.1 h1:YQsLlGDJgwhXFpucSPyVbCBviQtjlHv3jLTlp8YmtEw= github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/terraform-plugin-framework v0.10.0 h1:LGYcnvNdVaZA1ZHe53BHLVjaaGs7HTiq6+9Js29stL4= -github.com/hashicorp/terraform-plugin-framework v0.10.0/go.mod h1:CK7Opzukfu/2CPJs+HzUdfHrFlp+ZIQeSxjF0x8k464= -github.com/hashicorp/terraform-plugin-go v0.12.0 h1:6wW9mT1dSs0Xq4LR6HXj1heQ5ovr5GxXNJwkErZzpJw= -github.com/hashicorp/terraform-plugin-go v0.12.0/go.mod h1:kwhmaWHNDvT1B3QiSJdAtrB/D4RaKSY/v3r2BuoWK4M= -github.com/hashicorp/terraform-plugin-log v0.6.0 h1:/Vq78uSIdUSZ3iqDc9PESKtwt8YqNKN6u+khD+lLjuw= -github.com/hashicorp/terraform-plugin-log v0.6.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= +github.com/hashicorp/terraform-plugin-framework v0.16.0 h1:kEHh0d6dp5Ig/ey6PYXkWDZPMLIW8Me41T/Oa7bpO4s= +github.com/hashicorp/terraform-plugin-framework v0.16.0/go.mod h1:Vk5MuIJoE1qksHZawAZr6psx6YXsQBFIKDrWbROrwus= +github.com/hashicorp/terraform-plugin-go v0.14.1 h1:cwZzPYla82XwAqpLhSzdVsOMU+6H29tczAwrB0z9Zek= +github.com/hashicorp/terraform-plugin-go v0.14.1/go.mod h1:Bc/K6K26BQ2FHqIELPbpKtt2CzzbQou+0UQF3/0NsCQ= +github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R+Y2BQ0sRZftGKQs= +github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= @@ -217,8 +217,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/imports_test.go b/imports_test.go index 0acbc92..e6d0edb 100644 --- a/imports_test.go +++ b/imports_test.go @@ -44,7 +44,7 @@ func TestSet(t *testing.T) { require.Equal(t, s.PrependPackageNameIfMissing("[]Test", "test"), "[]test.Test") require.Equal(t, s.WithType("UseValidator(1)"), "UseValidator(1)") - require.Equal(t, s.WithType("github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown()"), "github_com_hashicorp_terraform_plugin_framework_tfsdk.UseStateForUnknown()") + require.Equal(t, s.WithType("github.com/hashicorp/terraform-plugin-framework/resource.UseStateForUnknown()"), "github_com_hashicorp_terraform_plugin_framework_resource.UseStateForUnknown()") require.Equal(t, s.WithType(`UseValidator("teleport.dev/origin")`), `UseValidator("teleport.dev/origin")`) require.Equal(t, s.WithType("types.Values"), "example_com_package_types.Values") diff --git a/test/config.yaml b/test/config.yaml index 7ed39a7..1b3436e 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -22,28 +22,34 @@ name_overrides: Test.Str: "str" time_type: - type: "TimeType" # Struct name of attrs.Type - value_type: "TimeValue" # Struct name of attrs.Value - cast_to_type: "time.Time" # Go type of .Value - cast_from_type: "time.Time" # Go type of an object field + type: "TimeType" # Struct name of attrs.Type + value_type: "TimeValue" # Struct name of attrs.Value + value_from_method: "ValueTime" # Method to get value from Terraform attribute + value_to_method: "ValueTime" # Method to construct Terraform attribute from value + null_value_method: "NullTime" # Method to get null value + cast_to_type: "time.Time" # Go type of .Value + cast_from_type: "time.Time" # Go type of an object field type_constructor: UseRFC3339Time() duration_type: - type: "DurationType" # Struct name of attrs.Type - value_type: "DurationValue" # Struct name of attrs.Value - cast_to_type: "time.Duration" # Go type of .Value + type: "DurationType" # Struct name of attrs.Type + value_type: "DurationValue" # Struct name of attrs.Value + value_from_method: "ValueDuration" # Method to get value from Terraform attribute + value_to_method: "ValueDuration" # Method to construct Terraform attribute from value + null_value_method: "NullDuration" # Method to get null value + cast_to_type: "time.Duration" # Go type of .Value cast_from_type: "time.Duration" # Go type of an object field injected_fields: Test: - - - name: id + - name: id type: github.com/hashicorp/terraform-plugin-framework/types.StringType computed: true + value_method: github.com/hashicorp/terraform-plugin-framework/types.StringUnknown plan_modifiers: "Test.Str": - - github.com/hashicorp/terraform-plugin-framework/tfsdk.UseStateForUnknown() + - github.com/hashicorp/terraform-plugin-framework/resource.UseStateForUnknown() validators: "Test.Str": diff --git a/test/copy_from_terraform_test.go b/test/copy_from_terraform_test.go index f984db5..0934320 100644 --- a/test/copy_from_terraform_test.go +++ b/test/copy_from_terraform_test.go @@ -155,7 +155,7 @@ func TestCopyFromCustom(t *testing.T) { func TestCopyFromOneOfScalarBranch(t *testing.T) { obj := copyFromTerraformObject(t) - obj.Attrs["branch3"] = types.String{Value: "Test"} + obj.Attributes()["branch3"] = types.StringValue("Test") target := Test{} diags := CopyTestFromTerraform(context.Background(), obj, &target) @@ -166,14 +166,18 @@ func TestCopyFromOneOfScalarBranch(t *testing.T) { func TestCopyFromOneOfObjectBranch(t *testing.T) { obj := copyFromTerraformObject(t) - obj.Attrs["branch2"] = types.Object{ - Attrs: map[string]attr.Value{ - "int32": types.Int64{Value: 5}, + + branch2, diags := types.ObjectValue( + obj.AttributeTypes(context.Background())["branch2"].(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "int32": types.Int64Value(5), }, - } + ) + requireNoDiagErrors(t, diags) + obj.Attributes()["branch2"] = branch2 target := Test{} - diags := CopyTestFromTerraform(context.Background(), obj, &target) + diags = CopyTestFromTerraform(context.Background(), obj, &target) requireNoDiagErrors(t, diags) require.Equal(t, int32(5), target.OneOf.(*Test_Branch2).Branch2.Int32) @@ -214,7 +218,7 @@ func TestCopyFromNullableEmbeddedFieldWithoutValue(t *testing.T) { obj := copyFromTerraformObject(t) // set a null value - obj.Attrs["max_age"] = DurationValue{Null: true} + obj.Attributes()["max_age"] = DurationValue{Null: true} target := Test{} diags := CopyTestFromTerraform(context.Background(), obj, &target) diff --git a/test/copy_to_terraform_test.go b/test/copy_to_terraform_test.go index abe033c..096938d 100644 --- a/test/copy_to_terraform_test.go +++ b/test/copy_to_terraform_test.go @@ -27,323 +27,300 @@ import ( ) func TestCopyToTerraformPrimitives(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) - require.Equal(t, "TestString", o.Attrs["str"].(types.String).Value) - require.False(t, o.Attrs["str"].(types.String).Unknown) - require.False(t, o.Attrs["str"].(types.String).Null) + require.Equal(t, "TestString", o.Attributes()["str"].(types.String).ValueString()) + require.False(t, o.Attributes()["str"].(types.String).IsUnknown()) + require.False(t, o.Attributes()["str"].(types.String).IsNull()) - require.Equal(t, int64(888), o.Attrs["int32"].(types.Int64).Value) - require.False(t, o.Attrs["int32"].(types.Int64).Unknown) - require.False(t, o.Attrs["int32"].(types.Int64).Null) + require.Equal(t, int64(888), o.Attributes()["int32"].(types.Int64).ValueInt64()) + require.False(t, o.Attributes()["int32"].(types.Int64).IsUnknown()) + require.False(t, o.Attributes()["int32"].(types.Int64).IsNull()) - require.Equal(t, int64(999), o.Attrs["int64"].(types.Int64).Value) - require.False(t, o.Attrs["int64"].(types.Int64).Unknown) - require.False(t, o.Attrs["int64"].(types.Int64).Null) + require.Equal(t, int64(999), o.Attributes()["int64"].(types.Int64).ValueInt64()) + require.False(t, o.Attributes()["int64"].(types.Int64).IsUnknown()) + require.False(t, o.Attributes()["int64"].(types.Int64).IsNull()) - require.Equal(t, float64(88.5), o.Attrs["float"].(types.Float64).Value) - require.False(t, o.Attrs["float"].(types.Float64).Unknown) - require.False(t, o.Attrs["float"].(types.Float64).Null) + require.Equal(t, float64(88.5), o.Attributes()["float"].(types.Float64).ValueFloat64()) + require.False(t, o.Attributes()["float"].(types.Float64).IsUnknown()) + require.False(t, o.Attributes()["float"].(types.Float64).IsNull()) - require.Equal(t, float64(99.5), o.Attrs["double"].(types.Float64).Value) - require.False(t, o.Attrs["double"].(types.Float64).Unknown) - require.False(t, o.Attrs["double"].(types.Float64).Null) + require.Equal(t, float64(99.5), o.Attributes()["double"].(types.Float64).ValueFloat64()) + require.False(t, o.Attributes()["double"].(types.Float64).IsUnknown()) + require.False(t, o.Attributes()["double"].(types.Float64).IsNull()) - require.True(t, o.Attrs["bool"].(types.Bool).Value) - require.False(t, o.Attrs["bool"].(types.Bool).Unknown) - require.False(t, o.Attrs["bool"].(types.Bool).Null) + require.True(t, o.Attributes()["bool"].(types.Bool).ValueBool()) + require.False(t, o.Attributes()["bool"].(types.Bool).IsUnknown()) + require.False(t, o.Attributes()["bool"].(types.Bool).IsNull()) - require.Equal(t, "TestBytes", o.Attrs["bytes"].(types.String).Value) - require.False(t, o.Attrs["bytes"].(types.String).Unknown) - require.False(t, o.Attrs["bytes"].(types.String).Null) + require.Equal(t, "TestBytes", o.Attributes()["bytes"].(types.String).ValueString()) + require.False(t, o.Attributes()["bytes"].(types.String).IsUnknown()) + require.False(t, o.Attributes()["bytes"].(types.String).IsNull()) } func TestCopyToTime(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) - require.Equal(t, timestamp, o.Attrs["timestamp"].(TimeValue).Value) - require.False(t, o.Attrs["timestamp"].(TimeValue).Unknown) - require.False(t, o.Attrs["timestamp"].(TimeValue).Null) + require.Equal(t, timestamp, o.Attributes()["timestamp"].(TimeValue).Value) + require.False(t, o.Attributes()["timestamp"].(TimeValue).IsUnknown()) + require.False(t, o.Attributes()["timestamp"].(TimeValue).IsNull()) - require.Equal(t, time.Time{}, o.Attrs["timestamp_missing"].(TimeValue).Value) - require.False(t, o.Attrs["timestamp_missing"].(TimeValue).Unknown) + require.Equal(t, time.Time{}, o.Attributes()["timestamp_missing"].(TimeValue).Value) + require.False(t, o.Attributes()["timestamp_missing"].(TimeValue).IsUnknown()) // Handle empty time value - // require.True(t, o.Attrs["timestamp_missing"].(TimeValue).Null) + // require.True(t, o.Attributes()["timestamp_missing"].(TimeValue).IsNull()) } func TestCopyToDuration(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) - require.Equal(t, duration, o.Attrs["duration_standard"].(DurationValue).Value) - require.False(t, o.Attrs["duration_standard"].(DurationValue).Unknown) - require.False(t, o.Attrs["duration_standard"].(DurationValue).Null) + require.Equal(t, duration, o.Attributes()["duration_standard"].(DurationValue).Value) + require.False(t, o.Attributes()["duration_standard"].(DurationValue).IsUnknown()) + require.False(t, o.Attributes()["duration_standard"].(DurationValue).IsNull()) - require.Equal(t, duration, o.Attrs["duration_custom"].(DurationValue).Value) - require.False(t, o.Attrs["duration_custom"].(DurationValue).Unknown) - require.False(t, o.Attrs["duration_custom"].(DurationValue).Null) + require.Equal(t, duration, o.Attributes()["duration_custom"].(DurationValue).Value) + require.False(t, o.Attributes()["duration_custom"].(DurationValue).IsUnknown()) + require.False(t, o.Attributes()["duration_custom"].(DurationValue).IsNull()) } func TestCopyToNested(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "TestString"}, - o.Attrs["nested"].(types.Object).Attrs["str"].(types.String), + types.StringValue("TestString"), + o.Attributes()["nested"].(types.Object).Attributes()["str"].(types.String), ) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "TestString"}, - o.Attrs["nested_nullable"].(types.Object).Attrs["str"].(types.String), + types.StringValue("TestString"), + o.Attributes()["nested_nullable"].(types.Object).Attributes()["str"].(types.String), ) - require.True(t, o.Attrs["nested_nullable_with_nil_value"].(types.Object).Null) + require.True(t, o.Attributes()["nested_nullable_with_nil_value"].(types.Object).IsNull()) } func TestCopyToList(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) require.Equal(t, []attr.Value{ - types.String{Null: false, Unknown: false, Value: "el1"}, - types.String{Null: false, Unknown: false, Value: "el2"}, - }, o.Attrs["string_list"].(types.List).Elems) + types.StringValue("el1"), + types.StringValue("el2"), + }, o.Attributes()["string_list"].(types.List).Elements()) - require.Equal(t, types.List{ - Null: true, - Unknown: false, - Elems: make([]attr.Value, 0), - ElemType: types.StringType, - }, o.Attrs["string_list_empty"].(types.List)) + require.Equal(t, + types.ListNull(types.StringType), + o.Attributes()["string_list_empty"].(types.List), + ) require.Equal(t, []attr.Value{ - types.String{Null: false, Unknown: false, Value: "bytes1"}, - types.String{Null: false, Unknown: false, Value: "bytes2"}, - }, o.Attrs["bytes_list"].(types.List).Elems) + types.StringValue("bytes1"), + types.StringValue("bytes2"), + }, o.Attributes()["bytes_list"].(types.List).Elements()) require.Equal(t, []attr.Value{ - TimeValue{Null: false, Unknown: false, Value: timestamp, Format: time.RFC3339}, - TimeValue{Null: false, Unknown: false, Value: timestamp, Format: time.RFC3339}, - }, o.Attrs["timestamp_list"].(types.List).Elems) + ValueTime(timestamp), + ValueTime(timestamp), + }, o.Attributes()["timestamp_list"].(types.List).Elements()) require.Equal(t, []attr.Value{ - DurationValue{Null: false, Unknown: false, Value: duration}, - DurationValue{Null: false, Unknown: false, Value: duration}, - }, o.Attrs["duration_custom_list"].(types.List).Elems) + ValueDuration(duration), + ValueDuration(duration), + }, o.Attributes()["duration_custom_list"].(types.List).Elements()) } func TestCopyTo_ChangeListSize(t *testing.T) { - o := copyToTerraformObject(t) - testObject := createTestObj() // Start with two elements. - diags := CopyTestToTerraform(context.Background(), testObject, &o) + o, diags := CopyTestToTerraform(context.Background(), testObject, emptyObject()) requireNoDiagErrors(t, diags) require.Equal(t, []attr.Value{ - types.String{Null: false, Unknown: false, Value: "el1"}, - types.String{Null: false, Unknown: false, Value: "el2"}, - }, o.Attrs["string_list"].(types.List).Elems) + types.StringValue("el1"), + types.StringValue("el2"), + }, o.Attributes()["string_list"].(types.List).Elements()) // Increase to 3, array access must not panic. testObject.StringList = []string{"el1", "el2", "el3"} - diags = CopyTestToTerraform(context.Background(), testObject, &o) + o, diags = CopyTestToTerraform(context.Background(), testObject, &o) requireNoDiagErrors(t, diags) require.Equal(t, []attr.Value{ - types.String{Null: false, Unknown: false, Value: "el1"}, - types.String{Null: false, Unknown: false, Value: "el2"}, - types.String{Null: false, Unknown: false, Value: "el3"}, - }, o.Attrs["string_list"].(types.List).Elems) + types.StringValue("el1"), + types.StringValue("el2"), + types.StringValue("el3"), + }, o.Attributes()["string_list"].(types.List).Elements()) // Decrease to a single element, others should be removed. testObject.StringList = []string{"elX"} - diags = CopyTestToTerraform(context.Background(), testObject, &o) + o, diags = CopyTestToTerraform(context.Background(), testObject, &o) requireNoDiagErrors(t, diags) require.Equal(t, []attr.Value{ - types.String{Null: false, Unknown: false, Value: "elX"}, - }, o.Attrs["string_list"].(types.List).Elems) + types.StringValue("elX"), + }, o.Attributes()["string_list"].(types.List).Elements()) } func TestCopyToNestedList(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) - nestedList := o.Attrs["nested_list"].(types.List) - firstEl := nestedList.Elems[0].(types.Object) + nestedList := o.Attributes()["nested_list"].(types.List) + firstEl := nestedList.Elements()[0].(types.Object) - require.Len(t, nestedList.Elems, 1) + require.Len(t, nestedList.Elements(), 1) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test"}, - firstEl.Attrs["str"], + types.StringValue("Test"), + firstEl.Attributes()["str"], ) - nestedNestedList := o.Attrs["nested_list"].(types.List).Elems[0].(types.Object).Attrs["nested_list"].(types.List) + nestedNestedList := o.Attributes()["nested_list"].(types.List).Elements()[0].(types.Object).Attributes()["nested_list"].(types.List) - require.Len(t, nestedNestedList.Elems, 2) + require.Len(t, nestedNestedList.Elements(), 2) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test1"}, - nestedNestedList.Elems[0].(types.Object).Attrs["str"], + types.StringValue("Test1"), + nestedNestedList.Elements()[0].(types.Object).Attributes()["str"], ) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test2"}, - nestedNestedList.Elems[1].(types.Object).Attrs["str"], + types.StringValue("Test2"), + nestedNestedList.Elements()[1].(types.Object).Attributes()["str"], ) - nestedMap := firstEl.Attrs["map"].(types.Map) + nestedMap := firstEl.Attributes()["map"].(types.Map) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "value1"}, - nestedMap.Elems["key1"].(types.String), + types.StringValue("value1"), + nestedMap.Elements()["key1"].(types.String), ) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "value2"}, - nestedMap.Elems["key2"].(types.String), + types.StringValue("value2"), + nestedMap.Elements()["key2"].(types.String), ) - nestedMapObject := firstEl.Attrs["map_object_nested"].(types.Map) + nestedMapObject := firstEl.Attributes()["map_object_nested"].(types.Map) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test1"}, - nestedMapObject.Elems["key1"].(types.Object).Attrs["str"].(types.String), + types.StringValue("Test1"), + nestedMapObject.Elements()["key1"].(types.Object).Attributes()["str"].(types.String), ) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test2"}, - nestedMapObject.Elems["key2"].(types.Object).Attrs["str"].(types.String), + types.StringValue("Test2"), + nestedMapObject.Elements()["key2"].(types.Object).Attributes()["str"].(types.String), ) - nestedListNullable := o.Attrs["nested_list_nullable"].(types.List) + nestedListNullable := o.Attributes()["nested_list_nullable"].(types.List) - require.Len(t, nestedListNullable.Elems, 1) + require.Len(t, nestedListNullable.Elements(), 1) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test"}, - nestedListNullable.Elems[0].(types.Object).Attrs["str"], + types.StringValue("Test"), + nestedListNullable.Elements()[0].(types.Object).Attributes()["str"], ) } func TestCopyToMap(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) - m := o.Attrs["map"].(types.Map).Elems + m := o.Attributes()["map"].(types.Map).Elements() - require.Equal(t, types.String{Null: false, Unknown: false, Value: "value1"}, m["key1"].(types.String)) - require.Equal(t, types.String{Null: false, Unknown: false, Value: "value2"}, m["key2"].(types.String)) + require.Equal(t, types.StringValue("value1"), m["key1"].(types.String)) + require.Equal(t, types.StringValue("value2"), m["key2"].(types.String)) } func TestCopyToCustom(t *testing.T) { - o := copyToTerraformObject(t) - - diags := CopyTestToTerraform(context.Background(), createTestObj(), &o) + o, diags := CopyTestToTerraform(context.Background(), createTestObj(), emptyObject()) requireNoDiagErrors(t, diags) require.Equal( t, []attr.Value{ - types.Bool{Null: false, Unknown: false, Value: false}, - types.Bool{Null: false, Unknown: false, Value: false}, - types.Bool{Null: false, Unknown: false, Value: true}, + types.BoolValue(false), + types.BoolValue(false), + types.BoolValue(true), }, - o.Attrs["bool_custom_list"].(types.List).Elems, + o.Attributes()["bool_custom_list"].(types.List).Elements(), ) } func TestCopyToOneOfBranch3(t *testing.T) { - o := copyToTerraformObject(t) testObj := createTestObj() testObj.OneOf = &Test_Branch3{Branch3: "Test"} - diags := CopyTestToTerraform(context.Background(), testObj, &o) + o, diags := CopyTestToTerraform(context.Background(), testObj, emptyObject()) requireNoDiagErrors(t, diags) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "Test"}, - o.Attrs["branch3"].(types.String), + types.StringValue("Test"), + o.Attributes()["branch3"].(types.String), ) } func TestCopyToOneOfBranch2(t *testing.T) { - o := copyToTerraformObject(t) testObj := createTestObj() testObj.OneOf = &Test_Branch2{Branch2: &Branch2{Int32: 5}} - diags := CopyTestToTerraform(context.Background(), testObj, &o) + o, diags := CopyTestToTerraform(context.Background(), testObj, emptyObject()) requireNoDiagErrors(t, diags) require.Equal( t, - types.Int64{Null: false, Unknown: false, Value: 5}, - o.Attrs["branch2"].(types.Object).Attrs["int32"], + types.Int64Value(5), + o.Attributes()["branch2"].(types.Object).Attributes()["int32"], ) } func TestCopyToOneOfNoBranch(t *testing.T) { - o := copyToTerraformObject(t) testObj := createTestObj() - diags := CopyTestToTerraform(context.Background(), testObj, &o) + o, diags := CopyTestToTerraform(context.Background(), testObj, emptyObject()) requireNoDiagErrors(t, diags) - require.True(t, o.Attrs["branch1"].(types.Object).Null) - require.True(t, o.Attrs["branch2"].(types.Object).Null) - require.True(t, o.Attrs["branch3"].(types.String).Null) + // If one of the oneOf branches is a primitive, the zero value should be treated as null. + + require.True(t, o.Attributes()["branch1"].(types.Object).IsNull()) + require.True(t, o.Attributes()["branch2"].(types.Object).IsNull()) + require.True(t, o.Attributes()["branch3"].(types.String).IsNull()) } func TestCopyToEmbeddedField(t *testing.T) { - o := copyToTerraformObject(t) testObj := createTestObj() - diags := CopyTestToTerraform(context.Background(), testObj, &o) + o, diags := CopyTestToTerraform(context.Background(), testObj, emptyObject()) requireNoDiagErrors(t, diags) - require.Equal(t, "embdtest1", o.Attrs["embedded_string"].(types.String).Value) - require.False(t, o.Attrs["embedded_string"].(types.String).Unknown) - require.False(t, o.Attrs["embedded_string"].(types.String).Null) + require.Equal(t, "embdtest1", o.Attributes()["embedded_string"].(types.String).ValueString()) + require.False(t, o.Attributes()["embedded_string"].(types.String).IsUnknown()) + require.False(t, o.Attributes()["embedded_string"].(types.String).IsNull()) - require.Equal(t, "embdtest2", o.Attrs["embedded_nested_field"].(types.Object).Attrs["embedded_nested_string"].(types.String).Value) + require.Equal(t, "embdtest2", o.Attributes()["embedded_nested_field"].(types.Object).Attributes()["embedded_nested_string"].(types.String).ValueString()) } func TestCopyToOneOfLowercase(t *testing.T) { - o := copyToTerraformObject(t) testObj := createTestObj() testObj.LowerSnakeOneof = &Test_Foo{Foo: "1234"} - diags := CopyTestToTerraform(context.Background(), testObj, &o) + o, diags := CopyTestToTerraform(context.Background(), testObj, emptyObject()) requireNoDiagErrors(t, diags) require.Equal( t, - types.String{Null: false, Unknown: false, Value: "1234"}, - o.Attrs["foo"].(types.String), + types.StringValue("1234"), + o.Attributes()["foo"].(types.String), ) } diff --git a/test/custom_types.go b/test/custom_types.go index 90d07ae..982422e 100644 --- a/test/custom_types.go +++ b/test/custom_types.go @@ -42,16 +42,16 @@ func CopyFromBoolSpecial(diags diag.Diagnostics, tf attr.Value, obj *[]BoolCusto return } - arr := make([]BoolCustom, len(v.Elems)) - for i, raw := range v.Elems { + arr := make([]BoolCustom, len(v.Elements())) + for i, raw := range v.Elements() { el, ok := raw.(types.Bool) if !ok { diags.AddError("Error reading value from Terraform", fmt.Sprintf("Failed to cast %T to types.Bool", raw)) return } - if !el.Null && !el.Unknown { - arr[i] = BoolCustom(el.Value) + if !el.IsNull() && !el.IsUnknown() { + arr[i] = BoolCustom(el.ValueBool()) } } @@ -59,27 +59,14 @@ func CopyFromBoolSpecial(diags diag.Diagnostics, tf attr.Value, obj *[]BoolCusto } // CopyToBoolSpecial copies source value to the target -func CopyToBoolSpecial(diags diag.Diagnostics, obj []BoolCustom, t attr.Type, v attr.Value) attr.Value { - value, ok := v.(types.List) - if !ok { - value = types.List{ - Null: true, - Unknown: false, - ElemType: types.BoolType, - } +func CopyToBoolSpecial(diags diag.Diagnostics, obj []BoolCustom) attr.Value { + elems := make([]attr.Value, len(obj)) + for i, b := range obj { + elems[i] = types.BoolValue(bool(b)) } - - if len(obj) > 0 { - if value.Elems == nil { - value.Elems = make([]attr.Value, len(obj)) - } - - for i, b := range obj { - value.Elems[i] = types.Bool{Null: false, Unknown: false, Value: bool(b)} - } - } - - return value + list, listDiags := types.ListValue(types.BoolType, elems) + diags.Append(listDiags...) + return list } // StringCustom is a custom type that maps a Terraform List of string, onto a @@ -104,15 +91,15 @@ func CopyFromStringCustom(diags diag.Diagnostics, tf attr.Value, obj *string) { } items := make([]string, 0) - for _, raw := range v.Elems { + for _, raw := range v.Elements() { el, ok := raw.(types.String) if !ok { diags.AddError("Error reading value from Terraform", fmt.Sprintf("Failed to cast %T to types.Bool", raw)) return } - if !el.Null && !el.Unknown { - items = append(items, el.Value) + if !el.IsNull() && !el.IsUnknown() { + items = append(items, el.ValueString()) } } @@ -121,25 +108,13 @@ func CopyFromStringCustom(diags diag.Diagnostics, tf attr.Value, obj *string) { // CopyToStringCustom copies a source value (single string) into the Terraform // value (a list of strings) by splitting the string on every "/". -func CopyToStringCustom(diags diag.Diagnostics, obj string, t attr.Type, v attr.Value) attr.Value { - value, ok := v.(types.List) - if !ok { - value = types.List{ - Null: true, - Unknown: false, - ElemType: types.StringType, - } +func CopyToStringCustom(diags diag.Diagnostics, obj string) attr.Value { + parts := strings.Split(obj, "/") + elems := make([]attr.Value, len(parts)) + for i, b := range parts { + elems[i] = types.StringValue(b) } - - if len(obj) > 0 { - if value.Elems == nil { - value.Elems = make([]attr.Value, len(obj)) - } - - for i, b := range strings.Split(obj, "/") { - value.Elems[i] = types.String{Null: false, Unknown: false, Value: b} - } - } - - return value + list, listDiags := types.ListValue(types.StringType, elems) + diags.Append(listDiags...) + return list } diff --git a/test/fixtures.go b/test/fixtures.go index 977f0c8..6ff364d 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -22,6 +22,7 @@ import ( time "time" "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stretchr/testify/require" ) @@ -104,351 +105,511 @@ func createTestObj() *Test { // copyFromTerraformObject returns a base object used in CopyFrom* tests func copyFromTerraformObject(t *testing.T) types.Object { + t.Helper() + s, d := GenSchemaTest(context.Background()) require.False(t, d.HasError()) - typ := s.AttributeType() + typ := s.Type() obj, ok := typ.(types.ObjectType) require.True(t, ok) - return types.Object{ - Null: false, - Unknown: false, - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test"}, - "int32": types.Int64{Value: 98}, - "int64": types.Int64{Value: 99}, - "float": types.Float64{Value: 0.75}, - "double": types.Float64{Value: 0.76}, - "bool": types.Bool{Value: true}, - "bytes": types.String{Value: "Test"}, - - "timestamp": TimeValue{Value: timestamp}, - "timestamp_missing": TimeValue{Unknown: true}, - "timestamp_nullable": TimeValue{Value: timestamp}, - "timestamp_nullable_with_nil_value": TimeValue{Null: true}, - "duration_standard": DurationValue{Value: duration}, - "duration_standard_missing": DurationValue{Unknown: true}, - "duration_custom": DurationValue{Value: duration}, - "duration_custom_missing": DurationValue{Unknown: true}, - - "string_list": types.List{ - Elems: []attr.Value{types.String{Value: "el1"}, types.String{Value: "el2"}}, - }, - "string_list_empty": types.List{Null: false}, - "bytes_list": types.List{ - Elems: []attr.Value{types.String{Value: "bytes1"}, types.String{Value: "bytes2"}}, - }, - - "timestamp_list": types.List{ - Elems: []attr.Value{TimeValue{Value: timestamp}, TimeValue{Value: timestamp}}, - }, - "duration_custom_list": types.List{ - Elems: []attr.Value{DurationValue{Value: duration}, DurationValue{Value: duration}}, - }, - - "bool_custom_list": types.List{ - Elems: []attr.Value{types.Bool{Value: true}, types.Bool{Value: false}, types.Bool{Value: true}}, - }, + must := func(v any, d diag.Diagnostics) attr.Value { + t.Helper() + requireNoDiagErrors(t, d) + return v.(attr.Value) + } - "nested": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test"}, - "map": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.String{Value: "Value1"}, - "key2": types.String{Value: "Value2"}, - }, - }, - "nested_list": types.List{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + attrs := map[string]attr.Value{ + "id": types.StringNull(), // TODO + "str": types.StringValue("Test"), + "int32": types.Int64Value(98), + "int64": types.Int64Value(99), + "float": types.Float64Value(0.75), + "double": types.Float64Value(0.76), + "bool": types.BoolValue(true), + "bytes": types.StringValue("Test"), + + "timestamp": ValueTime(timestamp), + "timestamp_missing": TimeValue{Unknown: true, Format: time.RFC3339}, + "timestamp_nullable": ValueTime(timestamp), + "timestamp_nullable_with_nil_value": NullTime(), + "duration_standard": ValueDuration(duration), + "duration_standard_missing": DurationValue{Unknown: true}, + "duration_custom": ValueDuration(duration), + "duration_custom_missing": DurationValue{Unknown: true}, + + "string_list": must(types.ListValue( + types.StringType, + []attr.Value{types.StringValue("el1"), types.StringValue("el2")}, + )), + "string_list_empty": must(types.ListValue(types.StringType, []attr.Value{})), + "bytes_list": must(types.ListValue( + types.StringType, + []attr.Value{types.StringValue("bytes1"), types.StringValue("bytes2")}, + )), + + "timestamp_list": must(types.ListValue( + UseRFC3339Time(), + []attr.Value{ValueTime(timestamp), ValueTime(timestamp)}, + )), + "duration_custom_list": must(types.ListValue( + DurationType{}, + []attr.Value{DurationValue{Value: duration}, DurationValue{Value: duration}}, + )), + + "bool_custom_list": must(types.ListValue( + types.BoolType, + []attr.Value{types.BoolValue(true), types.BoolValue(false), types.BoolValue(true)}, + )), + + "nested": must(types.ObjectValue( + obj.AttrTypes["nested"].(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test"), + "map": must(types.MapValue(types.StringType, map[string]attr.Value{ + "key1": types.StringValue("Value1"), + "key2": types.StringValue("Value2"), + })), + "nested_list": types.ListNull( + obj.AttrTypes["nested"].(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["nested"].(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["nested"].(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["nested"].(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - - "nested_nullable": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test"}, - "map": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.String{Value: "Value1"}, - "key2": types.String{Value: "Value2"}, - }, - }, - "nested_list": types.List{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + + "nested_nullable": must(types.ObjectValue( + obj.AttrTypes["nested_nullable"].(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test"), + "map": must(types.MapValue(types.StringType, map[string]attr.Value{ + "key1": types.StringValue("Value1"), + "key2": types.StringValue("Value2"), + })), + "nested_list": types.ListNull( + obj.AttrTypes["nested_nullable"].(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["nested_nullable"].(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["nested_nullable"].(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["nested_nullable"].(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - - "nested_nullable_with_nil_value": types.Object{Null: true}, - - "nested_list": types.List{ - Elems: []attr.Value{ - types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test"}, - "nested_list": types.List{ - Elems: []attr.Value{ - types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - }, + )), + + "nested_list": must(types.ListValue( + obj.AttrTypes["nested_list"].(types.ListType).ElemType, + []attr.Value{ + must(types.ObjectValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test"), + "nested_list": must(types.ListValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + []attr.Value{ + must(types.ObjectValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - }, + )), + must(types.ObjectValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, - }, - "map": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.String{Value: "Value1"}, - "key2": types.String{Value: "Value2"}, - }, + )), }, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "map": must(types.MapValue(types.StringType, map[string]attr.Value{ + "key1": types.StringValue("Value1"), + "key2": types.StringValue("Value2"), + })), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["nested_list"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - }, + )), }, - - "nested_list_nullable": types.List{ - Elems: []attr.Value{ - types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + + "nested_list_nullable": must(types.ListValue( + obj.AttrTypes["nested_list_nullable"].(types.ListType).ElemType, + []attr.Value{ + must(types.ObjectValue( + obj.AttrTypes["nested_list_nullable"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test"), + "nested_list": types.ListNull( + obj.AttrTypes["nested_list_nullable"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map": types.MapNull( + obj.AttrTypes["nested_list_nullable"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map"].(types.MapType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["nested_list_nullable"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["nested_list_nullable"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["nested_list_nullable"].(types.ListType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - }, + )), }, - - "map": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.String{Value: "Value1"}, - "key2": types.String{Value: "Value2"}, - }, - }, - - "map_object": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + + "map_object": must(types.MapValue( + obj.AttrTypes["map_object"].(types.MapType).ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), + "nested_list": types.ListNull( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map": types.MapNull( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map"].(types.MapType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), + "nested_list": types.ListNull( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map": types.MapNull( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map"].(types.MapType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["map_object"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - }, + )), }, - - "map_object_nullable": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + + "map_object_nullable": must(types.MapValue( + obj.AttrTypes["map_object_nullable"].(types.MapType).ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), + "nested_list": types.ListNull( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map": types.MapNull( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map"].(types.MapType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - "map_object_nested": types.Map{ - Elems: map[string]attr.Value{ - "key1": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test1"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), + "nested_list": types.ListNull( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["nested_list"].(types.ListType). + ElemType, + ), + "map": types.MapNull( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map"].(types.MapType). + ElemType, + ), + "map_object_nested": must(types.MapValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType, + map[string]attr.Value{ + "key1": must(types.ObjectValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test1"), }, - "key2": types.Object{ - Attrs: map[string]attr.Value{ - "str": types.String{Value: "Test2"}, - "nested_list": types.List{Null: true}, - "map": types.Map{Null: true}, - }, + )), + "key2": must(types.ObjectValue( + obj.AttrTypes["map_object_nullable"].(types.MapType). + ElemType.(types.ObjectType). + AttrTypes["map_object_nested"].(types.MapType). + ElemType.(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "str": types.StringValue("Test2"), }, - }, + )), }, - }, + )), }, - }, + )), }, - "mode": types.Int64{Value: 1}, - "branch1": types.Object{Null: true}, - "branch2": types.Object{Null: true}, - "branch3": types.String{Null: true}, - "empty_message_branch": types.Object{Null: true}, - "string_branch": types.String{Null: true}, - "embedded_string": types.String{Value: "embdtest1"}, - "embedded_nested_field": types.Object{ - Attrs: map[string]attr.Value{ - "embedded_nested_string": types.String{Value: "embdtest2"}, - }, + )), + + "nested_nullable_with_nil_value": types.ObjectNull( + obj.AttrTypes["nested_nullable_with_nil_value"].(types.ObjectType).AttrTypes, + ), + + "map": must(types.MapValue(types.StringType, map[string]attr.Value{ + "key1": types.StringValue("Value1"), + "key2": types.StringValue("Value2"), + })), + + "mode": types.Int64Value(1), + "branch1": types.ObjectNull(obj.AttrTypes["branch1"].(types.ObjectType).AttrTypes), + "branch2": types.ObjectNull(obj.AttrTypes["branch2"].(types.ObjectType).AttrTypes), + "branch3": types.StringNull(), + "empty_message_branch": types.ObjectNull(obj.AttrTypes["empty_message_branch"].(types.ObjectType).AttrTypes), + "string_branch": types.StringNull(), + "embedded_string": types.StringValue("embdtest1"), + "embedded_nested_field": must(types.ObjectValue( + obj.AttrTypes["embedded_nested_field"].(types.ObjectType).AttrTypes, + map[string]attr.Value{ + "embedded_nested_string": types.StringValue("embdtest2"), }, - "max_age": DurationValue{Value: duration}, - "string_override": types.List{Elems: []attr.Value{ - types.String{Value: "a"}, - types.String{Value: "b"}, - types.String{Value: "c"}, - }}, - "foo": types.String{Null: true}, - "bar": types.String{Value: "ham"}, - }, - AttrTypes: obj.AttrTypes, + )), + "max_age": DurationValue{Value: duration}, + "string_override": must(types.ListValue(types.StringType, []attr.Value{ + types.StringValue("a"), + types.StringValue("b"), + types.StringValue("c"), + })), + "foo": types.StringNull(), + "bar": types.StringValue("ham"), } + result, diags := types.ObjectValue(obj.AttrTypes, attrs) + requireNoDiagErrors(t, diags) + return result } -// copyToTerraformObject returns the base object used in CopyTo* tests -func copyToTerraformObject(t *testing.T) types.Object { - s, d := GenSchemaTest(context.Background()) - - require.False(t, d.HasError()) - typ := s.AttributeType() - - obj, ok := typ.(types.ObjectType) - require.True(t, ok) - - return types.Object{ - Unknown: false, - Null: false, - Attrs: make(map[string]attr.Value), - AttrTypes: obj.AttrTypes, - } +func emptyObject() *types.Object { + o, _ := types.ObjectValue( + map[string]attr.Type{"id": types.StringType}, + map[string]attr.Value{"id": types.StringNull()}, + ) + return &o } diff --git a/test/test_terraform.go b/test/test_terraform.go index b5f04e2..33c0f90 100644 --- a/test/test_terraform.go +++ b/test/test_terraform.go @@ -28,9 +28,9 @@ import ( proto "github.com/gogo/protobuf/proto" github_com_hashicorp_terraform_plugin_framework_attr "github.com/hashicorp/terraform-plugin-framework/attr" github_com_hashicorp_terraform_plugin_framework_diag "github.com/hashicorp/terraform-plugin-framework/diag" + github_com_hashicorp_terraform_plugin_framework_resource "github.com/hashicorp/terraform-plugin-framework/resource" github_com_hashicorp_terraform_plugin_framework_tfsdk "github.com/hashicorp/terraform-plugin-framework/tfsdk" github_com_hashicorp_terraform_plugin_framework_types "github.com/hashicorp/terraform-plugin-framework/types" - github_com_hashicorp_terraform_plugin_go_tftypes "github.com/hashicorp/terraform-plugin-go/tftypes" _ "google.golang.org/protobuf/types/known/timestamppb" ) @@ -426,7 +426,7 @@ func GenSchemaTest(ctx context.Context) (github_com_hashicorp_terraform_plugin_f "str": { Computed: true, Description: "Str string field", - PlanModifiers: []github_com_hashicorp_terraform_plugin_framework_tfsdk.AttributePlanModifier{github_com_hashicorp_terraform_plugin_framework_tfsdk.UseStateForUnknown()}, + PlanModifiers: []github_com_hashicorp_terraform_plugin_framework_tfsdk.AttributePlanModifier{github_com_hashicorp_terraform_plugin_framework_resource.UseStateForUnknown()}, Required: true, Sensitive: true, Type: github_com_hashicorp_terraform_plugin_framework_types.StringType, @@ -486,7 +486,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ obj.OneOfWithEmptyMessage = nil obj.LowerSnakeOneof = nil { - a, ok := tf.Attrs["bar"] + a, ok := tf.Attributes()["bar"] if !ok { diags.Append(attrReadMissingDiag{"Test.bar"}) } else { @@ -495,17 +495,17 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.bar", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { obj.LowerSnakeOneof = &Test_Bar{Bar: t} } } } } { - a, ok := tf.Attrs["bool"] + a, ok := tf.Attributes()["bool"] if !ok { diags.Append(attrReadMissingDiag{"Test.Bool"}) } else { @@ -514,22 +514,22 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Bool", "github.com/hashicorp/terraform-plugin-framework/types.Bool"}) } else { var t bool - if !v.Null && !v.Unknown { - t = bool(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueBool() } obj.Bool = t } } } { - a, ok := tf.Attrs["bool_custom_list"] + a, ok := tf.Attributes()["bool_custom_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.BoolCustomList"}) } CopyFromBoolSpecial(diags, a, &obj.BoolCustomList) } { - a, ok := tf.Attrs["branch1"] + a, ok := tf.Attributes()["branch1"] if !ok { diags.Append(attrReadMissingDiag{"Test.Branch1"}) } else { @@ -537,13 +537,13 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Branch1", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { b := &Branch1{} obj.OneOf = &Test_Branch1{Branch1: b} obj := b tf := v { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.Branch1.Str"}) } else { @@ -552,8 +552,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Branch1.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -564,7 +564,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["branch2"] + a, ok := tf.Attributes()["branch2"] if !ok { diags.Append(attrReadMissingDiag{"Test.Branch2"}) } else { @@ -572,13 +572,13 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Branch2", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { b := &Branch2{} obj.OneOf = &Test_Branch2{Branch2: b} obj := b tf := v { - a, ok := tf.Attrs["int32"] + a, ok := tf.Attributes()["int32"] if !ok { diags.Append(attrReadMissingDiag{"Test.Branch2.Int32"}) } else { @@ -587,8 +587,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Branch2.Int32", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) } else { var t int32 - if !v.Null && !v.Unknown { - t = int32(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = int32(v.ValueInt64()) } obj.Int32 = t } @@ -599,7 +599,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["branch3"] + a, ok := tf.Attributes()["branch3"] if !ok { diags.Append(attrReadMissingDiag{"Test.Branch3"}) } else { @@ -608,17 +608,17 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Branch3", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { obj.OneOf = &Test_Branch3{Branch3: t} } } } } { - a, ok := tf.Attrs["bytes"] + a, ok := tf.Attributes()["bytes"] if !ok { diags.Append(attrReadMissingDiag{"Test.bytes"}) } else { @@ -627,15 +627,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.bytes", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t []byte - if !v.Null && !v.Unknown { - t = []byte(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = []byte(v.ValueString()) } obj.Bytes = t } } } { - a, ok := tf.Attrs["bytes_list"] + a, ok := tf.Attributes()["bytes_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.BytesList"}) } else { @@ -643,16 +643,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.BytesList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.BytesList = make([][]byte, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.BytesList = make([][]byte, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.BytesList", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t []byte - if !v.Null && !v.Unknown { - t = []byte(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = []byte(v.ValueString()) } obj.BytesList[k] = t } @@ -662,7 +662,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["double"] + a, ok := tf.Attributes()["double"] if !ok { diags.Append(attrReadMissingDiag{"Test.Double"}) } else { @@ -671,15 +671,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Double", "github.com/hashicorp/terraform-plugin-framework/types.Float64"}) } else { var t float64 - if !v.Null && !v.Unknown { - t = float64(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueFloat64() } obj.Double = t } } } { - a, ok := tf.Attrs["duration_custom"] + a, ok := tf.Attributes()["duration_custom"] if !ok { diags.Append(attrReadMissingDiag{"Test.DurationCustom"}) } else { @@ -688,15 +688,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.DurationCustom", "DurationValue"}) } else { var t Duration - if !v.Null && !v.Unknown { - t = Duration(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = Duration(v.ValueDuration()) } obj.DurationCustom = t } } } { - a, ok := tf.Attrs["duration_custom_list"] + a, ok := tf.Attributes()["duration_custom_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.DurationCustomList"}) } else { @@ -704,16 +704,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.DurationCustomList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.DurationCustomList = make([]Duration, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.DurationCustomList = make([]Duration, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(DurationValue) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.DurationCustomList", "DurationValue"}) } else { var t Duration - if !v.Null && !v.Unknown { - t = Duration(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = Duration(v.ValueDuration()) } obj.DurationCustomList[k] = t } @@ -723,7 +723,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["duration_custom_missing"] + a, ok := tf.Attributes()["duration_custom_missing"] if !ok { diags.Append(attrReadMissingDiag{"Test.DurationCustomMissing"}) } else { @@ -732,15 +732,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.DurationCustomMissing", "DurationValue"}) } else { var t Duration - if !v.Null && !v.Unknown { - t = Duration(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = Duration(v.ValueDuration()) } obj.DurationCustomMissing = t } } } { - a, ok := tf.Attrs["duration_standard"] + a, ok := tf.Attributes()["duration_standard"] if !ok { diags.Append(attrReadMissingDiag{"Test.DurationStandard"}) } else { @@ -749,15 +749,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.DurationStandard", "DurationValue"}) } else { var t time.Duration - if !v.Null && !v.Unknown { - t = time.Duration(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = time.Duration(v.ValueDuration()) } obj.DurationStandard = t } } } { - a, ok := tf.Attrs["duration_standard_missing"] + a, ok := tf.Attributes()["duration_standard_missing"] if !ok { diags.Append(attrReadMissingDiag{"Test.DurationStandardMissing"}) } else { @@ -766,15 +766,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.DurationStandardMissing", "DurationValue"}) } else { var t time.Duration - if !v.Null && !v.Unknown { - t = time.Duration(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = time.Duration(v.ValueDuration()) } obj.DurationStandardMissing = t } } } { - a, ok := tf.Attrs["embedded_nested_field"] + a, ok := tf.Attributes()["embedded_nested_field"] if !ok { diags.Append(attrReadMissingDiag{"Test.EmbeddedNestedField"}) } else { @@ -783,12 +783,12 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.EmbeddedNestedField", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { obj.EmbeddedNestedField = nil - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj.EmbeddedNestedField = &EmbeddedNestedField{} obj := obj.EmbeddedNestedField { - a, ok := tf.Attrs["embedded_nested_string"] + a, ok := tf.Attributes()["embedded_nested_string"] if !ok { diags.Append(attrReadMissingDiag{"Test.EmbeddedNestedField.EmbeddedNestedString"}) } else { @@ -797,8 +797,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.EmbeddedNestedField.EmbeddedNestedString", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.EmbeddedNestedString = t } @@ -809,7 +809,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["embedded_string"] + a, ok := tf.Attributes()["embedded_string"] if !ok { diags.Append(attrReadMissingDiag{"Test.EmbeddedString"}) } else { @@ -818,15 +818,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.EmbeddedString", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.EmbeddedString = t } } } { - a, ok := tf.Attrs["empty_message_branch"] + a, ok := tf.Attributes()["empty_message_branch"] if !ok { diags.Append(attrReadMissingDiag{"Test.EmptyMessageBranch"}) } else { @@ -834,7 +834,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.EmptyMessageBranch", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { b := &EmptyMessageBranch{} obj.OneOfWithEmptyMessage = &Test_EmptyMessageBranch{EmptyMessageBranch: b} } @@ -842,7 +842,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["float"] + a, ok := tf.Attributes()["float"] if !ok { diags.Append(attrReadMissingDiag{"Test.Float"}) } else { @@ -851,15 +851,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Float", "github.com/hashicorp/terraform-plugin-framework/types.Float64"}) } else { var t float32 - if !v.Null && !v.Unknown { - t = float32(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = float32(v.ValueFloat64()) } obj.Float = t } } } { - a, ok := tf.Attrs["foo"] + a, ok := tf.Attributes()["foo"] if !ok { diags.Append(attrReadMissingDiag{"Test.foo"}) } else { @@ -868,17 +868,17 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.foo", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { obj.LowerSnakeOneof = &Test_Foo{Foo: t} } } } } { - a, ok := tf.Attrs["int32"] + a, ok := tf.Attributes()["int32"] if !ok { diags.Append(attrReadMissingDiag{"Test.Int32"}) } else { @@ -887,15 +887,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Int32", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) } else { var t int32 - if !v.Null && !v.Unknown { - t = int32(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = int32(v.ValueInt64()) } obj.Int32 = t } } } { - a, ok := tf.Attrs["int64"] + a, ok := tf.Attributes()["int64"] if !ok { diags.Append(attrReadMissingDiag{"Test.Int64"}) } else { @@ -904,15 +904,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Int64", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) } else { var t int64 - if !v.Null && !v.Unknown { - t = int64(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueInt64() } obj.Int64 = t } } } { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.Map"}) } else { @@ -920,16 +920,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -939,7 +939,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object"] + a, ok := tf.Attributes()["map_object"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject"}) } else { @@ -947,19 +947,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObject = make(map[string]Nested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObject = make(map[string]Nested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t Nested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject.Map"}) } else { @@ -967,16 +967,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -986,7 +986,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject.MapObjectNested"}) } else { @@ -994,19 +994,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject.MapObjectNested.Str"}) } else { @@ -1015,8 +1015,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.MapObject.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1031,7 +1031,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject.NestedList"}) } else { @@ -1039,20 +1039,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObject.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject.NestedList.Str"}) } else { @@ -1061,8 +1061,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.MapObject.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1077,7 +1077,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObject.Str"}) } else { @@ -1086,8 +1086,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.MapObject.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1102,7 +1102,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nullable"] + a, ok := tf.Attributes()["map_object_nullable"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable"}) } else { @@ -1110,20 +1110,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNullable = make(map[string]*Nested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNullable = make(map[string]*Nested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *Nested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &Nested{} obj := t { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable.Map"}) } else { @@ -1131,16 +1131,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -1150,7 +1150,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable.MapObjectNested"}) } else { @@ -1158,19 +1158,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable.MapObjectNested.Str"}) } else { @@ -1179,8 +1179,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1195,7 +1195,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable.NestedList"}) } else { @@ -1203,20 +1203,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable.NestedList.Str"}) } else { @@ -1225,8 +1225,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1241,7 +1241,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.MapObjectNullable.Str"}) } else { @@ -1250,8 +1250,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.MapObjectNullable.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1266,7 +1266,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["mode"] + a, ok := tf.Attributes()["mode"] if !ok { diags.Append(attrReadMissingDiag{"Test.Mode"}) } else { @@ -1275,15 +1275,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Mode", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) } else { var t Mode - if !v.Null && !v.Unknown { - t = Mode(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = Mode(v.ValueInt64()) } obj.Mode = t } } } { - a, ok := tf.Attrs["nested"] + a, ok := tf.Attributes()["nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested"}) } else { @@ -1292,11 +1292,11 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Nested", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { obj.Nested = Nested{} - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &obj.Nested { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested.Map"}) } else { @@ -1304,16 +1304,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Nested.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Nested.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -1323,7 +1323,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested.MapObjectNested"}) } else { @@ -1331,19 +1331,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Nested.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Nested.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested.MapObjectNested.Str"}) } else { @@ -1352,8 +1352,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Nested.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1368,7 +1368,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested.NestedList"}) } else { @@ -1376,20 +1376,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Nested.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.Nested.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested.NestedList.Str"}) } else { @@ -1398,8 +1398,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Nested.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1414,7 +1414,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.Nested.Str"}) } else { @@ -1423,8 +1423,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Nested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1435,7 +1435,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList"}) } else { @@ -1443,19 +1443,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]Nested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]Nested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t Nested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList.Map"}) } else { @@ -1463,16 +1463,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -1482,7 +1482,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList.MapObjectNested"}) } else { @@ -1490,19 +1490,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList.MapObjectNested.Str"}) } else { @@ -1511,8 +1511,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedList.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1527,7 +1527,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList.NestedList"}) } else { @@ -1535,20 +1535,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedList.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList.NestedList.Str"}) } else { @@ -1557,8 +1557,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedList.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1573,7 +1573,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedList.Str"}) } else { @@ -1582,8 +1582,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1598,7 +1598,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list_nullable"] + a, ok := tf.Attributes()["nested_list_nullable"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable"}) } else { @@ -1606,20 +1606,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedListNullable = make([]*Nested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedListNullable = make([]*Nested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *Nested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &Nested{} obj := t { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable.Map"}) } else { @@ -1627,16 +1627,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -1646,7 +1646,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable.MapObjectNested"}) } else { @@ -1654,19 +1654,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable.MapObjectNested.Str"}) } else { @@ -1675,8 +1675,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1691,7 +1691,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable.NestedList"}) } else { @@ -1699,20 +1699,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable.NestedList.Str"}) } else { @@ -1721,8 +1721,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1737,7 +1737,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedListNullable.Str"}) } else { @@ -1746,8 +1746,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedListNullable.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1762,7 +1762,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_nullable"] + a, ok := tf.Attributes()["nested_nullable"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable"}) } else { @@ -1771,12 +1771,12 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { obj.NestedNullable = nil - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj.NestedNullable = &Nested{} obj := obj.NestedNullable { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable.Map"}) } else { @@ -1784,16 +1784,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -1803,7 +1803,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable.MapObjectNested"}) } else { @@ -1811,19 +1811,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable.MapObjectNested.Str"}) } else { @@ -1832,8 +1832,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1848,7 +1848,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable.NestedList"}) } else { @@ -1856,20 +1856,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable.NestedList.Str"}) } else { @@ -1878,8 +1878,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1894,7 +1894,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullable.Str"}) } else { @@ -1903,8 +1903,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullable.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -1915,7 +1915,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_nullable_with_nil_value"] + a, ok := tf.Attributes()["nested_nullable_with_nil_value"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue"}) } else { @@ -1924,12 +1924,12 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue", "github.com/hashicorp/terraform-plugin-framework/types.Object"}) } else { obj.NestedNullableWithNilValue = nil - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj.NestedNullableWithNilValue = &Nested{} obj := obj.NestedNullableWithNilValue { - a, ok := tf.Attrs["map"] + a, ok := tf.Attributes()["map"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue.Map"}) } else { @@ -1937,16 +1937,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.Map", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.Map = make(map[string]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.Map = make(map[string]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.Map", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Map[k] = t } @@ -1956,7 +1956,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["map_object_nested"] + a, ok := tf.Attributes()["map_object_nested"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue.MapObjectNested"}) } else { @@ -1964,19 +1964,19 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.Map"}) } else { - obj.MapObjectNested = make(map[string]OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.MapObjectNested = make(map[string]OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.MapObjectNested", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v obj := &t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue.MapObjectNested.Str"}) } else { @@ -1985,8 +1985,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -2001,7 +2001,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["nested_list"] + a, ok := tf.Attributes()["nested_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue.NestedList"}) } else { @@ -2009,20 +2009,20 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.NestedList = make([]*OtherNested, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.NestedList = make([]*OtherNested, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Object) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.NestedList", "github_com_hashicorp_terraform_plugin_framework_types.Object"}) } else { var t *OtherNested - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { tf := v t = &OtherNested{} obj := t { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue.NestedList.Str"}) } else { @@ -2031,8 +2031,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -2047,7 +2047,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.NestedNullableWithNilValue.Str"}) } else { @@ -2056,8 +2056,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.NestedNullableWithNilValue.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } @@ -2068,7 +2068,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["str"] + a, ok := tf.Attributes()["str"] if !ok { diags.Append(attrReadMissingDiag{"Test.Str"}) } else { @@ -2077,15 +2077,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.Str = t } } } { - a, ok := tf.Attrs["string_branch"] + a, ok := tf.Attributes()["string_branch"] if !ok { diags.Append(attrReadMissingDiag{"Test.StringBranch"}) } else { @@ -2094,17 +2094,17 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.StringBranch", "github.com/hashicorp/terraform-plugin-framework/types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { obj.OneOfWithEmptyMessage = &Test_StringBranch{StringBranch: t} } } } } { - a, ok := tf.Attrs["string_list"] + a, ok := tf.Attributes()["string_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.StringList"}) } else { @@ -2112,16 +2112,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.StringList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.StringList = make([]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.StringList = make([]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.StringList", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.StringList[k] = t } @@ -2131,7 +2131,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["string_list_empty"] + a, ok := tf.Attributes()["string_list_empty"] if !ok { diags.Append(attrReadMissingDiag{"Test.StringListEmpty"}) } else { @@ -2139,16 +2139,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.StringListEmpty", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.StringListEmpty = make([]string, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.StringListEmpty = make([]string, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.StringListEmpty", "github_com_hashicorp_terraform_plugin_framework_types.String"}) } else { var t string - if !v.Null && !v.Unknown { - t = string(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = v.ValueString() } obj.StringListEmpty[k] = t } @@ -2158,14 +2158,14 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["string_override"] + a, ok := tf.Attributes()["string_override"] if !ok { diags.Append(attrReadMissingDiag{"Test.StringOverride"}) } CopyFromStringCustom(diags, a, &obj.StringOverride) } { - a, ok := tf.Attrs["timestamp"] + a, ok := tf.Attributes()["timestamp"] if !ok { diags.Append(attrReadMissingDiag{"Test.Timestamp"}) } else { @@ -2174,15 +2174,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Timestamp", "TimeValue"}) } else { var t time.Time - if !v.Null && !v.Unknown { - t = time.Time(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = time.Time(v.ValueTime()) } obj.Timestamp = t } } } { - a, ok := tf.Attrs["timestamp_list"] + a, ok := tf.Attributes()["timestamp_list"] if !ok { diags.Append(attrReadMissingDiag{"Test.TimestampList"}) } else { @@ -2190,16 +2190,16 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ if !ok { diags.Append(attrReadConversionFailureDiag{"Test.TimestampList", "github.com/hashicorp/terraform-plugin-framework/types.List"}) } else { - obj.TimestampList = make([]*time.Time, len(v.Elems)) - if !v.Null && !v.Unknown { - for k, a := range v.Elems { + obj.TimestampList = make([]*time.Time, len(v.Elements())) + if !v.IsNull() && !v.IsUnknown() { + for k, a := range v.Elements() { v, ok := a.(TimeValue) if !ok { diags.Append(attrReadConversionFailureDiag{"Test.TimestampList", "TimeValue"}) } else { var t *time.Time - if !v.Null && !v.Unknown { - c := time.Time(v.Value) + if !v.IsNull() && !v.IsUnknown() { + c := time.Time(v.ValueTime()) t = &c } obj.TimestampList[k] = t @@ -2210,7 +2210,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["timestamp_missing"] + a, ok := tf.Attributes()["timestamp_missing"] if !ok { diags.Append(attrReadMissingDiag{"Test.TimestampMissing"}) } else { @@ -2219,15 +2219,15 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.TimestampMissing", "TimeValue"}) } else { var t time.Time - if !v.Null && !v.Unknown { - t = time.Time(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = time.Time(v.ValueTime()) } obj.TimestampMissing = t } } } { - a, ok := tf.Attrs["timestamp_nullable"] + a, ok := tf.Attributes()["timestamp_nullable"] if !ok { diags.Append(attrReadMissingDiag{"Test.TimestampNullable"}) } else { @@ -2236,8 +2236,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.TimestampNullable", "TimeValue"}) } else { var t *time.Time - if !v.Null && !v.Unknown { - c := time.Time(v.Value) + if !v.IsNull() && !v.IsUnknown() { + c := time.Time(v.ValueTime()) t = &c } obj.TimestampNullable = t @@ -2245,7 +2245,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["timestamp_nullable_with_nil_value"] + a, ok := tf.Attributes()["timestamp_nullable_with_nil_value"] if !ok { diags.Append(attrReadMissingDiag{"Test.TimestampNullableWithNilValue"}) } else { @@ -2254,8 +2254,8 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.TimestampNullableWithNilValue", "TimeValue"}) } else { var t *time.Time - if !v.Null && !v.Unknown { - c := time.Time(v.Value) + if !v.IsNull() && !v.IsUnknown() { + c := time.Time(v.ValueTime()) t = &c } obj.TimestampNullableWithNilValue = t @@ -2263,7 +2263,7 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } { - a, ok := tf.Attrs["max_age"] + a, ok := tf.Attributes()["max_age"] if !ok { diags.Append(attrReadMissingDiag{"Test.Value"}) } else { @@ -2272,10 +2272,10 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ diags.Append(attrReadConversionFailureDiag{"Test.Value", "DurationValue"}) } else { var t Duration - if !v.Null && !v.Unknown { - t = Duration(v.Value) + if !v.IsNull() && !v.IsUnknown() { + t = Duration(v.ValueDuration()) } - if !v.Null && !v.Unknown { + if !v.IsNull() && !v.IsUnknown() { if obj.MaxAgeDuration == nil { obj.MaxAgeDuration = &MaxAgeDuration{} } @@ -2287,2998 +2287,1368 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ return diags } -// CopyTestToTerraform copies contents of the source Terraform object into a target struct -func CopyTestToTerraform(ctx context.Context, obj *Test, tf *github_com_hashicorp_terraform_plugin_framework_types.Object) github_com_hashicorp_terraform_plugin_framework_diag.Diagnostics { - var diags github_com_hashicorp_terraform_plugin_framework_diag.Diagnostics - tf.Null = false - tf.Unknown = false - if tf.Attrs == nil { - tf.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) +// CopyTestToTerraform copies contents of source struct into a Terraform object. +func CopyTestToTerraform(ctx context.Context, obj *Test, curr *github_com_hashicorp_terraform_plugin_framework_types.Object) (github_com_hashicorp_terraform_plugin_framework_types.Object, github_com_hashicorp_terraform_plugin_framework_diag.Diagnostics) { + schema, diags := GenSchemaTest(ctx) + if diags.HasError() { + return github_com_hashicorp_terraform_plugin_framework_types.Object{}, diags + } + schemaObj := schema.Type().(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + if obj == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes), diags + } + var attrs map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value + if curr == nil || curr.Attributes() == nil { + attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + } else { + attrs = curr.Attributes() } { - t, ok := tf.AttrTypes["bar"] + obj, ok := obj.LowerSnakeOneof.(*Test_Bar) if !ok { - diags.Append(attrWriteMissingDiag{"Test.bar"}) + obj = &Test_Bar{} + } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Bar) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - obj, ok := obj.LowerSnakeOneof.(*Test_Bar) - if !ok { - obj = &Test_Bar{} - } - v, ok := tf.Attrs["bar"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.bar", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.bar", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Bar) == "" - } - v.Value = string(obj.Bar) - v.Unknown = false - tf.Attrs["bar"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["bar"] = v } { - t, ok := tf.AttrTypes["bool"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Bool"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := bool(obj.Bool) + if val == false { + v = github_com_hashicorp_terraform_plugin_framework_types.BoolNull() } else { - v, ok := tf.Attrs["bool"].(github_com_hashicorp_terraform_plugin_framework_types.Bool) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Bool", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Bool) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Bool", "github.com/hashicorp/terraform-plugin-framework/types.Bool"}) - } - v.Null = bool(obj.Bool) == false - } - v.Value = bool(obj.Bool) - v.Unknown = false - tf.Attrs["bool"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.BoolValue(val) } + attrs["bool"] = v } { - t, ok := tf.AttrTypes["bool_custom_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.BoolCustomList"}) - } else { - v := CopyToBoolSpecial(diags, obj.BoolCustomList, t, tf.Attrs["bool_custom_list"]) - tf.Attrs["bool_custom_list"] = v - } + v := CopyToBoolSpecial(diags, obj.BoolCustomList) + attrs["bool_custom_list"] = v } { - a, ok := tf.AttrTypes["branch1"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Branch1"}) - } else { + schemaObj := schemaObj.AttrTypes["branch1"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { obj, ok := obj.OneOf.(*Test_Branch1) if !ok { obj = &Test_Branch1{} } - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Branch1", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["branch1"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if obj.Branch1 == nil { - v.Null = true - } else { - obj := obj.Branch1 - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Branch1.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Branch1.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Branch1.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } + if obj.Branch1 == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := obj.Branch1 + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } - v.Unknown = false - tf.Attrs["branch1"] = v } - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["branch1"] = v } { - a, ok := tf.AttrTypes["branch2"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Branch2"}) - } else { + schemaObj := schemaObj.AttrTypes["branch2"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { obj, ok := obj.OneOf.(*Test_Branch2) if !ok { obj = &Test_Branch2{} } - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Branch2", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["branch2"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if obj.Branch2 == nil { - v.Null = true - } else { - obj := obj.Branch2 - tf := &v - { - t, ok := tf.AttrTypes["int32"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Branch2.Int32"}) - } else { - v, ok := tf.Attrs["int32"].(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Branch2.Int32", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Branch2.Int32", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) - } - v.Null = int64(obj.Int32) == 0 - } - v.Value = int64(obj.Int32) - v.Unknown = false - tf.Attrs["int32"] = v - } + if obj.Branch2 == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := obj.Branch2 + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := int64(obj.Int32) + if val == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Null() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Value(val) } + attrs["int32"] = v } - v.Unknown = false - tf.Attrs["branch2"] = v } - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["branch2"] = v } { - t, ok := tf.AttrTypes["branch3"] + obj, ok := obj.OneOf.(*Test_Branch3) if !ok { - diags.Append(attrWriteMissingDiag{"Test.Branch3"}) + obj = &Test_Branch3{} + } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Branch3) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - obj, ok := obj.OneOf.(*Test_Branch3) - if !ok { - obj = &Test_Branch3{} - } - v, ok := tf.Attrs["branch3"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Branch3", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Branch3", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Branch3) == "" - } - v.Value = string(obj.Branch3) - v.Unknown = false - tf.Attrs["branch3"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["branch3"] = v } { - t, ok := tf.AttrTypes["bytes"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.bytes"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Bytes) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v, ok := tf.Attrs["bytes"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.bytes", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.bytes", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Bytes) == "" - } - v.Value = string(obj.Bytes) - v.Unknown = false - tf.Attrs["bytes"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["bytes"] = v } { - a, ok := tf.AttrTypes["bytes_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.BytesList"}) + elemType := schemaObj.AttrTypes["bytes_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.BytesList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.BytesList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["bytes_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.BytesList)), - Null: true, - } + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.BytesList)) + for k, a := range obj.BytesList { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.BytesList)) - } - } - if obj.BytesList != nil { - t := o.ElemType - if len(obj.BytesList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.BytesList)) - } - for k, a := range obj.BytesList { - v, ok := tf.Attrs["bytes_list"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.BytesList", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.BytesList", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(a) == "" - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.BytesList) > 0 { - c.Null = false - } + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - c.Unknown = false - tf.Attrs["bytes_list"] = c + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["bytes_list"] = v } { - t, ok := tf.AttrTypes["double"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Double"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := float64(obj.Double) + if val == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.Float64Null() } else { - v, ok := tf.Attrs["double"].(github_com_hashicorp_terraform_plugin_framework_types.Float64) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Double", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Float64) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Double", "github.com/hashicorp/terraform-plugin-framework/types.Float64"}) - } - v.Null = float64(obj.Double) == 0 - } - v.Value = float64(obj.Double) - v.Unknown = false - tf.Attrs["double"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.Float64Value(val) } + attrs["double"] = v } { - t, ok := tf.AttrTypes["duration_custom"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.DurationCustom"}) - } else { - v, ok := tf.Attrs["duration_custom"].(DurationValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.DurationCustom", err}) - } - v, ok = i.(DurationValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.DurationCustom", "DurationValue"}) - } - v.Null = false - } - v.Value = time.Duration(obj.DurationCustom) - v.Unknown = false - tf.Attrs["duration_custom"] = v - } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Duration(obj.DurationCustom) + v = ValueDuration(val) + attrs["duration_custom"] = v } { - a, ok := tf.AttrTypes["duration_custom_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.DurationCustomList"}) + elemType := schemaObj.AttrTypes["duration_custom_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.DurationCustomList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.DurationCustomList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["duration_custom_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.DurationCustomList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.DurationCustomList)) - } - } - if obj.DurationCustomList != nil { - t := o.ElemType - if len(obj.DurationCustomList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.DurationCustomList)) - } - for k, a := range obj.DurationCustomList { - v, ok := tf.Attrs["duration_custom_list"].(DurationValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.DurationCustomList", err}) - } - v, ok = i.(DurationValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.DurationCustomList", "DurationValue"}) - } - v.Null = false - } - v.Value = time.Duration(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.DurationCustomList) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["duration_custom_list"] = c + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.DurationCustomList)) + for k, a := range obj.DurationCustomList { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Duration(a) + v = ValueDuration(val) + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["duration_custom_list"] = v } { - t, ok := tf.AttrTypes["duration_custom_missing"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.DurationCustomMissing"}) - } else { - v, ok := tf.Attrs["duration_custom_missing"].(DurationValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.DurationCustomMissing", err}) - } - v, ok = i.(DurationValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.DurationCustomMissing", "DurationValue"}) - } - v.Null = false - } - v.Value = time.Duration(obj.DurationCustomMissing) - v.Unknown = false - tf.Attrs["duration_custom_missing"] = v - } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Duration(obj.DurationCustomMissing) + v = ValueDuration(val) + attrs["duration_custom_missing"] = v } { - t, ok := tf.AttrTypes["duration_standard"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.DurationStandard"}) - } else { - v, ok := tf.Attrs["duration_standard"].(DurationValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.DurationStandard", err}) - } - v, ok = i.(DurationValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.DurationStandard", "DurationValue"}) - } - v.Null = false - } - v.Value = time.Duration(obj.DurationStandard) - v.Unknown = false - tf.Attrs["duration_standard"] = v - } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Duration(obj.DurationStandard) + v = ValueDuration(val) + attrs["duration_standard"] = v } { - t, ok := tf.AttrTypes["duration_standard_missing"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.DurationStandardMissing"}) - } else { - v, ok := tf.Attrs["duration_standard_missing"].(DurationValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.DurationStandardMissing", err}) - } - v, ok = i.(DurationValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.DurationStandardMissing", "DurationValue"}) - } - v.Null = false - } - v.Value = time.Duration(obj.DurationStandardMissing) - v.Unknown = false - tf.Attrs["duration_standard_missing"] = v - } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Duration(obj.DurationStandardMissing) + v = ValueDuration(val) + attrs["duration_standard_missing"] = v } { - a, ok := tf.AttrTypes["embedded_nested_field"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.EmbeddedNestedField"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.EmbeddedNestedField", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["embedded_nested_field"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if obj.EmbeddedNestedField == nil { - v.Null = true - } else { - obj := obj.EmbeddedNestedField - tf := &v - { - t, ok := tf.AttrTypes["embedded_nested_string"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.EmbeddedNestedField.EmbeddedNestedString"}) - } else { - v, ok := tf.Attrs["embedded_nested_string"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.EmbeddedNestedField.EmbeddedNestedString", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.EmbeddedNestedField.EmbeddedNestedString", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.EmbeddedNestedString) == "" - } - v.Value = string(obj.EmbeddedNestedString) - v.Unknown = false - tf.Attrs["embedded_nested_string"] = v - } + schemaObj := schemaObj.AttrTypes["embedded_nested_field"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if obj.EmbeddedNestedField == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := obj.EmbeddedNestedField + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.EmbeddedNestedString) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["embedded_nested_string"] = v } - v.Unknown = false - tf.Attrs["embedded_nested_field"] = v } - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["embedded_nested_field"] = v } { - t, ok := tf.AttrTypes["embedded_string"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.EmbeddedString"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.EmbeddedString) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v, ok := tf.Attrs["embedded_string"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.EmbeddedString", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.EmbeddedString", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.EmbeddedString) == "" - } - v.Value = string(obj.EmbeddedString) - v.Unknown = false - tf.Attrs["embedded_string"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["embedded_string"] = v } { - a, ok := tf.AttrTypes["empty_message_branch"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.EmptyMessageBranch"}) - } else { + schemaObj := schemaObj.AttrTypes["empty_message_branch"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { obj, ok := obj.OneOfWithEmptyMessage.(*Test_EmptyMessageBranch) if !ok { obj = &Test_EmptyMessageBranch{} } - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.EmptyMessageBranch", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["empty_message_branch"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if obj.EmptyMessageBranch == nil { - v.Null = true - } else { - tf := &v - { - t, ok := tf.AttrTypes["active"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.EmptyMessageBranch.active"}) - } else { - v, ok := tf.Attrs["active"].(github_com_hashicorp_terraform_plugin_framework_types.Bool) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.EmptyMessageBranch.active", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Bool) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.EmptyMessageBranch.active", "github.com/hashicorp/terraform-plugin-framework/types.Bool"}) - } - v.Null = true - } - v.Unknown = false - tf.Attrs["active"] = v - } - } + if obj.EmptyMessageBranch == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + v = github_com_hashicorp_terraform_plugin_framework_types.BoolNull() + attrs["active"] = v } - v.Unknown = false - tf.Attrs["empty_message_branch"] = v } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["empty_message_branch"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := float64(obj.Float) + if val == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.Float64Null() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.Float64Value(val) } + attrs["float"] = v } { - t, ok := tf.AttrTypes["float"] + obj, ok := obj.LowerSnakeOneof.(*Test_Foo) if !ok { - diags.Append(attrWriteMissingDiag{"Test.Float"}) + obj = &Test_Foo{} + } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Foo) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v, ok := tf.Attrs["float"].(github_com_hashicorp_terraform_plugin_framework_types.Float64) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Float", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Float64) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Float", "github.com/hashicorp/terraform-plugin-framework/types.Float64"}) - } - v.Null = float64(obj.Float) == 0 - } - v.Value = float64(obj.Float) - v.Unknown = false - tf.Attrs["float"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["foo"] = v } { - t, ok := tf.AttrTypes["foo"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.foo"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := int64(obj.Int32) + if val == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Null() } else { - obj, ok := obj.LowerSnakeOneof.(*Test_Foo) - if !ok { - obj = &Test_Foo{} - } - v, ok := tf.Attrs["foo"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.foo", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.foo", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Foo) == "" - } - v.Value = string(obj.Foo) - v.Unknown = false - tf.Attrs["foo"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Value(val) } + attrs["int32"] = v } { - t, ok := tf.AttrTypes["int32"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Int32"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := int64(obj.Int64) + if val == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Null() } else { - v, ok := tf.Attrs["int32"].(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Int32", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Int32", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) - } - v.Null = int64(obj.Int32) == 0 - } - v.Value = int64(obj.Int32) - v.Unknown = false - tf.Attrs["int32"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Value(val) } + attrs["int64"] = v } { - t, ok := tf.AttrTypes["int64"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Int64"}) + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) } else { - v, ok := tf.Attrs["int64"].(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Int64", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Int64", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) - } - v.Null = int64(obj.Int64) == 0 + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v } - v.Value = int64(obj.Int64) - v.Unknown = false - tf.Attrs["int64"] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map"] = v } { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Map"}) + elemType := schemaObj.AttrTypes["map_object"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObject) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Map", err}) + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObject)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObject { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result + } + attrs["map"] = v + } + { + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v + } + } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) + attrs["map_object_nested"] = v + } + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) + } else { + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v + } + } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - v.Null = false + attrs["nested_list"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false } - } - c.Unknown = false - tf.Attrs["map"] = c + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map_object"] = v } { - a, ok := tf.AttrTypes["map_object"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject"}) + elemType := schemaObj.AttrTypes["map_object_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNullable) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObject)), - Null: true, + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNullable)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNullable { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObject)) - } - } - if obj.MapObject != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObject { - v, ok := tf.Attrs["map_object"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result + } + attrs["map"] = v } { - obj := a - tf := &v - { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObject.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } - } - } - { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject.MapObjectNested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObject.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false + attrs["str"] = v } } - c.Unknown = false - tf.Attrs["map_object_nested"] = c - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } + attrs["map_object_nested"] = v + } + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) + } else { + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject.NestedList.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObject.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false + attrs["str"] = v } } - c.Unknown = false - tf.Attrs["nested_list"] = c - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObject.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObject.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObject.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } + attrs["nested_list"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObject) > 0 { - c.Null = false } - } - c.Unknown = false - tf.Attrs["map_object"] = c + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map_object_nullable"] = v } { - a, ok := tf.AttrTypes["map_object_nullable"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := int64(obj.Mode) + if val == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Null() } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNullable)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNullable)) + v = github_com_hashicorp_terraform_plugin_framework_types.Int64Value(val) + } + attrs["mode"] = v + } + { + schemaObj := schemaObj.AttrTypes["nested"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := obj.Nested + { + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map"] = v } - if obj.MapObjectNullable != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNullable { - v, ok := tf.Attrs["map_object_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true - } else { - obj := a - tf := &v - { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObjectNullable.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } - } - } - { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } + { + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable.MapObjectNested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObjectNullable.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false - } + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - c.Unknown = false - tf.Attrs["map_object_nested"] = c + attrs["str"] = v } } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result + } + attrs["map_object_nested"] = v + } + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) + } else { + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true - } else { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable.NestedList.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObjectNullable.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["nested_list"] = c - } - } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.MapObjectNullable.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.MapObjectNullable.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.MapObjectNullable.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - v.Null = string(obj.Str) == "" + attrs["str"] = v } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v } - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - v.Unknown = false - c.Elems[k] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - if len(obj.MapObjectNullable) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map_object_nullable"] = c - } - } - } - { - t, ok := tf.AttrTypes["mode"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Mode"}) - } else { - v, ok := tf.Attrs["mode"].(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Mode", err}) + attrs["nested_list"] = v } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Int64) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Mode", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v } - v.Null = int64(obj.Mode) == 0 } - v.Value = int64(obj.Mode) - v.Unknown = false - tf.Attrs["mode"] = v - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["nested"] = v } { - a, ok := tf.AttrTypes["nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested"}) + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := obj.Nested - tf := &v - { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Nested.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } - } - } + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested.MapObjectNested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Nested.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map_object_nested"] = c - } - } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true - } else { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested.NestedList.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Nested.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["nested_list"] = c - } - } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Nested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Nested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Nested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - tf.Attrs["nested"] = v - } - } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } + obj := a { - obj := a - tf := &v - { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedList.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } - } - } - { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList.MapObjectNested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedList.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map_object_nested"] = c - } - } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true - } else { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList.NestedList.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedList.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["nested_list"] = c - } - } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedList.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["nested_list"] = c - } - } - } - { - a, ok := tf.AttrTypes["nested_list_nullable"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedListNullable)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedListNullable)) - } - } - if obj.NestedListNullable != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedListNullable) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedListNullable)) - } - for k, a := range obj.NestedListNullable { - v, ok := tf.Attrs["nested_list_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true - } else { - obj := a - tf := &v - { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedListNullable.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } - } - } - { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable.MapObjectNested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedListNullable.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map_object_nested"] = c - } - } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if a == nil { - v.Null = true - } else { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable.NestedList.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedListNullable.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["nested_list"] = c - } - } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedListNullable.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedListNullable.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedListNullable.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedListNullable) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["nested_list_nullable"] = c - } - } - } - { - a, ok := tf.AttrTypes["nested_nullable"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["nested_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - if obj.NestedNullable == nil { - v.Null = true - } else { - obj := obj.NestedNullable - tf := &v - { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullable.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } - } - } - { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) - } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } - { - obj := a - tf := &v - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable.MapObjectNested.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullable.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v - } - } - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map_object_nested"] = c - } - } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result + } + attrs["map"] = v + } + { + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v } } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result + } + attrs["map_object_nested"] = v + } + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) + } else { + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { if a == nil { - v.Null = true - } else { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { obj := a - tf := &v { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable.NestedList.Str"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullable.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - c.Unknown = false - tf.Attrs["nested_list"] = c + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["nested_list"] = v } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullable.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullable.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullable.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v + attrs["str"] = v } } - } - v.Unknown = false - tf.Attrs["nested_nullable"] = v + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["nested_list"] = v } { - a, ok := tf.AttrTypes["nested_nullable_with_nil_value"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue"}) + elemType := schemaObj.AttrTypes["nested_list_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedListNullable) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue", "github.com/hashicorp/terraform-plugin-framework/types.ObjectType"}) - } else { - v, ok := tf.Attrs["nested_nullable_with_nil_value"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedListNullable)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedListNullable { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) } - } - if obj.NestedNullableWithNilValue == nil { - v.Null = true - } else { - obj := obj.NestedNullableWithNilValue - tf := &v + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) { - a, ok := tf.AttrTypes["map"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue.Map"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.Map", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) + obj := a + { + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) } else { - c, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) - } - } - if obj.Map != nil { - t := o.ElemType - for k, a := range obj.Map { - v, ok := tf.Attrs["map"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullableWithNilValue.Map", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.Map", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = false - } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v - } - if len(obj.Map) > 0 { - c.Null = false - } - } - c.Unknown = false - tf.Attrs["map"] = c - } + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result + } + attrs["map"] = v } - } - { - a, ok := tf.AttrTypes["map_object_nested"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue.MapObjectNested"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.MapType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.MapObjectNested", "github.com/hashicorp/terraform-plugin-framework/types.MapType"}) + { + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) } else { - c, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Map) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.Map{ - - ElemType: o.ElemType, - Elems: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) - } - } - if obj.MapObjectNested != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - for k, a := range obj.MapObjectNested { - v, ok := tf.Attrs["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) { obj := a - tf := &v { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue.MapObjectNested.Str"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullableWithNilValue.MapObjectNested.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.MapObjectNested.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.MapObjectNested) > 0 { - c.Null = false - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - c.Unknown = false - tf.Attrs["map_object_nested"] = c + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map_object_nested"] = v } - } - { - a, ok := tf.AttrTypes["nested_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue.NestedList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.NestedList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - c, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - } - if obj.NestedList != nil { - o := o.ElemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) - if len(obj.NestedList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) - } - for k, a := range obj.NestedList { - v, ok := tf.Attrs["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.Object) - if !ok { - v = github_com_hashicorp_terraform_plugin_framework_types.Object{ - - AttrTypes: o.AttrTypes, - Attrs: make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(o.AttrTypes)), - } - } else { - if v.Attrs == nil { - v.Attrs = make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(tf.AttrTypes)) - } - } + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { if a == nil { - v.Null = true - } else { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { obj := a - tf := &v { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue.NestedList.Str"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullableWithNilValue.NestedList.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.NestedList.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" - } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.NestedList) > 0 { - c.Null = false - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - c.Unknown = false - tf.Attrs["nested_list"] = c + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["nested_list"] = v } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.NestedNullableWithNilValue.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.NestedNullableWithNilValue.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.NestedNullableWithNilValue.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v + attrs["str"] = v } } - } - v.Unknown = false - tf.Attrs["nested_nullable_with_nil_value"] = v - } - } - } - { - t, ok := tf.AttrTypes["str"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Str"}) - } else { - v, ok := tf.Attrs["str"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Str", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Str", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.Str) == "" + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - v.Value = string(obj.Str) - v.Unknown = false - tf.Attrs["str"] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["nested_list_nullable"] = v } { - t, ok := tf.AttrTypes["string_branch"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.StringBranch"}) - } else { - obj, ok := obj.OneOfWithEmptyMessage.(*Test_StringBranch) - if !ok { - obj = &Test_StringBranch{} - } - v, ok := tf.Attrs["string_branch"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.StringBranch", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.StringBranch", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(obj.StringBranch) == "" + schemaObj := schemaObj.AttrTypes["nested_nullable"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if obj.NestedNullable == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) } - v.Value = string(obj.StringBranch) - v.Unknown = false - tf.Attrs["string_branch"] = v - } - } - { - a, ok := tf.AttrTypes["string_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.StringList"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.StringList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["string_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringList)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringList)) + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := obj.NestedNullable + { + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map"] = v } - if obj.StringList != nil { - t := o.ElemType - if len(obj.StringList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringList)) + { + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v + } + } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - for k, a := range obj.StringList { - v, ok := tf.Attrs["string_list"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.StringList", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.StringList", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(a) == "" + attrs["map_object_nested"] = v + } + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) + } else { + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v + } + } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - if len(obj.StringList) > 0 { - c.Null = false + attrs["nested_list"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } - c.Unknown = false - tf.Attrs["string_list"] = c } - } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["nested_nullable"] = v } { - a, ok := tf.AttrTypes["string_list_empty"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.StringListEmpty"}) - } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.StringListEmpty", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["string_list_empty"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringListEmpty)), - Null: true, - } - } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringListEmpty)) + schemaObj := schemaObj.AttrTypes["nested_nullable_with_nil_value"].(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if obj.NestedNullableWithNilValue == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := obj.NestedNullableWithNilValue + { + elemType := schemaObj.AttrTypes["map"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.Map) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.Map)) + for k, a := range obj.Map { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["map"] = v } - if obj.StringListEmpty != nil { - t := o.ElemType - if len(obj.StringListEmpty) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringListEmpty)) + { + elemType := schemaObj.AttrTypes["map_object_nested"].(github_com_hashicorp_terraform_plugin_framework_types.MapType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.MapObjectNested) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.MapNull(elemType) + } else { + elems := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.MapObjectNested)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.MapObjectNested { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v + } + } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.MapValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - for k, a := range obj.StringListEmpty { - v, ok := tf.Attrs["string_list_empty"].(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.StringListEmpty", err}) - } - v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.StringListEmpty", "github.com/hashicorp/terraform-plugin-framework/types.String"}) - } - v.Null = string(a) == "" + attrs["map_object_nested"] = v + } + { + elemType := schemaObj.AttrTypes["nested_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.NestedList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) + } else { + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.NestedList)) + schemaObj := elemType.(github_com_hashicorp_terraform_plugin_framework_types.ObjectType) + for k, a := range obj.NestedList { + v := func() github_com_hashicorp_terraform_plugin_framework_attr.Value { + if a == nil { + return github_com_hashicorp_terraform_plugin_framework_types.ObjectNull(schemaObj.AttrTypes) + } + attrs := make(map[string]github_com_hashicorp_terraform_plugin_framework_attr.Value) + { + obj := a + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) + } + attrs["str"] = v + } + } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + elems[k] = v } - v.Value = string(a) - v.Unknown = false - c.Elems[k] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } - if len(obj.StringListEmpty) > 0 { - c.Null = false + attrs["nested_list"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } - c.Unknown = false - tf.Attrs["string_list_empty"] = c } + result, objDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(objDiags...) + return result + }() + attrs["nested_nullable_with_nil_value"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.Str) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["str"] = v } { - t, ok := tf.AttrTypes["string_override"] + obj, ok := obj.OneOfWithEmptyMessage.(*Test_StringBranch) if !ok { - diags.Append(attrWriteMissingDiag{"Test.StringOverride"}) + obj = &Test_StringBranch{} + } + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(obj.StringBranch) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - v := CopyToStringCustom(diags, obj.StringOverride, t, tf.Attrs["string_override"]) - tf.Attrs["string_override"] = v + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } + attrs["string_branch"] = v } { - t, ok := tf.AttrTypes["timestamp"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Timestamp"}) + elemType := schemaObj.AttrTypes["string_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.StringList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - v, ok := tf.Attrs["timestamp"].(TimeValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Timestamp", err}) - } - v, ok = i.(TimeValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Timestamp", "TimeValue"}) + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringList)) + for k, a := range obj.StringList { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() + } else { + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - v.Null = false + elems[k] = v } - v.Value = time.Time(obj.Timestamp) - v.Unknown = false - tf.Attrs["timestamp"] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["string_list"] = v } { - a, ok := tf.AttrTypes["timestamp_list"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.TimestampList"}) + elemType := schemaObj.AttrTypes["string_list_empty"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.StringListEmpty) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - o, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.ListType) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.TimestampList", "github.com/hashicorp/terraform-plugin-framework/types.ListType"}) - } else { - c, ok := tf.Attrs["timestamp_list"].(github_com_hashicorp_terraform_plugin_framework_types.List) - if !ok { - c = github_com_hashicorp_terraform_plugin_framework_types.List{ - - ElemType: o.ElemType, - Elems: make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.TimestampList)), - Null: true, - } + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.StringListEmpty)) + for k, a := range obj.StringListEmpty { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := string(a) + if val == "" { + v = github_com_hashicorp_terraform_plugin_framework_types.StringNull() } else { - if c.Elems == nil { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.TimestampList)) - } - } - if obj.TimestampList != nil { - t := o.ElemType - if len(obj.TimestampList) != len(c.Elems) { - c.Elems = make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.TimestampList)) - } - for k, a := range obj.TimestampList { - v, ok := tf.Attrs["timestamp_list"].(TimeValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.TimestampList", err}) - } - v, ok = i.(TimeValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.TimestampList", "TimeValue"}) - } - v.Null = false - } - if a == nil { - v.Null = true - } else { - v.Null = false - v.Value = time.Time(*a) - } - v.Unknown = false - c.Elems[k] = v - } - if len(obj.TimestampList) > 0 { - c.Null = false - } + v = github_com_hashicorp_terraform_plugin_framework_types.StringValue(val) } - c.Unknown = false - tf.Attrs["timestamp_list"] = c + elems[k] = v } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["string_list_empty"] = v } { - t, ok := tf.AttrTypes["timestamp_missing"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.TimestampMissing"}) + v := CopyToStringCustom(diags, obj.StringOverride) + attrs["string_override"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Time(obj.Timestamp) + v = ValueTime(val) + attrs["timestamp"] = v + } + { + elemType := schemaObj.AttrTypes["timestamp_list"].(github_com_hashicorp_terraform_plugin_framework_types.ListType).ElemType + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if len(obj.TimestampList) == 0 { + v = github_com_hashicorp_terraform_plugin_framework_types.ListNull(elemType) } else { - v, ok := tf.Attrs["timestamp_missing"].(TimeValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.TimestampMissing", err}) - } - v, ok = i.(TimeValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.TimestampMissing", "TimeValue"}) + elems := make([]github_com_hashicorp_terraform_plugin_framework_attr.Value, len(obj.TimestampList)) + for k, a := range obj.TimestampList { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if a == nil { + v = NullTime() + } else { + v = ValueTime(time.Time(*a)) } - v.Null = false + elems[k] = v } - v.Value = time.Time(obj.TimestampMissing) - v.Unknown = false - tf.Attrs["timestamp_missing"] = v + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ListValue(elemType, elems) + diags.Append(resultDiags...) + v = result } + attrs["timestamp_list"] = v } { - t, ok := tf.AttrTypes["timestamp_nullable"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.TimestampNullable"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + val := time.Time(obj.TimestampMissing) + v = ValueTime(val) + attrs["timestamp_missing"] = v + } + { + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if obj.TimestampNullable == nil { + v = NullTime() } else { - v, ok := tf.Attrs["timestamp_nullable"].(TimeValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.TimestampNullable", err}) - } - v, ok = i.(TimeValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.TimestampNullable", "TimeValue"}) - } - v.Null = false - } - if obj.TimestampNullable == nil { - v.Null = true - } else { - v.Null = false - v.Value = time.Time(*obj.TimestampNullable) - } - v.Unknown = false - tf.Attrs["timestamp_nullable"] = v + v = ValueTime(time.Time(*obj.TimestampNullable)) } + attrs["timestamp_nullable"] = v } { - t, ok := tf.AttrTypes["timestamp_nullable_with_nil_value"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.TimestampNullableWithNilValue"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if obj.TimestampNullableWithNilValue == nil { + v = NullTime() } else { - v, ok := tf.Attrs["timestamp_nullable_with_nil_value"].(TimeValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.TimestampNullableWithNilValue", err}) - } - v, ok = i.(TimeValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.TimestampNullableWithNilValue", "TimeValue"}) - } - v.Null = false - } - if obj.TimestampNullableWithNilValue == nil { - v.Null = true - } else { - v.Null = false - v.Value = time.Time(*obj.TimestampNullableWithNilValue) - } - v.Unknown = false - tf.Attrs["timestamp_nullable_with_nil_value"] = v + v = ValueTime(time.Time(*obj.TimestampNullableWithNilValue)) } + attrs["timestamp_nullable_with_nil_value"] = v } { - t, ok := tf.AttrTypes["max_age"] - if !ok { - diags.Append(attrWriteMissingDiag{"Test.Value"}) + var v github_com_hashicorp_terraform_plugin_framework_attr.Value + if obj.MaxAgeDuration == nil { + v = NullDuration() } else { - v, ok := tf.Attrs["max_age"].(DurationValue) - if !ok { - i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) - if err != nil { - diags.Append(attrWriteGeneralError{"Test.Value", err}) - } - v, ok = i.(DurationValue) - if !ok { - diags.Append(attrWriteConversionFailureDiag{"Test.Value", "DurationValue"}) - } - v.Null = false - } - if obj.MaxAgeDuration == nil { - v.Null = true - } else { - v.Value = time.Duration(obj.Value) - } - v.Unknown = false - tf.Attrs["max_age"] = v + val := time.Duration(obj.Value) + v = ValueDuration(val) } + attrs["max_age"] = v } - return diags + if _, ok := attrs["id"]; !ok { + attrs["id"] = github_com_hashicorp_terraform_plugin_framework_types.StringUnknown() + } + result, resultDiags := github_com_hashicorp_terraform_plugin_framework_types.ObjectValue(schemaObj.AttrTypes, attrs) + diags.Append(resultDiags...) + return result, diags } // attrReadMissingDiag represents diagnostic message on an attribute missing in the source object diff --git a/test/time_duration.go b/test/time_duration.go index 8d36ed0..925f79b 100644 --- a/test/time_duration.go +++ b/test/time_duration.go @@ -143,6 +143,18 @@ func (t TimeValue) String() string { return t.Value.String() } +// ValueTime returns the underlying time value +func (t TimeValue) ValueTime() time.Time { return t.Value } + +func ValueTime(value time.Time) TimeValue { + return TimeValue{Value: value, Format: time.RFC3339} +} + +// NullTime returns a null time value +func NullTime() TimeValue { + return TimeValue{Null: true, Format: time.RFC3339} +} + // DurationType represents time.Time Terraform type which is stored in RFC3339 format, nanoseconds truncated type DurationType struct { attr.Type @@ -208,9 +220,12 @@ type DurationValue struct { Value time.Duration } +// ValueDuration returns the underlying duration value. +func (t DurationValue) ValueDuration() Duration { return Duration(t.Value) } + // Type returns value type func (t DurationValue) Type(_ context.Context) attr.Type { - return TimeType{} + return DurationType{} } // ToTerraformValue returns the data contained in the *String as a string. If @@ -263,3 +278,13 @@ func (t DurationValue) String() string { return t.Value.String() } + +// ValueDuration constructs a DurationValue from the given duration +func ValueDuration(value time.Duration) DurationValue { + return DurationValue{Value: value} +} + +// NullDuration returns a null duration +func NullDuration() DurationValue { + return DurationValue{Null: true} +}