diff --git a/field.go b/field.go index 4114e7c..447d80e 100644 --- a/field.go +++ b/field.go @@ -115,6 +115,8 @@ type Field struct { IsNullable bool // IsSensitive is field sensitive? (password, token) IsSensitive bool + // IsEmbed is field embedded? + IsEmbed bool // Validators represents the array of field validators for a field Validators []string // PlanModifiers represents the array of plan modifiers for a field @@ -189,6 +191,7 @@ func BuildField(c *FieldBuildContext) (*Field, error) { IsRepeated: c.IsRepeated(), IsMap: c.IsMap(), IsNullable: c.GetNullable(), + IsEmbed: c.IsEmbed(), Validators: c.GetValidators(), PlanModifiers: c.GetPlanModifiers(), Path: c.GetPath(), diff --git a/field_build_context.go b/field_build_context.go index ef50a78..40b6b0b 100644 --- a/field_build_context.go +++ b/field_build_context.go @@ -89,6 +89,7 @@ type FieldBuildContext struct { imports *Imports path string goType string + isEmbed bool } // NewFieldBuildContext creates FieldBuildContext @@ -127,6 +128,7 @@ func NewFieldBuildContext(m MessageBuildContext, field *FieldDescriptorProtoExt, imports: m.imports, path: path, goType: m.imports.PrependPackageNameIfMissing(t, m.config.DefaultPackageName), + isEmbed: field.IsEmbed(), } return c, nil @@ -166,6 +168,16 @@ func (c *FieldBuildContext) GetNameWithTypeName() string { // GetName returns field name func (c *FieldBuildContext) GetName() string { + if c.IsEmbed() { + // Return the name of the struct with no prepended package or pointer. + goType := strings.TrimPrefix(c.GetGoType(), "*") + goTypeSplit := strings.SplitN(goType, ".", 2) + if len(goTypeSplit) == 2 { + return goTypeSplit[1] + } + return goType + } + name := c.field.GetName() if name[0:1] == strings.ToLower(name[0:1]) { return strcase.UpperCamelCase(name) @@ -316,6 +328,11 @@ func (c *FieldBuildContext) IsCastType() bool { return c.field.IsCastType() } +// IsEmbed returns true if the field has gogo.embed flag set to true +func (c *FieldBuildContext) IsEmbed() bool { + return c.isEmbed +} + // GetComment returns field comment as a single line func (c *FieldBuildContext) GetComment() string { // ",2," marks that we are extracting comment for a message field. See descriptor.SourceCodeInfo source for details. diff --git a/field_build_context_test.go b/field_build_context_test.go new file mode 100644 index 0000000..effddb0 --- /dev/null +++ b/field_build_context_test.go @@ -0,0 +1,78 @@ +/* +Copyright 2023 Gravitational, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "testing" + + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" + "github.com/stretchr/testify/require" +) + +func TestFieldBuildContextGetName(t *testing.T) { + tests := []struct { + name string + embedded bool + fieldName string + goType string + expected string + }{ + { + name: "regular name", + fieldName: "Name", + expected: "Name", + }, + { + name: "embedded name", + embedded: true, + fieldName: "Name", + goType: "EmbeddedName", + expected: "EmbeddedName", + }, + { + name: "embedded name with pointer", + embedded: true, + fieldName: "Name", + goType: "*EmbeddedName", + expected: "EmbeddedName", + }, + { + name: "embedded name in another package", + embedded: true, + fieldName: "Name", + goType: "*someotherpackage.EmbeddedName", + expected: "EmbeddedName", + }, + } + + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + t.Parallel() + msg := &descriptor.FieldDescriptorProto{ + Name: &test.fieldName, + } + + fbc := FieldBuildContext{ + field: &FieldDescriptorProtoExt{msg}, + goType: test.goType, + isEmbed: test.embedded, + } + require.Equal(t, test.expected, fbc.GetName()) + }) + } +} diff --git a/field_descriptor_proto_ext.go b/field_descriptor_proto_ext.go index 7678f68..971a2da 100644 --- a/field_descriptor_proto_ext.go +++ b/field_descriptor_proto_ext.go @@ -80,6 +80,11 @@ func (f *FieldDescriptorProtoExt) IsCustomType() bool { return gogoproto.IsCustomType(f.FieldDescriptorProto) } +// IsEmbed returns true if the field has the gogoproto.embed flag set to true +func (f *FieldDescriptorProtoExt) IsEmbed() bool { + return gogoproto.IsEmbed(f.FieldDescriptorProto) +} + // GetCastType returns field cast type name func (f *FieldDescriptorProtoExt) GetCastType() string { return gogoproto.GetCastType(f.FieldDescriptorProto) diff --git a/gen_copy_from.go b/gen_copy_from.go index b76dc99..8f28108 100644 --- a/gen_copy_from.go +++ b/gen_copy_from.go @@ -100,6 +100,9 @@ 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 { + if f.IsEmbed { + return j.BlockFunc(g) + } 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)), @@ -182,11 +185,12 @@ func (f *FieldCopyFromGenerator) genObject() *j.Statement { // obj.Nested = Nested{} 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) { + fn := func(g *j.Group) { if !m.IsEmpty { - // tf := v - g.Id("tf").Op(":=").Id("v") + if !f.IsEmbed { + // tf := v + g.Id("tf").Op(":=").Id("v") + } if f.IsNullable { // obj.Nested = &Nested{} @@ -200,7 +204,13 @@ func (f *FieldCopyFromGenerator) genObject() *j.Statement { m.GenerateFields(g) } - }) + } + if f.IsEmbed { + g.BlockFunc(fn) + } else { + // if !v.Null + g.If(j.Id("!v.Null && !v.Unknown")).BlockFunc(fn) + } } 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 diff --git a/gen_copy_to.go b/gen_copy_to.go index 0c90ed7..d6869d0 100644 --- a/gen_copy_to.go +++ b/gen_copy_to.go @@ -97,6 +97,9 @@ func (f *FieldCopyToGenerator) Generate() *j.Statement { // 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 { + if f.IsEmbed { + return j.BlockFunc(g) + } return j.Block( // _, ok := ft.AttrsTypes["key"] j.List(j.Id(v), j.Id("ok")).Op(":=").Id("tf.AttrTypes").Index(j.Lit(f.NameSnake)), @@ -179,11 +182,18 @@ func (f *FieldCopyToGenerator) genObjectBody(m *MessageCopyToGenerator, fieldNam if !m.IsEmpty { g.Id("obj").Op(":=").Id(fieldName) } - g.Id("tf").Op(":=").Id("&v") + if !f.IsEmbed { + g.Id("tf").Op(":=").Id("&v") + } m.GenerateFields(g) } } + if f.IsEmbed { + g.BlockFunc(copyObj) + return + } + 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} @@ -206,7 +216,6 @@ func (f *FieldCopyToGenerator) genObjectBody(m *MessageCopyToGenerator, fieldNam } else { g.BlockFunc(copyObj) } - g.Id("v.Unknown").Op("=").False() } // assertTo asserts a to typ @@ -251,10 +260,16 @@ func (f *FieldCopyToGenerator) genObject() *j.Statement { f.genOneOfStub(g) } - 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") - }) + if f.IsEmbed { + g.BlockFunc(func(g *j.Group) { + f.genObjectBody(m, fieldName, f.Field.ValueType, g) + }) + } else { + 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") + }) + } }) } diff --git a/gen_schema.go b/gen_schema.go index 72b865a..2e65314 100644 --- a/gen_schema.go +++ b/gen_schema.go @@ -22,7 +22,6 @@ import ( "io" - "github.com/dave/jennifer/jen" j "github.com/dave/jennifer/jen" ) @@ -73,8 +72,15 @@ func (m *MessageSchemaGenerator) fieldsDictSchema() j.Dict { d := j.Dict{} for _, f := range m.Fields { - f := NewFieldSchemaGenerator(f, m.i) - d[j.Lit(f.NameSnake)] = f.Generate() + if f.IsEmbed { + for _, f := range f.Message.Fields { + f := NewFieldSchemaGenerator(f, m.i) + d[j.Lit(f.NameSnake)] = f.Generate() + } + } else { + f := NewFieldSchemaGenerator(f, m.i) + d[j.Lit(f.NameSnake)] = f.Generate() + } } if len(m.Message.InjectedFields) > 0 { @@ -222,7 +228,7 @@ func (f *FieldSchemaGenerator) xNestedAttributes(typ string, m *MessageSchemaGen } func generatePlanModifiers(imports *Imports, pm []string) j.Code { - v := make([]jen.Code, len(pm)) + v := make([]j.Code, len(pm)) for i, n := range pm { v[i] = j.Id(imports.WithType(n)) } @@ -231,7 +237,7 @@ func generatePlanModifiers(imports *Imports, pm []string) j.Code { } func generateValidators(imports *Imports, vals []string) j.Code { - v := make([]jen.Code, len(vals)) + v := make([]j.Code, len(vals)) for i, n := range vals { v[i] = j.Id(imports.WithType(n)) } diff --git a/test/copy_from_terraform_test.go b/test/copy_from_terraform_test.go index 5df5335..59f2f3a 100644 --- a/test/copy_from_terraform_test.go +++ b/test/copy_from_terraform_test.go @@ -162,3 +162,13 @@ func TestCopyFromOneOfObjectNoBranch(t *testing.T) { require.Equal(t, nil, target.OneOf) } + +func TestCopyFromEmbedded(t *testing.T) { + obj := copyFromTerraformObject(t) + + target := Test{} + require.False(t, CopyTestFromTerraform(context.Background(), obj, &target).HasError()) + + require.Equal(t, int32(1), target.Embedded.EmbeddedOne) + require.Equal(t, int32(2), target.Embedded.EmbeddedTwo) +} diff --git a/test/copy_to_terraform_test.go b/test/copy_to_terraform_test.go index cb869f4..7530f83 100644 --- a/test/copy_to_terraform_test.go +++ b/test/copy_to_terraform_test.go @@ -318,3 +318,14 @@ func TestCopyToOneOfNoBranch(t *testing.T) { require.True(t, o.Attrs["branch2"].(types.Object).Null) require.True(t, o.Attrs["branch3"].(types.String).Null) } + +func TestCopyToEmbedded(t *testing.T) { + o := copyToTerraformObject(t) + testObj := createTestObj() + + diags := CopyTestToTerraform(context.Background(), testObj, &o) + require.False(t, diags.HasError()) + + require.Equal(t, types.Int64{Value: 1}, o.Attrs["embedded_one"]) + require.Equal(t, types.Int64{Value: 2}, o.Attrs["embedded_two"]) +} diff --git a/test/fixtures.go b/test/fixtures.go index 05afb0a..caaca23 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -92,6 +92,11 @@ func createTestObj() Test { }, Map: map[string]string{"key1": "value1", "key2": "value2"}, + + Embedded: &Embedded{ + EmbeddedOne: 1, + EmbeddedTwo: 2, + }, } } @@ -409,6 +414,9 @@ func copyFromTerraformObject(t *testing.T) types.Object { "branch3": types.String{Null: true}, "empty_message_branch": types.Object{Null: true}, "string_branch": types.String{Null: true}, + + "embedded_one": types.Int64{Value: 1}, + "embedded_two": types.Int64{Value: 2}, }, AttrTypes: obj.AttrTypes, } diff --git a/test/test.pb.go b/test/test.pb.go index 757de91..3547564 100644 --- a/test/test.pb.go +++ b/test/test.pb.go @@ -117,19 +117,21 @@ type Test struct { // Excluded is the excluded field Excluded bool `protobuf:"varint,32,opt,name=Excluded,proto3" json:"Excluded,omitempty"` // Types that are valid to be assigned to OneOf: - // // *Test_Branch1 // *Test_Branch2 // *Test_Branch3 OneOf isTest_OneOf `protobuf_oneof:"OneOf"` // Types that are valid to be assigned to OneOfWithEmptyMessage: - // // *Test_EmptyMessageBranch // *Test_StringBranch OneOfWithEmptyMessage isTest_OneOfWithEmptyMessage `protobuf_oneof:"OneOfWithEmptyMessage"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + // It's important that the name of this field doesn't match the name of the + // message, as golang expects this field to be referred to as its type as + // opposed to its field name. + *Embedded `protobuf:"bytes,38,opt,name=AnEmbeddedField,proto3,embedded=AnEmbeddedField" json:"AnEmbeddedField,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Test) Reset() { *m = Test{} } @@ -413,6 +415,41 @@ func (m *Branch2) XXX_DiscardUnknown() { var xxx_messageInfo_Branch2 proto.InternalMessageInfo +// Embedded message is embedded into the parent message +type Embedded struct { + // EmbeddedOne int field + EmbeddedOne int32 `protobuf:"varint,1,opt,name=EmbeddedOne,proto3" json:"EmbeddedOne,omitempty"` + // EmbeddedTwo int field + EmbeddedTwo int32 `protobuf:"varint,2,opt,name=EmbeddedTwo,proto3" json:"EmbeddedTwo,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Embedded) Reset() { *m = Embedded{} } +func (m *Embedded) String() string { return proto.CompactTextString(m) } +func (*Embedded) ProtoMessage() {} +func (*Embedded) Descriptor() ([]byte, []int) { + return fileDescriptor_c161fcfdc0c3ff1e, []int{6} +} +func (m *Embedded) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Embedded.Unmarshal(m, b) +} +func (m *Embedded) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Embedded.Marshal(b, m, deterministic) +} +func (m *Embedded) XXX_Merge(src proto.Message) { + xxx_messageInfo_Embedded.Merge(m, src) +} +func (m *Embedded) XXX_Size() int { + return xxx_messageInfo_Embedded.Size(m) +} +func (m *Embedded) XXX_DiscardUnknown() { + xxx_messageInfo_Embedded.DiscardUnknown(m) +} + +var xxx_messageInfo_Embedded proto.InternalMessageInfo + func init() { proto.RegisterEnum("test.Mode", Mode_name, Mode_value) proto.RegisterType((*Test)(nil), "test.Test") @@ -426,72 +463,76 @@ func init() { proto.RegisterType((*OtherNested)(nil), "test.OtherNested") proto.RegisterType((*Branch1)(nil), "test.Branch1") proto.RegisterType((*Branch2)(nil), "test.Branch2") + proto.RegisterType((*Embedded)(nil), "test.Embedded") } func init() { proto.RegisterFile("test.proto", fileDescriptor_c161fcfdc0c3ff1e) } var fileDescriptor_c161fcfdc0c3ff1e = []byte{ - // 978 bytes of a gzipped FileDescriptorProto - 0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, 0x1f, - 0x36, 0x12, 0xfb, 0x61, 0x7b, 0xbc, 0xa7, 0x26, 0x1d, 0xd7, 0xa1, 0x78, 0xd6, 0xfb, 0xaa, 0xd7, - 0x7f, 0xd5, 0xab, 0xe5, 0xb0, 0x00, 0xf9, 0x7e, 0xaf, 0x46, 0xb0, 0x08, 0x5a, 0xff, 0xe4, 0xa4, - 0x96, 0xb7, 0x2b, 0xd7, 0x7f, 0x36, 0x72, 0xd7, 0x6f, 0x1b, 0xb9, 0x5f, 0xdf, 0x36, 0x72, 0x83, - 0x82, 0xfc, 0xea, 0x1c, 0xfe, 0x13, 0x00, 0x00, 0xff, 0xff, 0x5e, 0xdf, 0x37, 0x5f, 0x71, 0x0a, - 0x00, 0x00, + // 1032 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4d, 0x73, 0x1b, 0x45, + 0x10, 0xd5, 0x68, 0xd7, 0xb6, 0xd4, 0x96, 0x65, 0xb9, 0xe3, 0x8f, 0x89, 0x42, 0xa4, 0x8d, 0x70, + 0xc8, 0x92, 0x83, 0x8c, 0xe5, 0x94, 0x8b, 0x4a, 0x41, 0xaa, 0x58, 0x62, 0x57, 0x08, 0x48, 0x82, + 0xb1, 0x4d, 0xce, 0x2b, 0x6b, 0x22, 0x2b, 0x48, 0xbb, 0x2a, 0xed, 0x08, 0xf0, 0xbf, 0xe0, 0xc8, + 0x4f, 0xf2, 0x31, 0x47, 0xe0, 0x60, 0x8a, 0x1c, 0xf9, 0x09, 0x9c, 0xa8, 0x9d, 0xd1, 0x7e, 0x6a, + 0x1d, 0x48, 0x6e, 0xd3, 0xaf, 0xdf, 0x7b, 0xf3, 0xd5, 0x3d, 0xbb, 0x00, 0x82, 0x7b, 0xa2, 0x39, + 0x99, 0xba, 0xc2, 0x45, 0xdd, 0x1f, 0x57, 0x37, 0x07, 0xee, 0xc0, 0x95, 0xc0, 0x9e, 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e, 0x0d, 0x00, 0x00, 0xff, 0xff, + 0x35, 0xda, 0xfc, 0xcd, 0x01, 0x0b, 0x00, 0x00, } diff --git a/test/test.proto b/test/test.proto index 7853931..c2631e0 100644 --- a/test/test.proto +++ b/test/test.proto @@ -154,6 +154,11 @@ message Test { // StringBranch is the oneof branch triggered by string value string StringBranch = 37; } + + // It's important that the name of this field doesn't match the name of the + // message, as golang expects this field to be referred to as its type as + // opposed to its field name. + Embedded AnEmbeddedField = 38 [ (gogoproto.embed) = true ]; } // EmptyMessageBranch message for empty oneof branch @@ -190,4 +195,13 @@ message Branch1 { message Branch2 { // Int32 int field int32 Int32 = 1; +} + +// Embedded message is embedded into the parent message +message Embedded { + // EmbeddedOne int field + int32 EmbeddedOne = 1; + + // EmbeddedTwo int field + int32 EmbeddedTwo = 2; } \ No newline at end of file diff --git a/test/test_terraform.go b/test/test_terraform.go index 2daea67..7b5829f 100644 --- a/test/test_terraform.go +++ b/test/test_terraform.go @@ -112,6 +112,16 @@ func GenSchemaTest(ctx context.Context) (github_com_hashicorp_terraform_plugin_f Optional: true, Type: DurationType{}, }, + "embedded_one": { + Description: "EmbeddedOne int field", + Optional: true, + Type: github_com_hashicorp_terraform_plugin_framework_types.Int64Type, + }, + "embedded_two": { + Description: "EmbeddedTwo int field", + Optional: true, + Type: github_com_hashicorp_terraform_plugin_framework_types.Int64Type, + }, "empty_message_branch": { Attributes: github_com_hashicorp_terraform_plugin_framework_tfsdk.SingleNestedAttributes(map[string]github_com_hashicorp_terraform_plugin_framework_tfsdk.Attribute{"active": { Computed: true, @@ -717,6 +727,47 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } } + { + obj.Embedded = nil + { + obj.Embedded = &Embedded{} + obj := obj.Embedded + { + a, ok := tf.Attrs["embedded_one"] + if !ok { + diags.Append(attrReadMissingDiag{"Test.AnEmbeddedField.EmbeddedOne"}) + } else { + v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Int64) + if !ok { + diags.Append(attrReadConversionFailureDiag{"Test.AnEmbeddedField.EmbeddedOne", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) + } else { + var t int32 + if !v.Null && !v.Unknown { + t = int32(v.Value) + } + obj.EmbeddedOne = t + } + } + } + { + a, ok := tf.Attrs["embedded_two"] + if !ok { + diags.Append(attrReadMissingDiag{"Test.AnEmbeddedField.EmbeddedTwo"}) + } else { + v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.Int64) + if !ok { + diags.Append(attrReadConversionFailureDiag{"Test.AnEmbeddedField.EmbeddedTwo", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) + } else { + var t int32 + if !v.Null && !v.Unknown { + t = int32(v.Value) + } + obj.EmbeddedTwo = t + } + } + } + } + } { a, ok := tf.Attrs["empty_message_branch"] if !ok { @@ -2223,7 +2274,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false tf.Attrs["branch1"] = v } } @@ -2281,7 +2331,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false tf.Attrs["branch2"] = v } } @@ -2550,6 +2599,57 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp tf.Attrs["duration_standard_missing"] = v } } + { + { + { + obj := obj.Embedded + { + t, ok := tf.AttrTypes["embedded_one"] + if !ok { + diags.Append(attrWriteMissingDiag{"Test.AnEmbeddedField.EmbeddedOne"}) + } else { + v, ok := tf.Attrs["embedded_one"].(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.AnEmbeddedField.EmbeddedOne", err}) + } + v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Int64) + if !ok { + diags.Append(attrWriteConversionFailureDiag{"Test.AnEmbeddedField.EmbeddedOne", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) + } + v.Null = int64(obj.EmbeddedOne) == 0 + } + v.Value = int64(obj.EmbeddedOne) + v.Unknown = false + tf.Attrs["embedded_one"] = v + } + } + { + t, ok := tf.AttrTypes["embedded_two"] + if !ok { + diags.Append(attrWriteMissingDiag{"Test.AnEmbeddedField.EmbeddedTwo"}) + } else { + v, ok := tf.Attrs["embedded_two"].(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.AnEmbeddedField.EmbeddedTwo", err}) + } + v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.Int64) + if !ok { + diags.Append(attrWriteConversionFailureDiag{"Test.AnEmbeddedField.EmbeddedTwo", "github.com/hashicorp/terraform-plugin-framework/types.Int64"}) + } + v.Null = int64(obj.EmbeddedTwo) == 0 + } + v.Value = int64(obj.EmbeddedTwo) + v.Unknown = false + tf.Attrs["embedded_two"] = v + } + } + } + } + } { a, ok := tf.AttrTypes["empty_message_branch"] if !ok { @@ -2601,7 +2701,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false tf.Attrs["empty_message_branch"] = v } } @@ -2875,7 +2974,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -2955,7 +3053,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -2990,7 +3087,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObject) > 0 { @@ -3157,7 +3253,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -3237,7 +3332,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -3272,7 +3366,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNullable) > 0 { @@ -3443,7 +3536,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -3523,7 +3615,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -3558,7 +3649,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false tf.Attrs["nested"] = v } } @@ -3719,7 +3809,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -3799,7 +3888,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -3834,7 +3922,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -4004,7 +4091,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -4084,7 +4170,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -4119,7 +4204,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedListNullable) > 0 { @@ -4270,7 +4354,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -4350,7 +4433,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -4385,7 +4467,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false tf.Attrs["nested_nullable"] = v } } @@ -4529,7 +4610,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.MapObjectNested) > 0 { @@ -4609,7 +4689,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false c.Elems[k] = v } if len(obj.NestedList) > 0 { @@ -4644,7 +4723,6 @@ func CopyTestToTerraform(ctx context.Context, obj Test, tf *github_com_hashicorp } } } - v.Unknown = false tf.Attrs["nested_nullable_with_nil_value"] = v } }