Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht committed Dec 12, 2024
1 parent fc9e4c8 commit 10c456e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ There must not be any behaviour change or schema change when migrating a resourc
- Please make sure there are no breaking differences due to changes in schema by running: `make diff-schema`.
- Integration tests shouldn't require any major changes.
By default, `ResourceStructToSchema` will convert a `types.List` field to a `ListAttribute` or `ListNestedAttribute`. For resources or data sources migrated from the SDKv2, `ListNestedBlock` must be used for such fields. To do this, call `cs.ConfigureForSdkV2Migration()` in the `ResourceStructToSchema` callback:
By default, `ResourceStructToSchema` will convert a `types.List` field to a `ListAttribute` or `ListNestedAttribute`. For resources or data sources migrated from the SDKv2, `ListNestedBlock` must be used for such fields. To do this, call `cs.ConfigureAsSdkV2Compatible()` in the `ResourceStructToSchema` callback:
```go
resp.Schema = tfschema.ResourceStructToSchema(ctx, Resource{}, func(c tfschema.CustomizableSchema) tfschema.CustomizableSchema {
cs.ConfigureForSdkV2Migration()
cs.ConfigureAsSdkV2Compatible()
// Add any additional configuration here
return cs
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *LibraryResource) Metadata(ctx context.Context, req resource.MetadataReq

func (r *LibraryResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
attrs, blocks := tfschema.ResourceStructToSchemaMap(ctx, LibraryExtended{}, func(c tfschema.CustomizableSchema) tfschema.CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
for field, attribute := range c.ToNestedBlockObject().Attributes {
switch attribute.(type) {
case tfschema.StringAttributeBuilder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *QualityMonitorResource) Metadata(ctx context.Context, req resource.Meta

func (r *QualityMonitorResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
attrs, blocks := tfschema.ResourceStructToSchemaMap(ctx, MonitorInfoExtended{}, func(c tfschema.CustomizableSchema) tfschema.CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetRequired("assets_dir")
c.SetRequired("output_schema_name")
c.SetReadOnly("monitor_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *ShareResource) Metadata(ctx context.Context, req resource.MetadataReque

func (r *ShareResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
attrs, blocks := tfschema.ResourceStructToSchemaMap(ctx, ShareInfoExtended{}, func(c tfschema.CustomizableSchema) tfschema.CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetRequired("name")

c.AddPlanModifier(stringplanmodifier.RequiresReplace(), "name") // ForceNew
Expand Down
4 changes: 2 additions & 2 deletions internal/providers/pluginfw/tfschema/customizable_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func (s *CustomizableSchema) SetReadOnly(path ...string) *CustomizableSchema {
return s
}

// ConfigureForSdkV2Migration modifies the underlying schema to be compatible with SDKv2. This method must
// ConfigureAsSdkV2Compatible modifies the underlying schema to be compatible with SDKv2. This method must
// be called on all resources that were originally implemented using the SDKv2 and are migrated to the plugin
// framework.
func (s *CustomizableSchema) ConfigureForSdkV2Migration() *CustomizableSchema {
func (s *CustomizableSchema) ConfigureAsSdkV2Compatible() *CustomizableSchema {
nbo := s.attr.(SingleNestedBlockBuilder).NestedObject
s.attr = SingleNestedBlockBuilder{NestedObject: convertAttributesToBlocks(nbo.Attributes, nbo.Blocks)}
return s
Expand Down
16 changes: 8 additions & 8 deletions internal/providers/pluginfw/tfschema/customizable_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestCustomizeSchemaObjectTypeValidatorAdded(t *testing.T) {
func TestCustomizeSchema_SetRequired_PanicOnBlock(t *testing.T) {
assert.Panics(t, func() {
_ = ResourceStructToSchema(context.Background(), TestTfSdk{}, func(c CustomizableSchema) CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetRequired("nested")
return c
})
Expand All @@ -176,7 +176,7 @@ func TestCustomizeSchema_SetRequired_PanicOnBlock(t *testing.T) {
func TestCustomizeSchema_SetOptional_PanicOnBlock(t *testing.T) {
assert.Panics(t, func() {
_ = ResourceStructToSchema(context.Background(), TestTfSdk{}, func(c CustomizableSchema) CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetOptional("nested")
return c
})
Expand All @@ -186,7 +186,7 @@ func TestCustomizeSchema_SetOptional_PanicOnBlock(t *testing.T) {
func TestCustomizeSchema_SetSensitive_PanicOnBlock(t *testing.T) {
assert.Panics(t, func() {
_ = ResourceStructToSchema(context.Background(), TestTfSdk{}, func(c CustomizableSchema) CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetSensitive("nested")
return c
})
Expand All @@ -196,7 +196,7 @@ func TestCustomizeSchema_SetSensitive_PanicOnBlock(t *testing.T) {
func TestCustomizeSchema_SetReadOnly_PanicOnBlock(t *testing.T) {
assert.Panics(t, func() {
_ = ResourceStructToSchema(context.Background(), TestTfSdk{}, func(c CustomizableSchema) CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetReadOnly("nested")
return c
})
Expand All @@ -206,7 +206,7 @@ func TestCustomizeSchema_SetReadOnly_PanicOnBlock(t *testing.T) {
func TestCustomizeSchema_SetComputed_PanicOnBlock(t *testing.T) {
assert.Panics(t, func() {
_ = ResourceStructToSchema(context.Background(), TestTfSdk{}, func(c CustomizableSchema) CustomizableSchema {
c.ConfigureForSdkV2Migration()
c.ConfigureAsSdkV2Compatible()
c.SetComputed("nested")
return c
})
Expand Down Expand Up @@ -263,7 +263,7 @@ func (m mockValidator) ValidateObject(context.Context, validator.ObjectRequest,
var _ validator.List = mockValidator{}
var _ validator.Object = mockValidator{}

func TestCustomizeSchema_ConfigureForSdkV2Migration(t *testing.T) {
func TestCustomizeSchema_ConfigureAsSdkV2Compatible(t *testing.T) {
v := mockValidator{}
pm := mockPlanModifier{}
testCases := []struct {
Expand Down Expand Up @@ -361,10 +361,10 @@ func TestCustomizeSchema_ConfigureForSdkV2Migration(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
if c.expectPanic {
assert.Panics(t, func() {
ConstructCustomizableSchema(c.baseSchema).ConfigureForSdkV2Migration()
ConstructCustomizableSchema(c.baseSchema).ConfigureAsSdkV2Compatible()
})
} else {
got := ConstructCustomizableSchema(c.baseSchema).ConfigureForSdkV2Migration()
got := ConstructCustomizableSchema(c.baseSchema).ConfigureAsSdkV2Compatible()
assert.Equal(t, c.want, got.attr.(SingleNestedBlockBuilder).NestedObject)
}
})
Expand Down

0 comments on commit 10c456e

Please sign in to comment.