From 3d7dd501da7c625f2268a23ebf5e12012efce246 Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Fri, 11 Aug 2023 11:26:36 +0100 Subject: [PATCH] Add handling in the flatten functions for api objects that could be nil (#31) --- .../all_output/datasource_data_source_gen.go | 50 +++++++++++++++---- .../all_output/provider_provider_gen.go | 50 +++++++++++++++---- .../all_output/resource_resource_gen.go | 50 +++++++++++++++---- .../datasource_data_source_gen.go | 50 +++++++++++++++---- .../provider_output/provider_provider_gen.go | 50 +++++++++++++++---- .../resources_output/resource_resource_gen.go | 50 +++++++++++++++---- .../list_nested_object_to_from.gotmpl | 10 +++- .../map_nested_object_to_from.gotmpl | 10 +++- .../set_nested_object_to_from.gotmpl | 10 +++- 9 files changed, 264 insertions(+), 66 deletions(-) diff --git a/internal/cmd/testdata/custom_and_external/all_output/datasource_data_source_gen.go b/internal/cmd/testdata/custom_and_external/all_output/datasource_data_source_gen.go index 75414752..02262458 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/datasource_data_source_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/datasource_data_source_gen.go @@ -1369,10 +1369,16 @@ func FromListNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apis ), diags } - var tfModels []ListNestedAttributeAssocExtTypeModel + var tfModels []*ListNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1470,10 +1476,16 @@ func FromMapNestedAttributeAssocExtType(ctx context.Context, apiObjects map[stri ), diags } - tfModels := make(map[string]MapNestedAttributeAssocExtTypeModel) + tfModels := make(map[string]*MapNestedAttributeAssocExtTypeModel) for k, apiObject := range apiObjects { - tfModels[k] = MapNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels[k] = nil + + continue + } + + tfModels[k] = &MapNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1571,10 +1583,16 @@ func FromSetNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apisd ), diags } - var tfModels []SetNestedAttributeAssocExtTypeModel + var tfModels []*SetNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1724,10 +1742,16 @@ func FromListNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.T ), diags } - var tfModels []ListNestedBlockAssocExtTypeModel + var tfModels []*ListNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1825,10 +1849,16 @@ func FromSetNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.Ty ), diags } - var tfModels []SetNestedBlockAssocExtTypeModel + var tfModels []*SetNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), diff --git a/internal/cmd/testdata/custom_and_external/all_output/provider_provider_gen.go b/internal/cmd/testdata/custom_and_external/all_output/provider_provider_gen.go index 53294180..c7d66590 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/provider_provider_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/provider_provider_gen.go @@ -508,10 +508,16 @@ func FromListNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apis ), diags } - var tfModels []ListNestedAttributeAssocExtTypeModel + var tfModels []*ListNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -609,10 +615,16 @@ func FromMapNestedAttributeAssocExtType(ctx context.Context, apiObjects map[stri ), diags } - tfModels := make(map[string]MapNestedAttributeAssocExtTypeModel) + tfModels := make(map[string]*MapNestedAttributeAssocExtTypeModel) for k, apiObject := range apiObjects { - tfModels[k] = MapNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels[k] = nil + + continue + } + + tfModels[k] = &MapNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -710,10 +722,16 @@ func FromSetNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apisd ), diags } - var tfModels []SetNestedAttributeAssocExtTypeModel + var tfModels []*SetNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -863,10 +881,16 @@ func FromListNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.T ), diags } - var tfModels []ListNestedBlockAssocExtTypeModel + var tfModels []*ListNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -964,10 +988,16 @@ func FromSetNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.Ty ), diags } - var tfModels []SetNestedBlockAssocExtTypeModel + var tfModels []*SetNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), diff --git a/internal/cmd/testdata/custom_and_external/all_output/resource_resource_gen.go b/internal/cmd/testdata/custom_and_external/all_output/resource_resource_gen.go index af7679f0..71bb0df4 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/resource_resource_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/resource_resource_gen.go @@ -526,10 +526,16 @@ func FromListNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apis ), diags } - var tfModels []ListNestedAttributeAssocExtTypeModel + var tfModels []*ListNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -627,10 +633,16 @@ func FromMapNestedAttributeAssocExtType(ctx context.Context, apiObjects map[stri ), diags } - tfModels := make(map[string]MapNestedAttributeAssocExtTypeModel) + tfModels := make(map[string]*MapNestedAttributeAssocExtTypeModel) for k, apiObject := range apiObjects { - tfModels[k] = MapNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels[k] = nil + + continue + } + + tfModels[k] = &MapNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -728,10 +740,16 @@ func FromSetNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apisd ), diags } - var tfModels []SetNestedAttributeAssocExtTypeModel + var tfModels []*SetNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -881,10 +899,16 @@ func FromListNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.T ), diags } - var tfModels []ListNestedBlockAssocExtTypeModel + var tfModels []*ListNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -982,10 +1006,16 @@ func FromSetNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.Ty ), diags } - var tfModels []SetNestedBlockAssocExtTypeModel + var tfModels []*SetNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), diff --git a/internal/cmd/testdata/custom_and_external/data_sources_output/datasource_data_source_gen.go b/internal/cmd/testdata/custom_and_external/data_sources_output/datasource_data_source_gen.go index 75414752..02262458 100644 --- a/internal/cmd/testdata/custom_and_external/data_sources_output/datasource_data_source_gen.go +++ b/internal/cmd/testdata/custom_and_external/data_sources_output/datasource_data_source_gen.go @@ -1369,10 +1369,16 @@ func FromListNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apis ), diags } - var tfModels []ListNestedAttributeAssocExtTypeModel + var tfModels []*ListNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1470,10 +1476,16 @@ func FromMapNestedAttributeAssocExtType(ctx context.Context, apiObjects map[stri ), diags } - tfModels := make(map[string]MapNestedAttributeAssocExtTypeModel) + tfModels := make(map[string]*MapNestedAttributeAssocExtTypeModel) for k, apiObject := range apiObjects { - tfModels[k] = MapNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels[k] = nil + + continue + } + + tfModels[k] = &MapNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1571,10 +1583,16 @@ func FromSetNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apisd ), diags } - var tfModels []SetNestedAttributeAssocExtTypeModel + var tfModels []*SetNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1724,10 +1742,16 @@ func FromListNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.T ), diags } - var tfModels []ListNestedBlockAssocExtTypeModel + var tfModels []*ListNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -1825,10 +1849,16 @@ func FromSetNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.Ty ), diags } - var tfModels []SetNestedBlockAssocExtTypeModel + var tfModels []*SetNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), diff --git a/internal/cmd/testdata/custom_and_external/provider_output/provider_provider_gen.go b/internal/cmd/testdata/custom_and_external/provider_output/provider_provider_gen.go index 53294180..c7d66590 100644 --- a/internal/cmd/testdata/custom_and_external/provider_output/provider_provider_gen.go +++ b/internal/cmd/testdata/custom_and_external/provider_output/provider_provider_gen.go @@ -508,10 +508,16 @@ func FromListNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apis ), diags } - var tfModels []ListNestedAttributeAssocExtTypeModel + var tfModels []*ListNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -609,10 +615,16 @@ func FromMapNestedAttributeAssocExtType(ctx context.Context, apiObjects map[stri ), diags } - tfModels := make(map[string]MapNestedAttributeAssocExtTypeModel) + tfModels := make(map[string]*MapNestedAttributeAssocExtTypeModel) for k, apiObject := range apiObjects { - tfModels[k] = MapNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels[k] = nil + + continue + } + + tfModels[k] = &MapNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -710,10 +722,16 @@ func FromSetNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apisd ), diags } - var tfModels []SetNestedAttributeAssocExtTypeModel + var tfModels []*SetNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -863,10 +881,16 @@ func FromListNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.T ), diags } - var tfModels []ListNestedBlockAssocExtTypeModel + var tfModels []*ListNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -964,10 +988,16 @@ func FromSetNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.Ty ), diags } - var tfModels []SetNestedBlockAssocExtTypeModel + var tfModels []*SetNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), diff --git a/internal/cmd/testdata/custom_and_external/resources_output/resource_resource_gen.go b/internal/cmd/testdata/custom_and_external/resources_output/resource_resource_gen.go index af7679f0..71bb0df4 100644 --- a/internal/cmd/testdata/custom_and_external/resources_output/resource_resource_gen.go +++ b/internal/cmd/testdata/custom_and_external/resources_output/resource_resource_gen.go @@ -526,10 +526,16 @@ func FromListNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apis ), diags } - var tfModels []ListNestedAttributeAssocExtTypeModel + var tfModels []*ListNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -627,10 +633,16 @@ func FromMapNestedAttributeAssocExtType(ctx context.Context, apiObjects map[stri ), diags } - tfModels := make(map[string]MapNestedAttributeAssocExtTypeModel) + tfModels := make(map[string]*MapNestedAttributeAssocExtTypeModel) for k, apiObject := range apiObjects { - tfModels[k] = MapNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels[k] = nil + + continue + } + + tfModels[k] = &MapNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -728,10 +740,16 @@ func FromSetNestedAttributeAssocExtType(ctx context.Context, apiObjects []*apisd ), diags } - var tfModels []SetNestedAttributeAssocExtTypeModel + var tfModels []*SetNestedAttributeAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedAttributeAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedAttributeAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -881,10 +899,16 @@ func FromListNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.T ), diags } - var tfModels []ListNestedBlockAssocExtTypeModel + var tfModels []*ListNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, ListNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &ListNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), @@ -982,10 +1006,16 @@ func FromSetNestedBlockAssocExtType(ctx context.Context, apiObjects []*apisdk.Ty ), diags } - var tfModels []SetNestedBlockAssocExtTypeModel + var tfModels []*SetNestedBlockAssocExtTypeModel for _, apiObject := range apiObjects { - tfModels = append(tfModels, SetNestedBlockAssocExtTypeModel{ + if apiObject == nil { + tfModels = append(tfModels, nil) + + continue + } + + tfModels = append(tfModels, &SetNestedBlockAssocExtTypeModel{ BoolAttribute: types.BoolPointerValue(apiObject.BoolAttribute), Float64Attribute: types.Float64PointerValue(apiObject.Float64Attribute), Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute), diff --git a/internal/templates/list_nested_object_to_from.gotmpl b/internal/templates/list_nested_object_to_from.gotmpl index 06cc0fe3..9cacba18 100644 --- a/internal/templates/list_nested_object_to_from.gotmpl +++ b/internal/templates/list_nested_object_to_from.gotmpl @@ -83,10 +83,16 @@ tfModel.ObjectType(ctx), ), diags } -var tfModels []{{.Name}}Model +var tfModels []*{{.Name}}Model for _, apiObject := range apiObjects { -tfModels = append(tfModels, {{.Name}}Model{ +if apiObject == nil { +tfModels = append(tfModels, nil) + +continue +} + +tfModels = append(tfModels, &{{.Name}}Model{ {{- range $field := .Fields }} {{$field.Name}}: types.{{$field.DefaultFrom}}(apiObject.{{$field.Name}}), {{- end}} diff --git a/internal/templates/map_nested_object_to_from.gotmpl b/internal/templates/map_nested_object_to_from.gotmpl index 865b83d4..a1d3c0ab 100644 --- a/internal/templates/map_nested_object_to_from.gotmpl +++ b/internal/templates/map_nested_object_to_from.gotmpl @@ -83,10 +83,16 @@ tfModel.ObjectType(ctx), ), diags } -tfModels := make(map[string]{{.Name}}Model) +tfModels := make(map[string]*{{.Name}}Model) for k, apiObject := range apiObjects { -tfModels[k] = {{.Name}}Model{ +if apiObject == nil { +tfModels[k] = nil + +continue +} + +tfModels[k] = &{{.Name}}Model{ {{- range $field := .Fields }} {{$field.Name}}: types.{{$field.DefaultFrom}}(apiObject.{{$field.Name}}), {{- end}} diff --git a/internal/templates/set_nested_object_to_from.gotmpl b/internal/templates/set_nested_object_to_from.gotmpl index 400805bd..00881a07 100644 --- a/internal/templates/set_nested_object_to_from.gotmpl +++ b/internal/templates/set_nested_object_to_from.gotmpl @@ -83,10 +83,16 @@ tfModel.ObjectType(ctx), ), diags } -var tfModels []{{.Name}}Model +var tfModels []*{{.Name}}Model for _, apiObject := range apiObjects { -tfModels = append(tfModels, {{.Name}}Model{ +if apiObject == nil { +tfModels = append(tfModels, nil) + +continue +} + +tfModels = append(tfModels, &{{.Name}}Model{ {{- range $field := .Fields }} {{$field.Name}}: types.{{$field.DefaultFrom}}(apiObject.{{$field.Name}}), {{- end}}