Skip to content

Commit

Permalink
call ApplySchemaCustomizations even if no customizeSchema is passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchy committed Jan 3, 2025
1 parent e2cec37 commit 59a31c6
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions internal/providers/pluginfw/tfschema/struct_to_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 59a31c6

Please sign in to comment.