Skip to content

Commit b3fad33

Browse files
committed
Rename customtype package to customtypes
1 parent b5bcfe3 commit b3fad33

File tree

23 files changed

+284
-258
lines changed

23 files changed

+284
-258
lines changed

internal/common/autogen/customtype/nested_list.go renamed to internal/common/autogen/customtypes/nested_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package customtype
1+
package customtypes
22

33
import (
44
"context"
@@ -19,7 +19,7 @@ import (
1919
- Schema definition:
2020
"sample_nested_object_list": schema.ListNestedAttribute{
2121
...
22-
CustomType: customtype.NewNestedListType[TFSampleNestedObjectModel](ctx),
22+
CustomType: customtypes.NewNestedListType[TFSampleNestedObjectModel](ctx),
2323
NestedObject: schema.NestedAttributeObject{
2424
Attributes: map[string]schema.Attribute{
2525
"string_attribute": schema.StringAttribute{...},
@@ -29,7 +29,7 @@ import (
2929
3030
- TF Models:
3131
type TFModel struct {
32-
SampleNestedObjectList customtype.NestedListValue[TFSampleNestedObjectModel] `tfsdk:"sample_nested_object_list"`
32+
SampleNestedObjectList customtypes.NestedListValue[TFSampleNestedObjectModel] `tfsdk:"sample_nested_object_list"`
3333
...
3434
}
3535

internal/common/autogen/customtype/object.go renamed to internal/common/autogen/customtypes/object.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package customtype
1+
package customtypes
22

33
import (
44
"context"
@@ -19,15 +19,15 @@ import (
1919
- Schema definition:
2020
"sample_nested_object": schema.SingleNestedAttribute{
2121
...
22-
CustomType: customtype.NewObjectType[TFSampleNestedObjectModel](ctx),
22+
CustomType: customtypes.NewObjectType[TFSampleNestedObjectModel](ctx),
2323
Attributes: map[string]schema.Attribute{
2424
"string_attribute": schema.StringAttribute{...},
2525
},
2626
}
2727
2828
- TF Models:
2929
type TFModel struct {
30-
SampleNestedObject customtype.ObjectValue[TFSampleNestedObjectModel] `tfsdk:"sample_nested_object"`
30+
SampleNestedObject customtypes.ObjectValue[TFSampleNestedObjectModel] `tfsdk:"sample_nested_object"`
3131
...
3232
}
3333

internal/common/autogen/marshal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1010
"github.com/hashicorp/terraform-plugin-framework/attr"
1111
"github.com/hashicorp/terraform-plugin-framework/types"
12-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtype"
12+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtypes"
1313
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/stringcase"
1414
)
1515

@@ -77,7 +77,7 @@ func marshalAttr(attrNameModel string, attrValModel reflect.Value, objJSON map[s
7777

7878
if val == nil && isUpdate {
7979
switch obj.(type) {
80-
case types.List, types.Set, customtype.NestedListValueInterface:
80+
case types.List, types.Set, customtypes.NestedListValueInterface:
8181
val = []any{} // Send an empty array if it's a null root list or set
8282
}
8383
}
@@ -115,15 +115,15 @@ func getModelAttr(val attr.Value, isUpdate bool) (any, error) {
115115
return nil, fmt.Errorf("marshal failed for JSON custom type: %v", err)
116116
}
117117
return valueJSON, nil
118-
case customtype.ObjectValueInterface:
118+
case customtypes.ObjectValueInterface:
119119
valuePtr, diags := v.ValuePtrAsAny(context.Background())
120120
if diags.HasError() {
121121
return nil, fmt.Errorf("marshal failed for type: %v", diags)
122122
}
123123

124124
result, err := marshalAttrs(reflect.ValueOf(valuePtr).Elem(), isUpdate)
125125
return result, err
126-
case customtype.NestedListValueInterface:
126+
case customtypes.NestedListValueInterface:
127127
slicePtr, diags := v.SlicePtrAsAny(context.Background())
128128
if diags.HasError() {
129129
return nil, fmt.Errorf("marshal failed for type: %v", diags)

internal/common/autogen/marshal_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/attr"
99
"github.com/hashicorp/terraform-plugin-framework/types"
1010
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen"
11-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtype"
11+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtypes"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
1414
)
@@ -302,39 +302,39 @@ func TestMarshalCustomTypeObject(t *testing.T) {
302302
type modelEmptyTest struct{}
303303

304304
type modelCustomTypeTest struct {
305-
AttrPrimitiveOmit types.String `tfsdk:"attr_primitive_omit" autogen:"omitjson"`
306-
AttrObjectOmit customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_object_omit" autogen:"omitjson"`
307-
AttrObjectOmitUpdate customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_object_omit_update" autogen:"omitjsonupdate"`
308-
AttrNull customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_null" autogen:"includenullonupdate"`
309-
AttrInt types.Int64 `tfsdk:"attr_int"`
310-
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
305+
AttrPrimitiveOmit types.String `tfsdk:"attr_primitive_omit" autogen:"omitjson"`
306+
AttrObjectOmit customtypes.ObjectValue[modelEmptyTest] `tfsdk:"attr_object_omit" autogen:"omitjson"`
307+
AttrObjectOmitUpdate customtypes.ObjectValue[modelEmptyTest] `tfsdk:"attr_object_omit_update" autogen:"omitjsonupdate"`
308+
AttrNull customtypes.ObjectValue[modelEmptyTest] `tfsdk:"attr_null" autogen:"includenullonupdate"`
309+
AttrInt types.Int64 `tfsdk:"attr_int"`
310+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
311311
}
312312

313313
type modelCustomTypeParentTest struct {
314-
AttrString types.String `tfsdk:"attr_string"`
315-
AttrObject customtype.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_object"`
314+
AttrString types.String `tfsdk:"attr_string"`
315+
AttrObject customtypes.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_object"`
316316
}
317317

318-
nullObject := customtype.NewObjectValueNull[modelEmptyTest](ctx)
319-
emptyObject := customtype.NewObjectValue[modelEmptyTest](ctx, modelEmptyTest{})
318+
nullObject := customtypes.NewObjectValueNull[modelEmptyTest](ctx)
319+
emptyObject := customtypes.NewObjectValue[modelEmptyTest](ctx, modelEmptyTest{})
320320

321321
model := struct {
322-
AttrObjectBasic customtype.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_object_basic"`
323-
AttrObjectNull customtype.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_object_null"`
324-
AttrObjectNested customtype.ObjectValue[modelCustomTypeParentTest] `tfsdk:"attr_object_nested"`
322+
AttrObjectBasic customtypes.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_object_basic"`
323+
AttrObjectNull customtypes.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_object_null"`
324+
AttrObjectNested customtypes.ObjectValue[modelCustomTypeParentTest] `tfsdk:"attr_object_nested"`
325325
}{
326-
AttrObjectBasic: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
326+
AttrObjectBasic: customtypes.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
327327
AttrInt: types.Int64Value(1),
328328
AttrPrimitiveOmit: types.StringValue("omitted"),
329329
AttrObjectOmit: emptyObject,
330330
AttrObjectOmitUpdate: emptyObject,
331331
AttrNull: nullObject,
332332
AttrMANYUpper: types.Int64Value(2),
333333
}),
334-
AttrObjectNull: customtype.NewObjectValueNull[modelCustomTypeTest](ctx),
335-
AttrObjectNested: customtype.NewObjectValue[modelCustomTypeParentTest](ctx, modelCustomTypeParentTest{
334+
AttrObjectNull: customtypes.NewObjectValueNull[modelCustomTypeTest](ctx),
335+
AttrObjectNested: customtypes.NewObjectValue[modelCustomTypeParentTest](ctx, modelCustomTypeParentTest{
336336
AttrString: types.StringValue("parent"),
337-
AttrObject: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
337+
AttrObject: customtypes.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
338338
AttrInt: types.Int64Value(2),
339339
AttrPrimitiveOmit: types.StringValue("omitted"),
340340
AttrObjectOmit: emptyObject,
@@ -398,40 +398,40 @@ func TestMarshalCustomTypeNestedList(t *testing.T) {
398398
}
399399

400400
type modelNestedListItem struct {
401-
AttrOmit customtype.NestedListValue[modelEmptyTest] `tfsdk:"attr_omit" autogen:"omitjson"`
402-
AttrOmitUpdate customtype.NestedListValue[modelEmptyTest] `tfsdk:"attr_omit_update" autogen:"omitjsonupdate"`
403-
AttrPrimitive types.String `tfsdk:"attr_primitive"`
404-
AttrObject customtype.ObjectValue[modelNestedObject] `tfsdk:"attr_object"`
405-
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
401+
AttrOmit customtypes.NestedListValue[modelEmptyTest] `tfsdk:"attr_omit" autogen:"omitjson"`
402+
AttrOmitUpdate customtypes.NestedListValue[modelEmptyTest] `tfsdk:"attr_omit_update" autogen:"omitjsonupdate"`
403+
AttrPrimitive types.String `tfsdk:"attr_primitive"`
404+
AttrObject customtypes.ObjectValue[modelNestedObject] `tfsdk:"attr_object"`
405+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
406406
}
407407

408408
model := struct {
409-
AttrNestedList customtype.NestedListValue[modelNestedListItem] `tfsdk:"attr_nested_list"`
410-
AttrNestedListNull customtype.NestedListValue[modelNestedListItem] `tfsdk:"attr_nested_list_null"`
411-
AttrNestedListEmpty customtype.NestedListValue[modelNestedListItem] `tfsdk:"attr_nested_list_empty"`
409+
AttrNestedList customtypes.NestedListValue[modelNestedListItem] `tfsdk:"attr_nested_list"`
410+
AttrNestedListNull customtypes.NestedListValue[modelNestedListItem] `tfsdk:"attr_nested_list_null"`
411+
AttrNestedListEmpty customtypes.NestedListValue[modelNestedListItem] `tfsdk:"attr_nested_list_empty"`
412412
}{
413-
AttrNestedList: customtype.NewNestedListValue[modelNestedListItem](ctx, []modelNestedListItem{
413+
AttrNestedList: customtypes.NewNestedListValue[modelNestedListItem](ctx, []modelNestedListItem{
414414
{
415415
AttrPrimitive: types.StringValue("string1"),
416416
AttrMANYUpper: types.Int64Value(1),
417-
AttrObject: customtype.NewObjectValue[modelNestedObject](ctx, modelNestedObject{
417+
AttrObject: customtypes.NewObjectValue[modelNestedObject](ctx, modelNestedObject{
418418
AttrNestedInt: types.Int64Value(2),
419419
}),
420-
AttrOmit: customtype.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
421-
AttrOmitUpdate: customtype.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
420+
AttrOmit: customtypes.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
421+
AttrOmitUpdate: customtypes.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
422422
},
423423
{
424424
AttrPrimitive: types.StringValue("string2"),
425425
AttrMANYUpper: types.Int64Value(3),
426-
AttrObject: customtype.NewObjectValue[modelNestedObject](ctx, modelNestedObject{
426+
AttrObject: customtypes.NewObjectValue[modelNestedObject](ctx, modelNestedObject{
427427
AttrNestedInt: types.Int64Value(4),
428428
}),
429-
AttrOmit: customtype.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
430-
AttrOmitUpdate: customtype.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
429+
AttrOmit: customtypes.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
430+
AttrOmitUpdate: customtypes.NewNestedListValue[modelEmptyTest](ctx, []modelEmptyTest{}),
431431
},
432432
}),
433-
AttrNestedListNull: customtype.NewNestedListValueNull[modelNestedListItem](ctx),
434-
AttrNestedListEmpty: customtype.NewNestedListValue[modelNestedListItem](ctx, []modelNestedListItem{}),
433+
AttrNestedListNull: customtypes.NewNestedListValueNull[modelNestedListItem](ctx),
434+
AttrNestedListEmpty: customtypes.NewNestedListValue[modelNestedListItem](ctx, []modelNestedListItem{}),
435435
}
436436

437437
const expectedCreateJSON = `

internal/common/autogen/unknown.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
99
"github.com/hashicorp/terraform-plugin-framework/attr"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
11-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtype"
11+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtypes"
1212
)
1313

1414
// ResolveUnknowns converts unknown attributes to null.
@@ -43,7 +43,7 @@ func prepareAttr(value attr.Value) (attr.Value, error) {
4343
ctx := context.Background()
4444

4545
switch v := value.(type) {
46-
case customtype.ObjectValueInterface:
46+
case customtypes.ObjectValueInterface:
4747
if v.IsUnknown() {
4848
return v.NewObjectValueNull(ctx), nil
4949
}
@@ -60,7 +60,7 @@ func prepareAttr(value attr.Value) (attr.Value, error) {
6060

6161
objNew := v.NewObjectValue(ctx, valuePtr)
6262
return objNew, nil
63-
case customtype.NestedListValueInterface:
63+
case customtypes.NestedListValueInterface:
6464
if v.IsUnknown() {
6565
return v.NewNestedListValueNull(ctx), nil
6666
}

internal/common/autogen/unknown_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/types"
99
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen"
10-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtype"
10+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtypes"
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313
)
@@ -18,23 +18,23 @@ func TestResolveUnknowns(t *testing.T) {
1818
type modelEmptyTest struct{}
1919

2020
type modelCustomTypeTest struct {
21-
AttrKnownString types.String `tfsdk:"attr_known_string"`
22-
AttrUnknownObject customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_unknown_object"`
23-
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
21+
AttrKnownString types.String `tfsdk:"attr_known_string"`
22+
AttrUnknownObject customtypes.ObjectValue[modelEmptyTest] `tfsdk:"attr_unknown_object"`
23+
AttrMANYUpper types.Int64 `tfsdk:"attr_many_upper"`
2424
}
2525

2626
type modelst struct {
27-
AttrStringUnknown types.String `tfsdk:"attr_string_unknown"`
28-
AttrObjectUnknown types.Object `tfsdk:"attr_object_unknown"`
29-
AttrListUnknown types.List `tfsdk:"attr_list_unknown"`
30-
AttrObject types.Object `tfsdk:"attr_object"`
31-
AttrListString types.List `tfsdk:"attr_list_string"`
32-
AttrSetString types.Set `tfsdk:"attr_set_string"`
33-
AttrListObjObj types.List `tfsdk:"attr_list_obj_obj"`
34-
AttrMapUnknown types.Map `tfsdk:"attr_map_unknown"`
35-
AttrCustomObjectUnknown customtype.ObjectValue[modelEmptyTest] `tfsdk:"attr_custom_object_unknown"`
36-
AttrCustomObject customtype.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_custom_object"`
37-
AttrCustomNestedListUnknown customtype.NestedListValue[modelEmptyTest] `tfsdk:"attr_custom_nested_list_unknown"`
27+
AttrStringUnknown types.String `tfsdk:"attr_string_unknown"`
28+
AttrObjectUnknown types.Object `tfsdk:"attr_object_unknown"`
29+
AttrListUnknown types.List `tfsdk:"attr_list_unknown"`
30+
AttrObject types.Object `tfsdk:"attr_object"`
31+
AttrListString types.List `tfsdk:"attr_list_string"`
32+
AttrSetString types.Set `tfsdk:"attr_set_string"`
33+
AttrListObjObj types.List `tfsdk:"attr_list_obj_obj"`
34+
AttrMapUnknown types.Map `tfsdk:"attr_map_unknown"`
35+
AttrCustomObjectUnknown customtypes.ObjectValue[modelEmptyTest] `tfsdk:"attr_custom_object_unknown"`
36+
AttrCustomObject customtypes.ObjectValue[modelCustomTypeTest] `tfsdk:"attr_custom_object"`
37+
AttrCustomNestedListUnknown customtypes.NestedListValue[modelEmptyTest] `tfsdk:"attr_custom_nested_list_unknown"`
3838
}
3939

4040
model := modelst{
@@ -81,13 +81,13 @@ func TestResolveUnknowns(t *testing.T) {
8181
types.ObjectUnknown(objTypeParentTest.AttributeTypes()),
8282
}),
8383
AttrMapUnknown: types.MapUnknown(types.StringType),
84-
AttrCustomObjectUnknown: customtype.NewObjectValueUnknown[modelEmptyTest](ctx),
85-
AttrCustomObject: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
84+
AttrCustomObjectUnknown: customtypes.NewObjectValueUnknown[modelEmptyTest](ctx),
85+
AttrCustomObject: customtypes.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
8686
AttrKnownString: types.StringValue("val1"),
87-
AttrUnknownObject: customtype.NewObjectValueUnknown[modelEmptyTest](ctx),
87+
AttrUnknownObject: customtypes.NewObjectValueUnknown[modelEmptyTest](ctx),
8888
AttrMANYUpper: types.Int64Unknown(),
8989
}),
90-
AttrCustomNestedListUnknown: customtype.NewNestedListValueUnknown[modelEmptyTest](ctx),
90+
AttrCustomNestedListUnknown: customtypes.NewNestedListValueUnknown[modelEmptyTest](ctx),
9191
}
9292
modelExpected := modelst{
9393
AttrStringUnknown: types.StringNull(),
@@ -133,13 +133,13 @@ func TestResolveUnknowns(t *testing.T) {
133133
types.ObjectNull(objTypeParentTest.AttributeTypes()),
134134
}),
135135
AttrMapUnknown: types.MapNull(types.StringType),
136-
AttrCustomObjectUnknown: customtype.NewObjectValueNull[modelEmptyTest](ctx),
137-
AttrCustomObject: customtype.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
136+
AttrCustomObjectUnknown: customtypes.NewObjectValueNull[modelEmptyTest](ctx),
137+
AttrCustomObject: customtypes.NewObjectValue[modelCustomTypeTest](ctx, modelCustomTypeTest{
138138
AttrKnownString: types.StringValue("val1"),
139-
AttrUnknownObject: customtype.NewObjectValueNull[modelEmptyTest](ctx),
139+
AttrUnknownObject: customtypes.NewObjectValueNull[modelEmptyTest](ctx),
140140
AttrMANYUpper: types.Int64Null(),
141141
}),
142-
AttrCustomNestedListUnknown: customtype.NewNestedListValueNull[modelEmptyTest](ctx),
142+
AttrCustomNestedListUnknown: customtypes.NewNestedListValueNull[modelEmptyTest](ctx),
143143
}
144144
require.NoError(t, autogen.ResolveUnknowns(&model))
145145
assert.Equal(t, modelExpected, model)

internal/common/autogen/unmarshal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1111
"github.com/hashicorp/terraform-plugin-framework/attr"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
13-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtype"
13+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/customtypes"
1414
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen/stringcase"
1515
)
1616

@@ -135,7 +135,7 @@ func getTfAttr(value any, valueType attr.Type, oldVal attr.Value, name string) (
135135
}
136136
return mapNew, nil
137137
}
138-
if obj, ok := oldVal.(customtype.ObjectValueInterface); ok {
138+
if obj, ok := oldVal.(customtypes.ObjectValueInterface); ok {
139139
ctx := context.Background()
140140
valuePtr, diags := obj.ValuePtrAsAny(ctx)
141141
if diags.HasError() {
@@ -173,7 +173,7 @@ func getTfAttr(value any, valueType attr.Type, oldVal attr.Value, name string) (
173173
}
174174
return setNew, nil
175175
}
176-
if list, ok := oldVal.(customtype.NestedListValueInterface); ok {
176+
if list, ok := oldVal.(customtypes.NestedListValueInterface); ok {
177177
if len(v) == 0 && list.Len() == 0 {
178178
// Keep current list if both model and JSON lists are zero-len (empty or null) so config is preserved.
179179
// It avoids inconsistent result after apply when user explicitly sets an empty list in config.

0 commit comments

Comments
 (0)