From 6e206f9f26bf2a1880386e92c9eb78ae62293ea3 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Fri, 3 Jan 2025 11:28:37 +0100 Subject: [PATCH] call ApplySchemaCustomizations even if no customizeSchema is passed in --- .../products/library/resource_library.go | 1 + .../resource_quality_monitor.go | 1 + .../pluginfw/tfschema/struct_to_schema.go | 26 +++++++++++-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/internal/providers/pluginfw/products/library/resource_library.go b/internal/providers/pluginfw/products/library/resource_library.go index 856ee32f96..89af2516ca 100644 --- a/internal/providers/pluginfw/products/library/resource_library.go +++ b/internal/providers/pluginfw/products/library/resource_library.go @@ -103,6 +103,7 @@ func (r *LibraryResource) Schema(ctx context.Context, req resource.SchemaRequest c.AddPlanModifier(listplanmodifier.RequiresReplace(), field) } } + c.SetComputed("id") return c }) resp.Schema = schema.Schema{ diff --git a/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go b/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go index 8c42c09830..ef3c435b59 100644 --- a/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go +++ b/internal/providers/pluginfw/products/qualitymonitor/resource_quality_monitor.go @@ -87,6 +87,7 @@ func (r *QualityMonitorResource) Schema(ctx context.Context, req resource.Schema c.SetReadOnly("status") c.SetReadOnly("dashboard_id") c.SetReadOnly("schedule", "pause_status") + c.SetComputed("id") return c }) resp.Schema = schema.Schema{ diff --git a/internal/providers/pluginfw/tfschema/struct_to_schema.go b/internal/providers/pluginfw/tfschema/struct_to_schema.go index 08f51e49bc..f3a80976cf 100644 --- a/internal/providers/pluginfw/tfschema/struct_to_schema.go +++ b/internal/providers/pluginfw/tfschema/struct_to_schema.go @@ -195,27 +195,31 @@ func DataSourceStructToSchema(ctx context.Context, v any, customizeSchema func(C // ResourceStructToSchemaMap returns two maps from string to resource schema attributes and blocks using a tfsdk struct, with custoimzations applied. func ResourceStructToSchemaMap(ctx context.Context, v any, customizeSchema func(CustomizableSchema) CustomizableSchema) (map[string]schema.Attribute, map[string]schema.Block) { nestedBlockObj := typeToSchema(ctx, reflect.ValueOf(v)) + cs := *ConstructCustomizableSchema(nestedBlockObj) + + if schemaProvider, ok := v.(CustomizableSchemaProvider); ok { + cs = schemaProvider.ApplySchemaCustomizations(cs) + } if customizeSchema != nil { - cs := *ConstructCustomizableSchema(nestedBlockObj) - if schemaProvider, ok := v.(CustomizableSchemaProvider); ok { - cs = schemaProvider.ApplySchemaCustomizations(cs) - } cs = customizeSchema(cs) - return BuildResourceAttributeMap(cs.ToNestedBlockObject().Attributes), BuildResourceBlockMap(cs.ToNestedBlockObject().Blocks) - } else { - return BuildResourceAttributeMap(nestedBlockObj.Attributes), BuildResourceBlockMap(nestedBlockObj.Blocks) } + + return BuildResourceAttributeMap(cs.ToNestedBlockObject().Attributes), BuildResourceBlockMap(cs.ToNestedBlockObject().Blocks) } // DataSourceStructToSchemaMap returns twp maps from string to data source schema attributes and blocks using a tfsdk struct, with custoimzations applied. func DataSourceStructToSchemaMap(ctx context.Context, v any, customizeSchema func(CustomizableSchema) CustomizableSchema) (map[string]dataschema.Attribute, map[string]dataschema.Block) { nestedBlockObj := typeToSchema(ctx, reflect.ValueOf(v)) + cs := *ConstructCustomizableSchema(nestedBlockObj) + + if schemaProvider, ok := v.(CustomizableSchemaProvider); ok { + cs = schemaProvider.ApplySchemaCustomizations(cs) + } if customizeSchema != nil { - cs := customizeSchema(*ConstructCustomizableSchema(nestedBlockObj)) - return BuildDataSourceAttributeMap(cs.ToNestedBlockObject().Attributes), BuildDataSourceBlockMap(cs.ToNestedBlockObject().Blocks) - } else { - return BuildDataSourceAttributeMap(nestedBlockObj.Attributes), BuildDataSourceBlockMap(nestedBlockObj.Blocks) + cs = customizeSchema(cs) } + + return BuildDataSourceAttributeMap(cs.ToNestedBlockObject().Attributes), BuildDataSourceBlockMap(cs.ToNestedBlockObject().Blocks) }