Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmay-db committed Jul 29, 2024
1 parent 4f3b923 commit b35195c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
13 changes: 7 additions & 6 deletions common/reflect_resource_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,17 @@ func fieldIsOptional(field reflect.StructField) bool {
}

func PluginFrameworkResourceStructToSchema(v any, customizeSchema func(CustomizableSchemaPluginFramework) CustomizableSchemaPluginFramework) schema.Schema {
attributes := PluginFrameworkResourceStructToSchemaMap(v, customizeSchema)
return schema.Schema{Attributes: attributes}
}

func PluginFrameworkResourceStructToSchemaMap(v any, customizeSchema func(CustomizableSchemaPluginFramework) CustomizableSchemaPluginFramework) map[string]schema.Attribute {
attributes := pluginFrameworkResourceTypeToSchema(reflect.ValueOf(v))

if customizeSchema != nil {
cs := customizeSchema(*ConstructCustomizableSchema(attributes))
return schema.Schema{Attributes: cs.ToAttributeMap()}
return cs.ToAttributeMap()
} else {
return schema.Schema{Attributes: attributes}
return attributes
}
}

func PluginFrameworkResourceStructToSchemaMap(v any) map[string]schema.Attribute {
return pluginFrameworkResourceTypeToSchema(reflect.ValueOf(v))
}
17 changes: 15 additions & 2 deletions pluginframework/resource_quality_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,21 @@ func (r *QualityMonitorResource) Metadata(ctx context.Context, req resource.Meta
func (r *QualityMonitorResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Terraform schema for Databricks Lakehouse Monitor. MonitorInfo struct is used to create the schema",
// TODO: Add CustomizeSchemaPath once it is supported in the plugin framework
Attributes: common.PluginFrameworkResourceStructToSchemaMap(catalog_tf.MonitorInfo{}),
Attributes: common.PluginFrameworkResourceStructToSchemaMap(catalog_tf.MonitorInfo{}, func(c common.CustomizableSchemaPluginFramework) common.CustomizableSchemaPluginFramework {
c.AddNewField("skip_builtin_dashboard", schema.BoolAttribute{Optional: true, Required: false})
c.AddNewField("warehouse_id", schema.StringAttribute{Optional: true, Required: false})
c.SetRequired("assets_dir")
c.SetRequired("output_schema_name")
c.SetRequired("table_name")
// TODO: Uncomment this once SetReadOnly is supported in the plugin framework
// c.SetReadOnly("monitor_version")
// c.SetReadOnly("drift_metrics_table_name")
// c.SetReadOnly("profile_metrics_table_name")
// c.SetReadOnly("status")
// c.SetReadOnly("dashboard_id")
// c.SetReadOnly("schedule", "pause_status")
return c
}),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ resource "databricks_sql_table" "testtable" {
}
}

resource "databricks_lakehouse_monitor_pluginframework" "testmonitor" {
table_name = "${databricks_catalog.testcatalog.name}.${databricks_schema.testschema.name}.${databricks_sql_table.testtable.name}"
}
# TODO: Uncomment once SetReadOnly is supported in the plugin framework and add the necessary fields
# resource "databricks_lakehouse_monitor_pluginframework" "testmonitor" {
# table_name = "${databricks_catalog.testcatalog.name}.${databricks_schema.testschema.name}.${databricks_sql_table.testtable.name}"
# }

0 comments on commit b35195c

Please sign in to comment.