From 10c456e6c0aef33b04d76d810fe3645bfb01bd74 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Thu, 12 Dec 2024 11:56:15 +0100 Subject: [PATCH] rename --- CONTRIBUTING.md | 4 ++-- .../products/library/resource_library.go | 2 +- .../qualitymonitor/resource_quality_monitor.go | 2 +- .../pluginfw/products/sharing/resource_share.go | 2 +- .../pluginfw/tfschema/customizable_schema.go | 4 ++-- .../tfschema/customizable_schema_test.go | 16 ++++++++-------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f32958dbe..54f584a1e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 }) diff --git a/internal/providers/pluginfw/products/library/resource_library.go b/internal/providers/pluginfw/products/library/resource_library.go index ba7442927..f7b3854a5 100644 --- a/internal/providers/pluginfw/products/library/resource_library.go +++ b/internal/providers/pluginfw/products/library/resource_library.go @@ -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: diff --git a/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go b/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go index d4e0248f6..574bb72e3 100644 --- a/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go +++ b/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go @@ -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") diff --git a/internal/providers/pluginfw/products/sharing/resource_share.go b/internal/providers/pluginfw/products/sharing/resource_share.go index 61219eda8..17c10137a 100644 --- a/internal/providers/pluginfw/products/sharing/resource_share.go +++ b/internal/providers/pluginfw/products/sharing/resource_share.go @@ -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 diff --git a/internal/providers/pluginfw/tfschema/customizable_schema.go b/internal/providers/pluginfw/tfschema/customizable_schema.go index 558bc2220..217bfa888 100644 --- a/internal/providers/pluginfw/tfschema/customizable_schema.go +++ b/internal/providers/pluginfw/tfschema/customizable_schema.go @@ -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 diff --git a/internal/providers/pluginfw/tfschema/customizable_schema_test.go b/internal/providers/pluginfw/tfschema/customizable_schema_test.go index 1dfec1772..c2d691da4 100644 --- a/internal/providers/pluginfw/tfschema/customizable_schema_test.go +++ b/internal/providers/pluginfw/tfschema/customizable_schema_test.go @@ -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 }) @@ -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 }) @@ -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 }) @@ -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 }) @@ -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 }) @@ -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 { @@ -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) } })