From db288d63f423c68407cdf59b4939d36886ebb24f Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Thu, 30 Oct 2025 16:48:30 +0530 Subject: [PATCH 1/3] [Internal] Unified Provider: All resources on Go SDK --- access/resource_ip_access_list.go | 13 ++-- catalog/resource_artifact_allowlist.go | 15 ++-- catalog/resource_catalog.go | 72 ++++++++++--------- catalog/resource_connection.go | 19 +++-- catalog/resource_credential.go | 19 +++-- catalog/resource_external_location.go | 13 ++-- catalog/resource_grant.go | 17 +++-- catalog/resource_grants.go | 11 ++- catalog/resource_online_table.go | 19 +++-- catalog/resource_quality_monitor.go | 21 ++++-- catalog/resource_registered_model.go | 21 ++++-- catalog/resource_schema.go | 13 ++-- catalog/resource_sql_table.go | 12 ++-- catalog/resource_system_schema.go | 17 +++-- catalog/resource_volume.go | 13 ++-- catalog/resource_workspace_binding.go | 17 +++-- common/client.go | 8 +-- dashboards/resource_dashboard.go | 8 +-- internal/providers/providers_test.go | 2 +- mlflow/resource_mlflow_experiment.go | 8 +-- mlflow/resource_mlflow_model.go | 8 +-- mlflow/resource_mlflow_webhook.go | 8 +-- permissions/permissions_test.go | 2 +- .../resource_access_control_rule_set.go | 4 +- permissions/resource_permissions.go | 2 +- pipelines/resource_pipeline.go | 8 +-- policies/resource_cluster_policy.go | 8 +-- repos/resource_git_credential.go | 8 +-- scim/data_current_user.go | 2 +- secrets/resource_secret.go | 6 +- secrets/resource_secret_acl.go | 6 +- secrets/resource_secret_scope.go | 6 +- serving/resource_model_serving.go | 8 +-- ...ce_model_serving_provisioned_throughput.go | 8 +-- settings/generic_setting.go | 12 ++-- settings/resource_notification_destination.go | 8 +-- sharing/resource_recipient.go | 8 +-- sharing/resource_share.go | 8 +-- sql/resource_alert.go | 8 +-- sql/resource_query.go | 8 +-- sql/resource_sql_alerts.go | 8 +-- sql/resource_sql_endpoint.go | 8 +-- storage/resource_file.go | 6 +- .../resource_vector_search_endpoint.go | 8 +-- vectorsearch/resource_vector_search_index.go | 6 +- workspace/resource_directory.go | 10 ++- workspace/resource_global_init_script.go | 14 ++-- workspace/resource_notebook.go | 2 +- workspace/resource_workspace_conf.go | 23 +++--- workspace/resource_workspace_file.go | 12 ++-- 50 files changed, 351 insertions(+), 220 deletions(-) diff --git a/access/resource_ip_access_list.go b/access/resource_ip_access_list.go index 5b899ffd7a..ba4401f446 100644 --- a/access/resource_ip_access_list.go +++ b/access/resource_ip_access_list.go @@ -15,6 +15,7 @@ type ipAccessListUpdateRequest struct { ListType settings.ListType `json:"list_type"` IpAddresses []string `json:"ip_addresses"` Enabled bool `json:"enabled,omitempty" tf:"default:true"` + common.Namespace } // ResourceIPAccessList manages IP access lists @@ -26,12 +27,13 @@ func ResourceIPAccessList() common.Resource { Type: schema.TypeString, ValidateFunc: validation.Any(validation.IsIPv4Address, validation.IsCIDR), } + common.NamespaceCustomizeSchemaMap(s) return s }) return common.Resource{ Schema: s, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -45,7 +47,7 @@ func ResourceIPAccessList() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -57,7 +59,7 @@ func ResourceIPAccessList() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -67,11 +69,14 @@ func ResourceIPAccessList() common.Resource { return w.IpAccessLists.Update(ctx, iacl) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return w.IpAccessLists.DeleteByIpAccessListId(ctx, d.Id()) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/catalog/resource_artifact_allowlist.go b/catalog/resource_artifact_allowlist.go index 9ce2e10467..3336d85a68 100644 --- a/catalog/resource_artifact_allowlist.go +++ b/catalog/resource_artifact_allowlist.go @@ -19,14 +19,18 @@ type ArtifactAllowlistInfo struct { CreatedBy string `json:"created_by,omitempty" tf:"computed"` // Unique identifier of parent metastore. MetastoreId string `json:"metastore_id,omitempty" tf:"computed"` + common.Namespace } func ResourceArtifactAllowlist() common.Resource { - allowlistSchema := common.StructToSchema(ArtifactAllowlistInfo{}, common.NoCustomize) + allowlistSchema := common.StructToSchema(ArtifactAllowlistInfo{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { + common.NamespaceCustomizeSchemaMap(s) + return s + }) p := common.NewPairID("metastore_id", "artifact_type") createOrUpdate := func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -53,9 +57,12 @@ func ResourceArtifactAllowlist() common.Resource { } return common.Resource{ Schema: allowlistSchema, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: createOrUpdate, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -82,7 +89,7 @@ func ResourceArtifactAllowlist() common.Resource { }, Update: createOrUpdate, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_catalog.go b/catalog/resource_catalog.go index db7f70cdc8..9445dedaf7 100644 --- a/catalog/resource_catalog.go +++ b/catalog/resource_catalog.go @@ -28,8 +28,13 @@ func ucDirectoryPathSlashAndEmptySuppressDiff(k, old, new string, d *schema.Reso return false } +type CatalogInfoResource struct { + catalog.CatalogInfo + common.Namespace +} + func ResourceCatalog() common.Resource { - catalogSchema := common.StructToSchema(catalog.CatalogInfo{}, + catalogSchema := common.StructToSchema(CatalogInfoResource{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { s["force_destroy"] = &schema.Schema{ Type: schema.TypeBool, @@ -58,12 +63,41 @@ func ResourceCatalog() common.Resource { common.CustomizeSchemaPath(s, v).SetReadOnly() } common.CustomizeSchemaPath(s, "effective_predictive_optimization_flag").SetComputed().SetSuppressDiff() + common.NamespaceCustomizeSchemaMap(s) return s }) return common.Resource{ Schema: catalogSchema, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + // The only scenario in which we can update options is for the `authorized_paths` key. Any + // other changes to the options field will result in an error. + if d.HasChange("options") { + old, new := d.GetChange("options") + oldMap := old.(map[string]interface{}) + newMap := new.(map[string]interface{}) + delete(oldMap, "authorized_paths") + delete(newMap, "authorized_paths") + // If any attribute other than `authorized_paths` is removed, the resource should be recreated. + for k := range oldMap { + if _, ok := newMap[k]; !ok { + if err := d.ForceNew("options"); err != nil { + return err + } + } + } + // If any attribute other than `authorized_paths` is added or changed, the resource should be recreated. + for k, v := range newMap { + if oldV, ok := oldMap[k]; !ok || oldV != v { + if err := d.ForceNew("options"); err != nil { + return err + } + } + } + } + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -107,7 +141,7 @@ func ResourceCatalog() common.Resource { return bindings.AddCurrentWorkspaceBindings(ctx, d, w, ci.Name, bindings.BindingsSecurableTypeCatalog) }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -119,7 +153,7 @@ func ResourceCatalog() common.Resource { return common.StructToData(ci, catalogSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -188,7 +222,7 @@ func ResourceCatalog() common.Resource { return bindings.AddCurrentWorkspaceBindings(ctx, d, w, ci.Name, bindings.BindingsSecurableTypeCatalog) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -216,33 +250,5 @@ func ResourceCatalog() common.Resource { } return w.Catalogs.Delete(ctx, catalog.DeleteCatalogRequest{Force: force, Name: d.Id()}) }, - CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { - // The only scenario in which we can update options is for the `authorized_paths` key. Any - // other changes to the options field will result in an error. - if d.HasChange("options") { - old, new := d.GetChange("options") - oldMap := old.(map[string]interface{}) - newMap := new.(map[string]interface{}) - delete(oldMap, "authorized_paths") - delete(newMap, "authorized_paths") - // If any attribute other than `authorized_paths` is removed, the resource should be recreated. - for k := range oldMap { - if _, ok := newMap[k]; !ok { - if err := d.ForceNew("options"); err != nil { - return err - } - } - } - // If any attribute other than `authorized_paths` is added or changed, the resource should be recreated. - for k, v := range newMap { - if oldV, ok := oldMap[k]; !ok || oldV != v { - if err := d.ForceNew("options"); err != nil { - return err - } - } - } - } - return nil - }, } } diff --git a/catalog/resource_connection.go b/catalog/resource_connection.go index 10a7fac257..527cdaf80f 100644 --- a/catalog/resource_connection.go +++ b/catalog/resource_connection.go @@ -25,8 +25,13 @@ func suppressComputedFields(k, old, new string, d *schema.ResourceData) bool { return false } +type ConnectionInfoResource struct { + catalog.ConnectionInfo + common.Namespace +} + func ResourceConnection() common.Resource { - s := common.StructToSchema(catalog.ConnectionInfo{}, + s := common.StructToSchema(ConnectionInfoResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { for _, v := range []string{"url", "metastore_id", "credential_type", "connection_id", "created_at", "created_by", "full_name", "provisioning_info", "securable_type", "updated_at", "updated_by"} { @@ -41,6 +46,7 @@ func ResourceConnection() common.Resource { common.CustomizeSchemaPath(m, "options").SetSensitive().SetCustomSuppressDiff(suppressComputedFields) common.CustomizeSchemaPath(m, "name").SetCustomSuppressDiff(common.EqualFoldDiffSuppress) + common.NamespaceCustomizeSchemaMap(m) return m }) pi := common.NewPairID("metastore_id", "name").Schema( @@ -49,8 +55,11 @@ func ResourceConnection() common.Resource { }) return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -79,7 +88,7 @@ func ResourceConnection() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -113,7 +122,7 @@ func ResourceConnection() common.Resource { return common.StructToData(conn, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -161,7 +170,7 @@ func ResourceConnection() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_credential.go b/catalog/resource_credential.go index 634a1c5531..7bd8783058 100644 --- a/catalog/resource_credential.go +++ b/catalog/resource_credential.go @@ -9,7 +9,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -var credentialSchema = common.StructToSchema(catalog.CredentialInfo{}, +type CredentialInfoResource struct { + catalog.CredentialInfo + common.Namespace +} + +var credentialSchema = common.StructToSchema(CredentialInfoResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { var alofServiceCreds = []string{"aws_iam_role", "azure_managed_identity", "azure_service_principal", "databricks_gcp_service_account"} @@ -55,14 +60,18 @@ var credentialSchema = common.StructToSchema(catalog.CredentialInfo{}, Computed: true, } m["name"].DiffSuppressFunc = common.EqualFoldDiffSuppress + common.NamespaceCustomizeSchemaMap(m) return m }) func ResourceCredential() common.Resource { return common.Resource{ Schema: credentialSchema, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -94,7 +103,7 @@ func ResourceCredential() common.Resource { return bindings.AddCurrentWorkspaceBindings(ctx, d, w, cred.Name, bindings.BindingsSecurableTypeCredential) }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -115,7 +124,7 @@ func ResourceCredential() common.Resource { }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { force := d.Get("force_update").(bool) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -173,7 +182,7 @@ func ResourceCredential() common.Resource { }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { force := d.Get("force_destroy").(bool) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_external_location.go b/catalog/resource_external_location.go index cbc445da26..293058ddad 100644 --- a/catalog/resource_external_location.go +++ b/catalog/resource_external_location.go @@ -13,6 +13,7 @@ import ( type ExternalLocationInfo struct { catalog.ExternalLocationInfo SkipValidation bool `json:"skip_validation,omitempty"` + common.Namespace } func ResourceExternalLocation() common.Resource { @@ -57,12 +58,16 @@ func ResourceExternalLocation() common.Resource { common.CustomizeSchemaPath(m, "file_event_queue", "managed_aqs", "subscription_id").SetRequired() common.CustomizeSchemaPath(m, "file_event_queue").SetMaxItems(1) + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -95,7 +100,7 @@ func ResourceExternalLocation() common.Resource { return bindings.AddCurrentWorkspaceBindings(ctx, d, w, el.Name, bindings.BindingsSecurableTypeExternalLocation) }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -107,7 +112,7 @@ func ResourceExternalLocation() common.Resource { }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { force := d.Get("force_update").(bool) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -184,7 +189,7 @@ func ResourceExternalLocation() common.Resource { }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { force := d.Get("force_destroy").(bool) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_grant.go b/catalog/resource_grant.go index 28f26cb9bf..0c5ba07c23 100644 --- a/catalog/resource_grant.go +++ b/catalog/resource_grant.go @@ -131,8 +131,13 @@ func parseSecurableId(d *schema.ResourceData) (string, string, string, error) { return split[0], split[1], split[2], nil } +type GrantResource struct { + permissions.UnityCatalogPrivilegeAssignment + common.Namespace +} + func ResourceGrant() common.Resource { - s := common.StructToSchema(permissions.UnityCatalogPrivilegeAssignment{}, + s := common.StructToSchema(GrantResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(m, "principal").SetForceNew() @@ -155,13 +160,17 @@ func ResourceGrant() common.Resource { ConflictsWith: permissions.SliceWithoutString(allFields, field), } } + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -208,7 +217,7 @@ func ResourceGrant() common.Resource { return d.Set(securable, name) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -233,7 +242,7 @@ func ResourceGrant() common.Resource { return replacePermissionsForPrincipal(unityCatalogPermissionsAPI, securable, name, principal, grants) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_grants.go b/catalog/resource_grants.go index 7d5693ec08..0612207554 100644 --- a/catalog/resource_grants.go +++ b/catalog/resource_grants.go @@ -24,6 +24,7 @@ type PrivilegeAssignment struct { // privilege_assignments column renamed to `grant` block for simplicity type PermissionsList struct { Assignments []PrivilegeAssignment `json:"privilege_assignments" tf:"slice_set,alias:grant"` + common.Namespace } // diffPermissions returns an array of catalog.PermissionsChange of this permissions list with `diff` privileges removed @@ -160,12 +161,16 @@ func ResourceGrants() common.Resource { for field := range permissions.Mappings { s[field].AtLeastOneOf = alof } + common.NamespaceCustomizeSchemaMap(s) return s }) return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -209,7 +214,7 @@ func ResourceGrants() common.Resource { return d.Set(securable, name) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -227,7 +232,7 @@ func ResourceGrants() common.Resource { return replaceAllPermissions(unityCatalogPermissionsAPI, securable, name, grants.toSdkPermissionsList()) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_online_table.go b/catalog/resource_online_table.go index 7e658b6f48..45e529a3e1 100644 --- a/catalog/resource_online_table.go +++ b/catalog/resource_online_table.go @@ -29,8 +29,13 @@ func waitForOnlineTableDeletion(w *databricks.WorkspaceClient, ctx context.Conte }) } +type OnlineTableResource struct { + catalog.OnlineTable + common.Namespace +} + func ResourceOnlineTable() common.Resource { - s := common.StructToSchema(catalog.OnlineTable{}, + s := common.StructToSchema(OnlineTableResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["name"].DiffSuppressFunc = common.EqualFoldDiffSuppress common.CustomizeSchemaPath(m, "spec", "source_table_full_name").SetCustomSuppressDiff(common.EqualFoldDiffSuppress) @@ -43,12 +48,17 @@ func ResourceOnlineTable() common.Resource { runTypes := []string{"spec.0.run_triggered", "spec.0.run_continuously"} common.CustomizeSchemaPath(m, "spec", "run_triggered").SetAtLeastOneOf(runTypes).SetSuppressDiff() common.CustomizeSchemaPath(m, "spec", "run_continuously").SetAtLeastOneOf(runTypes).SetSuppressDiff() + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ + Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -69,7 +79,7 @@ func ResourceOnlineTable() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -80,7 +90,7 @@ func ResourceOnlineTable() common.Resource { return common.StructToData(*table, s, d) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -91,7 +101,6 @@ func ResourceOnlineTable() common.Resource { return waitForOnlineTableDeletion(w, ctx, d.Id()) }, StateUpgraders: []schema.StateUpgrader{}, - Schema: s, SchemaVersion: 0, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(onlineTableDefaultProvisionTimeout), diff --git a/catalog/resource_quality_monitor.go b/catalog/resource_quality_monitor.go index c6450a0d93..300cdbabcd 100644 --- a/catalog/resource_quality_monitor.go +++ b/catalog/resource_quality_monitor.go @@ -33,9 +33,14 @@ func WaitForMonitor(w *databricks.WorkspaceClient, ctx context.Context, monitorN }) } +type MonitorInfoResource struct { + catalog.MonitorInfo + common.Namespace +} + func ResourceQualityMonitor() common.Resource { monitorSchema := common.StructToSchema( - catalog.MonitorInfo{}, + MonitorInfoResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(m, "assets_dir").SetRequired() common.CustomizeSchemaPath(m, "output_schema_name").SetRequired() @@ -56,13 +61,18 @@ func ResourceQualityMonitor() common.Resource { common.CustomizeSchemaPath(m, "status").SetReadOnly() common.CustomizeSchemaPath(m, "dashboard_id").SetReadOnly() common.CustomizeSchemaPath(m, "schedule", "pause_status").SetReadOnly() + common.NamespaceCustomizeSchemaMap(m) return m }, ) return common.Resource{ + Schema: monitorSchema, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -83,7 +93,7 @@ func ResourceQualityMonitor() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -108,7 +118,7 @@ func ResourceQualityMonitor() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -125,7 +135,7 @@ func ResourceQualityMonitor() common.Resource { return WaitForMonitor(w, ctx, update.TableName) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -134,7 +144,6 @@ func ResourceQualityMonitor() common.Resource { }) return err }, - Schema: monitorSchema, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(qualityMonitorDefaultProvisionTimeout), }, diff --git a/catalog/resource_registered_model.go b/catalog/resource_registered_model.go index 9a14879325..4c23355eb9 100644 --- a/catalog/resource_registered_model.go +++ b/catalog/resource_registered_model.go @@ -8,9 +8,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +type RegisteredModelResource struct { + catalog.CreateRegisteredModelRequest + common.Namespace +} + func ResourceRegisteredModel() common.Resource { s := common.StructToSchema( - catalog.CreateRegisteredModelRequest{}, + RegisteredModelResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { caseInsensitiveFields := []string{"name", "catalog_name", "schema_name"} for _, field := range caseInsensitiveFields { @@ -34,12 +39,17 @@ func ResourceRegisteredModel() common.Resource { } } + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ + Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -65,7 +75,7 @@ func ResourceRegisteredModel() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -76,7 +86,7 @@ func ResourceRegisteredModel() common.Resource { return common.StructToData(*model, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -122,14 +132,13 @@ func ResourceRegisteredModel() common.Resource { return err }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return w.RegisteredModels.DeleteByFullName(ctx, d.Id()) }, StateUpgraders: []schema.StateUpgrader{}, - Schema: s, SchemaVersion: 0, } } diff --git a/catalog/resource_schema.go b/catalog/resource_schema.go index 7d2f895da6..ed9338c9e3 100644 --- a/catalog/resource_schema.go +++ b/catalog/resource_schema.go @@ -20,6 +20,7 @@ type SchemaInfo struct { MetastoreID string `json:"metastore_id,omitempty" tf:"computed"` FullName string `json:"full_name,omitempty" tf:"computed"` SchemaID string `json:"schema_id" tf:"computed"` + common.Namespace } func ResourceSchema() common.Resource { @@ -38,12 +39,16 @@ func ResourceSchema() common.Resource { common.CustomizeSchemaPath(s, "enable_predictive_optimization").SetValidateFunc( validation.StringInSlice([]string{"DISABLE", "ENABLE", "INHERIT"}, false), ) + common.NamespaceCustomizeSchemaMap(s) return s }) return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -81,7 +86,7 @@ func ResourceSchema() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -92,7 +97,7 @@ func ResourceSchema() common.Resource { return common.StructToData(schema, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -149,7 +154,7 @@ func ResourceSchema() common.Resource { Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { force := d.Get("force_destroy").(bool) name := d.Id() - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_sql_table.go b/catalog/resource_sql_table.go index 99019c7868..f4bf400e52 100644 --- a/catalog/resource_sql_table.go +++ b/catalog/resource_sql_table.go @@ -65,6 +65,7 @@ type SqlTableInfo struct { WarehouseID string `json:"warehouse_id,omitempty"` Owner string `json:"owner,omitempty" tf:"computed"` TableID string `json:"table_id" tf:"computed"` + common.Namespace exec common.CommandExecutor sqlExec sql.StatementExecutionInterface @@ -92,6 +93,7 @@ func (ti SqlTableInfo) CustomizeSchema(s *common.CustomizableSchema) *common.Cus s.SchemaPath("column", "type").SetCustomSuppressDiff(func(k, old, new string, d *schema.ResourceData) bool { return getColumnType(old) == getColumnType(new) }) + common.NamespaceCustomizeSchema(s) return s } @@ -175,7 +177,7 @@ func (ti *SqlTableInfo) initCluster(ctx context.Context, d *schema.ResourceData, } } ti.exec = c.CommandExecutor(ctx) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -663,7 +665,7 @@ func ResourceSqlTable() common.Resource { if d.HasChange("comment") && d.Get("table_type") == "VIEW" { d.ForceNew("comment") } - return nil + return common.NamespaceCustomizeDiff(d) }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { var ti = new(SqlTableInfo) @@ -675,7 +677,7 @@ func ResourceSqlTable() common.Resource { return err } if ti.Owner != "" { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -695,7 +697,7 @@ func ResourceSqlTable() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -729,7 +731,7 @@ func ResourceSqlTable() common.Resource { return common.StructToData(ti, tableSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_system_schema.go b/catalog/resource_system_schema.go index a8e65db3a1..2b42373d58 100644 --- a/catalog/resource_system_schema.go +++ b/catalog/resource_system_schema.go @@ -12,8 +12,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +type SystemSchemaResource struct { + catalog.SystemSchemaInfo + common.Namespace +} + func ResourceSystemSchema() common.Resource { - systemSchema := common.StructToSchema(catalog.SystemSchemaInfo{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { + systemSchema := common.StructToSchema(SystemSchemaResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["metastore_id"] = &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -30,6 +35,7 @@ func ResourceSystemSchema() common.Resource { Type: schema.TypeString, Computed: true, } + common.NamespaceCustomizeSchemaMap(m) return m }) pi := common.NewPairID("metastore_id", "schema").Schema( @@ -44,7 +50,7 @@ func ResourceSystemSchema() common.Resource { return fmt.Errorf("internal type casting error") } log.Printf("[DEBUG] Old system schema: %s, new: %s", old, new) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -82,13 +88,16 @@ func ResourceSystemSchema() common.Resource { } return common.Resource{ Schema: systemSchema, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: createOrUpdate, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { _, schemaName, err := pi.Unpack(d) if err != nil { return err } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -133,7 +142,7 @@ func ResourceSystemSchema() common.Resource { log.Printf("[WARN] %s is auto enabled, ignoring it", schemaName) return nil } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_volume.go b/catalog/resource_volume.go index 3ee2a32542..d529d852c0 100644 --- a/catalog/resource_volume.go +++ b/catalog/resource_volume.go @@ -29,6 +29,7 @@ type VolumeInfo struct { // The storage location on the cloud StorageLocation string `json:"storage_location,omitempty" tf:"force_new"` VolumeType catalog.VolumeType `json:"volume_type" tf:"force_new"` + common.Namespace } func getNameFromId(id string) (string, error) { @@ -58,12 +59,16 @@ func ResourceVolume() common.Resource { // If server side validation is added in the future, this validation function // can be removed. common.CustomizeSchemaPath(m, "volume_type").SetValidateFunc(validation.StringInSlice([]string{"MANAGED", "EXTERNAL"}, false)) + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -90,7 +95,7 @@ func ResourceVolume() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -105,7 +110,7 @@ func ResourceVolume() common.Resource { return d.Set("volume_path", "/Volumes/"+strings.ReplaceAll(v.FullName, ".", "/")) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -163,7 +168,7 @@ func ResourceVolume() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/catalog/resource_workspace_binding.go b/catalog/resource_workspace_binding.go index cae05bd724..54ae923aa2 100644 --- a/catalog/resource_workspace_binding.go +++ b/catalog/resource_workspace_binding.go @@ -52,8 +52,13 @@ var getSecurableName = func(d *schema.ResourceData) string { return securableName.(string) } +type WorkspaceBindingResource struct { + catalog.WorkspaceBinding + common.Namespace +} + func ResourceWorkspaceBinding() common.Resource { - workspaceBindingSchema := common.StructToSchema(catalog.WorkspaceBinding{}, + workspaceBindingSchema := common.StructToSchema(WorkspaceBindingResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["catalog_name"] = &schema.Schema{ Type: schema.TypeString, @@ -80,12 +85,16 @@ func ResourceWorkspaceBinding() common.Resource { string(catalog.WorkspaceBindingBindingTypeBindingTypeReadWrite), string(catalog.WorkspaceBindingBindingTypeBindingTypeReadOnly), }, false)) + common.NamespaceCustomizeSchemaMap(m) return m }, ) return common.Resource{ Schema: workspaceBindingSchema, SchemaVersion: 1, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, StateUpgraders: []schema.StateUpgrader{ { Version: 0, @@ -94,7 +103,7 @@ func ResourceWorkspaceBinding() common.Resource { }, }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -111,7 +120,7 @@ func ResourceWorkspaceBinding() common.Resource { return err }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -146,7 +155,7 @@ func ResourceWorkspaceBinding() common.Resource { } }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/common/client.go b/common/client.go index a9919c7d21..a7faa6524b 100644 --- a/common/client.go +++ b/common/client.go @@ -142,7 +142,7 @@ func (c *DatabricksClient) getWorkspaceClientForWorkspaceConfiguredProvider( // Provider is configured at workspace level and we get the // workspace client from the provider. if workspaceID == "" { - return c.WorkspaceClient() + return c.WorkspaceClientUnifiedProvider(ctx, d) } workspaceIDInt, err := parseWorkspaceID(workspaceID) @@ -152,7 +152,7 @@ func (c *DatabricksClient) getWorkspaceClientForWorkspaceConfiguredProvider( // Check if the workspace ID specified in the resource matches // the workspace ID of the provider configured workspace client. - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return nil, err } @@ -219,7 +219,7 @@ func (c *DatabricksClient) setCachedWorkspaceID(ctx context.Context, w *databric // over plugin framework. func (c *DatabricksClient) GetWorkspaceClient() (*databricks.WorkspaceClient, diag.Diagnostics) { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return nil, diag.Diagnostics{diag.NewErrorDiagnostic("Failed to get workspace client", err.Error())} } @@ -370,7 +370,7 @@ func (c *DatabricksClient) AccountOrWorkspaceRequest(accCallback func(*databrick } return accCallback(a) } else { - ws, err := c.WorkspaceClient() + ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/dashboards/resource_dashboard.go b/dashboards/resource_dashboard.go index b1c9d71be2..c8a3836b66 100644 --- a/dashboards/resource_dashboard.go +++ b/dashboards/resource_dashboard.go @@ -66,7 +66,7 @@ func ResourceDashboard() common.Resource { return common.Resource{ Schema: dashboardSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -115,7 +115,7 @@ func ResourceDashboard() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -138,7 +138,7 @@ func ResourceDashboard() common.Resource { return common.StructToData(resp, dashboardSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -181,7 +181,7 @@ func ResourceDashboard() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/internal/providers/providers_test.go b/internal/providers/providers_test.go index 320ab050a9..c90d269624 100644 --- a/internal/providers/providers_test.go +++ b/internal/providers/providers_test.go @@ -370,7 +370,7 @@ func TestConfig_OAuthFetchesToken(t *testing.T) { } func testOAuthFetchesToken(t *testing.T, c *common.DatabricksClient) { - ws, err := c.WorkspaceClient() + ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) require.NoError(t, err) bgCtx := context.Background() { diff --git a/mlflow/resource_mlflow_experiment.go b/mlflow/resource_mlflow_experiment.go index eb8668f466..be89be862e 100644 --- a/mlflow/resource_mlflow_experiment.go +++ b/mlflow/resource_mlflow_experiment.go @@ -39,7 +39,7 @@ func ResourceMlflowExperiment() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -53,7 +53,7 @@ func ResourceMlflowExperiment() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -64,7 +64,7 @@ func ResourceMlflowExperiment() common.Resource { return common.StructToData(e.Experiment, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -74,7 +74,7 @@ func ResourceMlflowExperiment() common.Resource { }) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/mlflow/resource_mlflow_model.go b/mlflow/resource_mlflow_model.go index a461287215..3feaa50623 100644 --- a/mlflow/resource_mlflow_model.go +++ b/mlflow/resource_mlflow_model.go @@ -22,7 +22,7 @@ func ResourceMlflowModel() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -36,7 +36,7 @@ func ResourceMlflowModel() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -55,7 +55,7 @@ func ResourceMlflowModel() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -68,7 +68,7 @@ func ResourceMlflowModel() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/mlflow/resource_mlflow_webhook.go b/mlflow/resource_mlflow_webhook.go index 91ef36c261..4e2837decb 100644 --- a/mlflow/resource_mlflow_webhook.go +++ b/mlflow/resource_mlflow_webhook.go @@ -46,7 +46,7 @@ func ResourceMlflowWebhook() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -66,7 +66,7 @@ func ResourceMlflowWebhook() common.Resource { Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { var mOrig ml.CreateRegistryWebhook common.DataToStructPointer(d, s, &mOrig) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -88,7 +88,7 @@ func ResourceMlflowWebhook() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -102,7 +102,7 @@ func ResourceMlflowWebhook() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/permissions/permissions_test.go b/permissions/permissions_test.go index 563ee90585..109febe23e 100644 --- a/permissions/permissions_test.go +++ b/permissions/permissions_test.go @@ -364,7 +364,7 @@ func TestAccPermissions_Pipeline(t *testing.T) { }, acceptance.Step{ Template: policyTemplate, Check: acceptance.ResourceCheck("databricks_pipeline.this", func(ctx context.Context, c *common.DatabricksClient, id string) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) assert.NoError(t, err) pipeline, err := w.Pipelines.GetByPipelineId(context.Background(), id) assert.NoError(t, err) diff --git a/permissions/resource_access_control_rule_set.go b/permissions/resource_access_control_rule_set.go index 7d0b2a5466..2f2772a4db 100644 --- a/permissions/resource_access_control_rule_set.go +++ b/permissions/resource_access_control_rule_set.go @@ -32,7 +32,7 @@ func ResourceAccessControlRuleSet() common.Resource { } return accountClient.AccessControl.GetRuleSet(ctx, getRuleSetReq) } - workspaceClient, err := c.WorkspaceClient() + workspaceClient, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return nil, err } @@ -46,7 +46,7 @@ func ResourceAccessControlRuleSet() common.Resource { } return accountClient.AccessControl.UpdateRuleSet(ctx, updateRuleSetReq) } - workspaceClient, err := c.WorkspaceClient() + workspaceClient, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return nil, err } diff --git a/permissions/resource_permissions.go b/permissions/resource_permissions.go index 4655cc6f89..82a0ffce75 100644 --- a/permissions/resource_permissions.go +++ b/permissions/resource_permissions.go @@ -271,7 +271,7 @@ func ResourcePermissions() common.Resource { Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { var entity entity.PermissionsEntity common.DataToStructPointer(d, s, &entity) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/pipelines/resource_pipeline.go b/pipelines/resource_pipeline.go index ff568e66e6..cf7ed87b20 100644 --- a/pipelines/resource_pipeline.go +++ b/pipelines/resource_pipeline.go @@ -282,14 +282,14 @@ func ResourcePipeline() common.Resource { return common.Resource{ Schema: pipelineSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return Create(w, ctx, d, d.Timeout(schema.TimeoutCreate)) }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -317,7 +317,7 @@ func ResourcePipeline() common.Resource { return common.StructToData(p, pipelineSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -325,7 +325,7 @@ func ResourcePipeline() common.Resource { }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/policies/resource_cluster_policy.go b/policies/resource_cluster_policy.go index ab55443736..45ad1d99cf 100644 --- a/policies/resource_cluster_policy.go +++ b/policies/resource_cluster_policy.go @@ -57,7 +57,7 @@ func ResourceClusterPolicy() common.Resource { }, }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -94,7 +94,7 @@ func ResourceClusterPolicy() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -105,7 +105,7 @@ func ResourceClusterPolicy() common.Resource { return common.StructToData(resp, rcpSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -120,7 +120,7 @@ func ResourceClusterPolicy() common.Resource { return w.ClusterPolicies.Edit(ctx, request) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/repos/resource_git_credential.go b/repos/resource_git_credential.go index ee4cb90458..1021de335a 100644 --- a/repos/resource_git_credential.go +++ b/repos/resource_git_credential.go @@ -37,7 +37,7 @@ func ResourceGitCredential() common.Resource { Schema: s, SchemaVersion: 1, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -71,7 +71,7 @@ func ResourceGitCredential() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -96,7 +96,7 @@ func ResourceGitCredential() common.Resource { return err } req.CredentialId = cred_id - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -109,7 +109,7 @@ func ResourceGitCredential() common.Resource { return w.GitCredentials.Update(ctx, req) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/scim/data_current_user.go b/scim/data_current_user.go index 7a6066c1bd..580cf95a7f 100644 --- a/scim/data_current_user.go +++ b/scim/data_current_user.go @@ -46,7 +46,7 @@ func DataSourceCurrentUser() common.Resource { }, }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/secrets/resource_secret.go b/secrets/resource_secret.go index e4507c2692..a1de1ecc1b 100644 --- a/secrets/resource_secret.go +++ b/secrets/resource_secret.go @@ -70,7 +70,7 @@ func ResourceSecret() common.Resource { return common.Resource{ Schema: s, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -88,7 +88,7 @@ func ResourceSecret() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -104,7 +104,7 @@ func ResourceSecret() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/secrets/resource_secret_acl.go b/secrets/resource_secret_acl.go index e271c651d4..4c89d6d75e 100644 --- a/secrets/resource_secret_acl.go +++ b/secrets/resource_secret_acl.go @@ -41,7 +41,7 @@ func ResourceSecretACL() common.Resource { return true }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -58,7 +58,7 @@ func ResourceSecretACL() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -76,7 +76,7 @@ func ResourceSecretACL() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/secrets/resource_secret_scope.go b/secrets/resource_secret_scope.go index ebb19f9efa..d60a529762 100644 --- a/secrets/resource_secret_scope.go +++ b/secrets/resource_secret_scope.go @@ -68,7 +68,7 @@ func ResourceSecretScope() common.Resource { Schema: s, SchemaVersion: 2, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -86,7 +86,7 @@ func ResourceSecretScope() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -97,7 +97,7 @@ func ResourceSecretScope() common.Resource { return common.StructToData(scope, s, d) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/serving/resource_model_serving.go b/serving/resource_model_serving.go index 215f5edbdc..d4e8ab745c 100644 --- a/serving/resource_model_serving.go +++ b/serving/resource_model_serving.go @@ -227,7 +227,7 @@ func ResourceModelServing() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -250,7 +250,7 @@ func ResourceModelServing() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) var sOrig serving.ServingEndpointDetailed common.DataToStructPointer(d, s, &sOrig) if err != nil { @@ -284,7 +284,7 @@ func ResourceModelServing() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -308,7 +308,7 @@ func ResourceModelServing() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/serving/resource_model_serving_provisioned_throughput.go b/serving/resource_model_serving_provisioned_throughput.go index bd0a933a04..c0c3605560 100644 --- a/serving/resource_model_serving_provisioned_throughput.go +++ b/serving/resource_model_serving_provisioned_throughput.go @@ -39,7 +39,7 @@ func ResourceModelServingProvisionedThroughput() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -62,7 +62,7 @@ func ResourceModelServingProvisionedThroughput() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) var sOrig serving.ServingEndpointDetailed common.DataToStructPointer(d, s, &sOrig) if err != nil { @@ -80,7 +80,7 @@ func ResourceModelServingProvisionedThroughput() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -113,7 +113,7 @@ func ResourceModelServingProvisionedThroughput() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/settings/generic_setting.go b/settings/generic_setting.go index 91108b86eb..1e326436e8 100644 --- a/settings/generic_setting.go +++ b/settings/generic_setting.go @@ -288,7 +288,7 @@ func (aw accountWorkspaceSetting[T]) Read(ctx context.Context, c *common.Databri } return aw.readAccFunc(ctx, a, etag) } else { - ws, err := c.WorkspaceClient() + ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return nil, err } @@ -303,7 +303,7 @@ func (aw accountWorkspaceSetting[T]) Update(ctx context.Context, c *common.Datab } return aw.updateAccFunc(ctx, a, t) } else { - ws, err := c.WorkspaceClient() + ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return "", err } @@ -318,7 +318,7 @@ func (aw accountWorkspaceSetting[T]) Delete(ctx context.Context, c *common.Datab } return aw.deleteAccFunc(ctx, a, etag) } else { - ws, err := c.WorkspaceClient() + ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return "", err } @@ -366,7 +366,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R var res string switch defn := defn.(type) { case workspaceSettingDefinition[T]: - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -425,7 +425,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R var res *T switch defn := defn.(type) { case workspaceSettingDefinition[T]: - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -472,7 +472,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R updateETag := func(req *string, newEtag string) { *req = newEtag } switch defn := defn.(type) { case workspaceSettingDefinition[T]: - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/settings/resource_notification_destination.go b/settings/resource_notification_destination.go index a610c4c2d4..778462cff3 100644 --- a/settings/resource_notification_destination.go +++ b/settings/resource_notification_destination.go @@ -168,28 +168,28 @@ func ResourceNotificationDestination() common.Resource { Schema: ndSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return Create(ctx, d, w) }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return Read(ctx, d, w) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return Update(ctx, d, w) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/sharing/resource_recipient.go b/sharing/resource_recipient.go index ce5232e53b..9ba1ffbc66 100644 --- a/sharing/resource_recipient.go +++ b/sharing/resource_recipient.go @@ -48,7 +48,7 @@ func ResourceRecipient() common.Resource { return common.Resource{ Schema: recipientSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -62,7 +62,7 @@ func ResourceRecipient() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -81,7 +81,7 @@ func ResourceRecipient() common.Resource { return common.StructToData(ri, recipientSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -122,7 +122,7 @@ func ResourceRecipient() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/sharing/resource_share.go b/sharing/resource_share.go index d079190a56..e4801f46eb 100644 --- a/sharing/resource_share.go +++ b/sharing/resource_share.go @@ -155,7 +155,7 @@ func ResourceShare() common.Resource { return common.Resource{ Schema: shareSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -184,7 +184,7 @@ func ResourceShare() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -203,7 +203,7 @@ func ResourceShare() common.Resource { return common.StructToData(si, shareSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -263,7 +263,7 @@ func ResourceShare() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/sql/resource_alert.go b/sql/resource_alert.go index c7d71e8c61..eff321f3ef 100644 --- a/sql/resource_alert.go +++ b/sql/resource_alert.go @@ -50,7 +50,7 @@ func ResourceAlert() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -78,7 +78,7 @@ func ResourceAlert() common.Resource { return err }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -94,7 +94,7 @@ func ResourceAlert() common.Resource { return common.StructToData(apiAlert, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -118,7 +118,7 @@ func ResourceAlert() common.Resource { return err }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/sql/resource_query.go b/sql/resource_query.go index 4db7820d21..7446dd8285 100644 --- a/sql/resource_query.go +++ b/sql/resource_query.go @@ -93,7 +93,7 @@ func ResourceQuery() common.Resource { s := common.StructToSchema(QueryStruct{}, nil) return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -121,7 +121,7 @@ func ResourceQuery() common.Resource { return err }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -137,7 +137,7 @@ func ResourceQuery() common.Resource { return common.StructToData(QueryStruct{Query: *apiQuery}, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -160,7 +160,7 @@ func ResourceQuery() common.Resource { return err }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/sql/resource_sql_alerts.go b/sql/resource_sql_alerts.go index 7a54a59ecb..ee0bcbfe37 100644 --- a/sql/resource_sql_alerts.go +++ b/sql/resource_sql_alerts.go @@ -130,7 +130,7 @@ func ResourceSqlAlert() common.Resource { return common.Resource{ Create: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -147,7 +147,7 @@ func ResourceSqlAlert() common.Resource { return nil }, Read: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -160,7 +160,7 @@ func ResourceSqlAlert() common.Resource { return a.fromAPIObject(apiAlert, s, data) }, Update: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -172,7 +172,7 @@ func ResourceSqlAlert() common.Resource { return w.AlertsLegacy.Update(ctx, ca) }, Delete: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/sql/resource_sql_endpoint.go b/sql/resource_sql_endpoint.go index a08e138fd5..1eba939e16 100644 --- a/sql/resource_sql_endpoint.go +++ b/sql/resource_sql_endpoint.go @@ -105,7 +105,7 @@ func ResourceSqlEndpoint() common.Resource { Create: schema.DefaultTimeout(30 * time.Minute), }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -138,7 +138,7 @@ func ResourceSqlEndpoint() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -153,7 +153,7 @@ func ResourceSqlEndpoint() common.Resource { return common.StructToData(warehouse, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -168,7 +168,7 @@ func ResourceSqlEndpoint() common.Resource { return nil }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/storage/resource_file.go b/storage/resource_file.go index 85121b3d2e..14be2c7ebb 100644 --- a/storage/resource_file.go +++ b/storage/resource_file.go @@ -52,7 +52,7 @@ func getContentReader(data *schema.ResourceData) (*hashReadCloser, error) { } func upload(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient, path string) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -104,7 +104,7 @@ func ResourceFile() common.Resource { return nil }, Read: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -127,7 +127,7 @@ func ResourceFile() common.Resource { return upload(ctx, data, c, path) }, Delete: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index b6bb62c2e5..1909ba35c8 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -41,7 +41,7 @@ func ResourceVectorSearchEndpoint() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -64,7 +64,7 @@ func ResourceVectorSearchEndpoint() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -81,7 +81,7 @@ func ResourceVectorSearchEndpoint() common.Resource { return nil }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -98,7 +98,7 @@ func ResourceVectorSearchEndpoint() common.Resource { }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/vectorsearch/resource_vector_search_index.go b/vectorsearch/resource_vector_search_index.go index 85d9eaf205..b853c2fdab 100644 --- a/vectorsearch/resource_vector_search_index.go +++ b/vectorsearch/resource_vector_search_index.go @@ -67,7 +67,7 @@ func ResourceVectorSearchIndex() common.Resource { return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -89,7 +89,7 @@ func ResourceVectorSearchIndex() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -100,7 +100,7 @@ func ResourceVectorSearchIndex() common.Resource { return common.StructToData(*index, s, d) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/workspace/resource_directory.go b/workspace/resource_directory.go index 2ed4bcc4df..eebc58727e 100644 --- a/workspace/resource_directory.go +++ b/workspace/resource_directory.go @@ -40,9 +40,10 @@ func ResourceDirectory() common.Resource { Computed: true, }, } + common.NamespaceCustomizeSchemaMap(s) directoryRead := func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -66,8 +67,11 @@ func ResourceDirectory() common.Resource { return common.Resource{ Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -83,7 +87,7 @@ func ResourceDirectory() common.Resource { Read: directoryRead, Update: directoryRead, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/workspace/resource_global_init_script.go b/workspace/resource_global_init_script.go index 37d915941f..16b59e03b1 100644 --- a/workspace/resource_global_init_script.go +++ b/workspace/resource_global_init_script.go @@ -44,7 +44,12 @@ func ResourceGlobalInitScript() common.Resource { }, } s := FileContentSchemaWithoutPath(extra) + common.NamespaceCustomizeSchemaMap(s) return common.Resource{ + Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { content, err := ReadContent(d) if err != nil { @@ -54,7 +59,7 @@ func ResourceGlobalInitScript() common.Resource { return fmt.Errorf("size of the global init script (%d bytes) exceeds maximal allowed (%d bytes)", contentLen, maxScriptSize) } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -71,7 +76,7 @@ func ResourceGlobalInitScript() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -90,7 +95,7 @@ func ResourceGlobalInitScript() common.Resource { return fmt.Errorf("size of the global init script (%d bytes) exceeds maximal allowed (%d bytes)", contentLen, maxScriptSize) } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -103,13 +108,12 @@ func ResourceGlobalInitScript() common.Resource { }) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } return w.GlobalInitScripts.DeleteByScriptId(ctx, d.Id()) }, - Schema: s, SchemaVersion: 1, Timeouts: &schema.ResourceTimeout{}, } diff --git a/workspace/resource_notebook.go b/workspace/resource_notebook.go index 1bff5895ff..38d86fb2d3 100644 --- a/workspace/resource_notebook.go +++ b/workspace/resource_notebook.go @@ -341,7 +341,7 @@ func ResourceNotebook() common.Resource { oldFormat = "SOURCE" } } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } diff --git a/workspace/resource_workspace_conf.go b/workspace/resource_workspace_conf.go index 41e720b1c2..69fb70ef9b 100644 --- a/workspace/resource_workspace_conf.go +++ b/workspace/resource_workspace_conf.go @@ -64,7 +64,7 @@ func applyWorkspaceConf(ctx context.Context, d *schema.ResourceData, c *common.D } } - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -96,7 +96,7 @@ func updateWorkspaceConf(ctx context.Context, d *schema.ResourceData, c *common. } func deleteWorkspaceConf(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -222,7 +222,7 @@ func ResourceWorkspaceConf() common.Resource { Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { config := d.Get("custom_config").(map[string]any) log.Printf("[DEBUG] Config available in state: %v", config) - w, err := c.WorkspaceClient() + w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -244,11 +244,18 @@ func ResourceWorkspaceConf() common.Resource { return d.Set("custom_config", config) }, Delete: deleteWorkspaceConf, - Schema: map[string]*schema.Schema{ - "custom_config": { - Type: schema.TypeMap, - Optional: true, - }, + Schema: func() map[string]*schema.Schema { + s := map[string]*schema.Schema{ + "custom_config": { + Type: schema.TypeMap, + Optional: true, + }, + } + common.NamespaceCustomizeSchemaMap(s) + return s + }(), + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) }, } } diff --git a/workspace/resource_workspace_file.go b/workspace/resource_workspace_file.go index 8a72107e1d..ddebad3bb9 100644 --- a/workspace/resource_workspace_file.go +++ b/workspace/resource_workspace_file.go @@ -29,15 +29,19 @@ func ResourceWorkspaceFile() common.Resource { Computed: true, }, }) + common.NamespaceCustomizeSchemaMap(s) return common.Resource{ Schema: s, SchemaVersion: 1, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { content, err := ReadContent(d) if err != nil { return err } - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -68,7 +72,7 @@ func ResourceWorkspaceFile() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -82,7 +86,7 @@ func ResourceWorkspaceFile() common.Resource { return common.StructToData(objectStatus, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } @@ -99,7 +103,7 @@ func ResourceWorkspaceFile() common.Resource { }) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClient() + client, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { return err } From 66b389611ec9c64fe4dea25b741e1f88871242ff Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Thu, 30 Oct 2025 17:14:45 +0530 Subject: [PATCH 2/3] - --- common/client.go | 8 +++---- dashboards/resource_dashboard.go | 5 ++++ internal/providers/providers_test.go | 2 +- mlflow/resource_mlflow_experiment.go | 11 ++++++++- mlflow/resource_mlflow_model.go | 11 ++++++++- mlflow/resource_mlflow_webhook.go | 11 ++++++++- permissions/permissions_test.go | 2 +- .../resource_access_control_rule_set.go | 4 ++-- permissions/resource_permissions.go | 2 +- pipelines/resource_pipeline.go | 5 ++++ policies/resource_cluster_policy.go | 11 ++++++++- repos/resource_git_credential.go | 11 ++++++++- scim/data_current_user.go | 2 +- secrets/resource_secret.go | 6 ++--- secrets/resource_secret_acl.go | 6 ++--- secrets/resource_secret_scope.go | 11 +++++++-- serving/resource_model_serving.go | 11 ++++++++- ...ce_model_serving_provisioned_throughput.go | 11 ++++++++- settings/generic_setting.go | 12 +++++----- settings/resource_notification_destination.go | 6 ++++- sharing/data_shares_test.go | 2 +- sharing/resource_recipient.go | 12 +++++++++- sharing/resource_share.go | 9 ++++++-- sharing/resource_share_test.go | 20 ++++++++-------- sql/resource_alert.go | 11 ++++++++- sql/resource_query.go | 5 ++++ sql/resource_sql_alerts.go | 13 +++++++---- sql/resource_sql_endpoint.go | 3 +++ storage/resource_file.go | 6 ++--- .../resource_vector_search_endpoint.go | 11 ++++++++- vectorsearch/resource_vector_search_index.go | 11 ++++++++- workspace/resource_directory.go | 10 +++----- workspace/resource_global_init_script.go | 14 ++++------- workspace/resource_notebook.go | 2 +- workspace/resource_workspace_conf.go | 23 +++++++------------ workspace/resource_workspace_file.go | 12 ++++------ 36 files changed, 216 insertions(+), 96 deletions(-) diff --git a/common/client.go b/common/client.go index a7faa6524b..a9919c7d21 100644 --- a/common/client.go +++ b/common/client.go @@ -142,7 +142,7 @@ func (c *DatabricksClient) getWorkspaceClientForWorkspaceConfiguredProvider( // Provider is configured at workspace level and we get the // workspace client from the provider. if workspaceID == "" { - return c.WorkspaceClientUnifiedProvider(ctx, d) + return c.WorkspaceClient() } workspaceIDInt, err := parseWorkspaceID(workspaceID) @@ -152,7 +152,7 @@ func (c *DatabricksClient) getWorkspaceClientForWorkspaceConfiguredProvider( // Check if the workspace ID specified in the resource matches // the workspace ID of the provider configured workspace client. - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return nil, err } @@ -219,7 +219,7 @@ func (c *DatabricksClient) setCachedWorkspaceID(ctx context.Context, w *databric // over plugin framework. func (c *DatabricksClient) GetWorkspaceClient() (*databricks.WorkspaceClient, diag.Diagnostics) { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return nil, diag.Diagnostics{diag.NewErrorDiagnostic("Failed to get workspace client", err.Error())} } @@ -370,7 +370,7 @@ func (c *DatabricksClient) AccountOrWorkspaceRequest(accCallback func(*databrick } return accCallback(a) } else { - ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) + ws, err := c.WorkspaceClient() if err != nil { return err } diff --git a/dashboards/resource_dashboard.go b/dashboards/resource_dashboard.go index c8a3836b66..5d4db5f578 100644 --- a/dashboards/resource_dashboard.go +++ b/dashboards/resource_dashboard.go @@ -14,6 +14,7 @@ import ( type Dashboard struct { dashboards.Dashboard + common.Namespace EmbedCredentials bool `json:"embed_credentials,omitempty"` FilePath string `json:"file_path,omitempty"` Md5 string `json:"md5,omitempty"` @@ -56,6 +57,7 @@ func (Dashboard) CustomizeSchema(s *common.CustomizableSchema) *common.Customiza // DiffSuppressFunc s.SchemaPath("serialized_dashboard").SetCustomSuppressDiff(customDiffSerializedDashboard) + common.NamespaceCustomizeSchema(s) return s } @@ -212,6 +214,9 @@ func ResourceDashboard() common.Resource { return err }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/internal/providers/providers_test.go b/internal/providers/providers_test.go index c90d269624..320ab050a9 100644 --- a/internal/providers/providers_test.go +++ b/internal/providers/providers_test.go @@ -370,7 +370,7 @@ func TestConfig_OAuthFetchesToken(t *testing.T) { } func testOAuthFetchesToken(t *testing.T, c *common.DatabricksClient) { - ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) + ws, err := c.WorkspaceClient() require.NoError(t, err) bgCtx := context.Background() { diff --git a/mlflow/resource_mlflow_experiment.go b/mlflow/resource_mlflow_experiment.go index be89be862e..2636cd6e46 100644 --- a/mlflow/resource_mlflow_experiment.go +++ b/mlflow/resource_mlflow_experiment.go @@ -19,9 +19,14 @@ func experimentNameSuppressDiff(k, old, new string, d *schema.ResourceData) bool return false } +type MlflowExperiment struct { + ml.Experiment + common.Namespace +} + func ResourceMlflowExperiment() common.Resource { s := common.StructToSchema( - ml.Experiment{}, + MlflowExperiment{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { for _, p := range []string{"creation_time", "experiment_id", "last_update_time", "lifecycle_stage", "tags"} { common.CustomizeSchemaPath(m, p).SetComputed() @@ -34,6 +39,7 @@ func ResourceMlflowExperiment() common.Resource { Type: schema.TypeString, Deprecated: "Remove the description attribute as it no longer is used and will be removed in a future version.", } + common.NamespaceCustomizeSchemaMap(m) return m }) @@ -84,5 +90,8 @@ func ResourceMlflowExperiment() common.Resource { Schema: s, SchemaVersion: 0, Timeouts: &schema.ResourceTimeout{}, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/mlflow/resource_mlflow_model.go b/mlflow/resource_mlflow_model.go index 3feaa50623..60f3e20977 100644 --- a/mlflow/resource_mlflow_model.go +++ b/mlflow/resource_mlflow_model.go @@ -8,15 +8,21 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +type MlflowModel struct { + ml.CreateModelRequest + common.Namespace +} + func ResourceMlflowModel() common.Resource { s := common.StructToSchema( - ml.CreateModelRequest{}, + MlflowModel{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { s["name"].ForceNew = true s["registered_model_id"] = &schema.Schema{ Computed: true, Type: schema.TypeString, } + common.NamespaceCustomizeSchemaMap(s) return s }) @@ -78,5 +84,8 @@ func ResourceMlflowModel() common.Resource { return w.ModelRegistry.DeleteModel(ctx, req) }, Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/mlflow/resource_mlflow_webhook.go b/mlflow/resource_mlflow_webhook.go index 4e2837decb..b9ec550a94 100644 --- a/mlflow/resource_mlflow_webhook.go +++ b/mlflow/resource_mlflow_webhook.go @@ -27,9 +27,14 @@ func readWebHook(w *databricks.WorkspaceClient, ctx context.Context, ID string) return ml.RegistryWebhook{}, fmt.Errorf("webhook with ID %s isn't found", ID) } +type MlflowWebhook struct { + ml.CreateRegistryWebhook + common.Namespace +} + func ResourceMlflowWebhook() common.Resource { s := common.StructToSchema( - ml.CreateRegistryWebhook{}, + MlflowWebhook{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["status"].ValidateFunc = validation.StringInSlice([]string{"ACTIVE", "TEST_MODE", "DISABLED"}, true) if p, err := common.SchemaPath(m, "http_url_spec", "url"); err == nil { @@ -41,6 +46,7 @@ func ResourceMlflowWebhook() common.Resource { common.MustSchemaPath(m, "http_url_spec", "secret").Sensitive = true common.MustSchemaPath(m, "job_spec", "access_token").Sensitive = true + common.NamespaceCustomizeSchemaMap(m) return m }) @@ -109,5 +115,8 @@ func ResourceMlflowWebhook() common.Resource { return w.ModelRegistry.DeleteWebhook(ctx, ml.DeleteWebhookRequest{Id: d.Id()}) }, Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/permissions/permissions_test.go b/permissions/permissions_test.go index 109febe23e..563ee90585 100644 --- a/permissions/permissions_test.go +++ b/permissions/permissions_test.go @@ -364,7 +364,7 @@ func TestAccPermissions_Pipeline(t *testing.T) { }, acceptance.Step{ Template: policyTemplate, Check: acceptance.ResourceCheck("databricks_pipeline.this", func(ctx context.Context, c *common.DatabricksClient, id string) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() assert.NoError(t, err) pipeline, err := w.Pipelines.GetByPipelineId(context.Background(), id) assert.NoError(t, err) diff --git a/permissions/resource_access_control_rule_set.go b/permissions/resource_access_control_rule_set.go index 2f2772a4db..7d0b2a5466 100644 --- a/permissions/resource_access_control_rule_set.go +++ b/permissions/resource_access_control_rule_set.go @@ -32,7 +32,7 @@ func ResourceAccessControlRuleSet() common.Resource { } return accountClient.AccessControl.GetRuleSet(ctx, getRuleSetReq) } - workspaceClient, err := c.WorkspaceClientUnifiedProvider(ctx, d) + workspaceClient, err := c.WorkspaceClient() if err != nil { return nil, err } @@ -46,7 +46,7 @@ func ResourceAccessControlRuleSet() common.Resource { } return accountClient.AccessControl.UpdateRuleSet(ctx, updateRuleSetReq) } - workspaceClient, err := c.WorkspaceClientUnifiedProvider(ctx, d) + workspaceClient, err := c.WorkspaceClient() if err != nil { return nil, err } diff --git a/permissions/resource_permissions.go b/permissions/resource_permissions.go index 82a0ffce75..4655cc6f89 100644 --- a/permissions/resource_permissions.go +++ b/permissions/resource_permissions.go @@ -271,7 +271,7 @@ func ResourcePermissions() common.Resource { Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { var entity entity.PermissionsEntity common.DataToStructPointer(d, s, &entity) - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/pipelines/resource_pipeline.go b/pipelines/resource_pipeline.go index cf7ed87b20..f9e1050575 100644 --- a/pipelines/resource_pipeline.go +++ b/pipelines/resource_pipeline.go @@ -173,6 +173,7 @@ type Pipeline struct { State pipelines.PipelineState `json:"state,omitempty"` // Provides the URL to the pipeline in the Databricks UI. URL string `json:"url,omitempty"` + common.Namespace } func (Pipeline) Aliases() map[string]map[string]string { @@ -273,6 +274,7 @@ func (Pipeline) CustomizeSchema(s *common.CustomizableSchema) *common.Customizab // RequiredWith fields s.SchemaPath("ingestion_definition").SetRequiredWith([]string{"ingestion_definition.0.objects"}) + common.NamespaceCustomizeSchema(s) return s } @@ -335,5 +337,8 @@ func ResourcePipeline() common.Resource { Timeouts: &schema.ResourceTimeout{ Default: schema.DefaultTimeout(DefaultTimeout), }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/policies/resource_cluster_policy.go b/policies/resource_cluster_policy.go index 45ad1d99cf..130254b040 100644 --- a/policies/resource_cluster_policy.go +++ b/policies/resource_cluster_policy.go @@ -25,8 +25,13 @@ func isBuiltinPolicyFamily(ctx context.Context, w *databricks.WorkspaceClient, f return false, nil } +type ClusterPolicyResource struct { + compute.CreatePolicy + common.Namespace +} + var rcpSchema = common.StructToSchema( - compute.CreatePolicy{}, + ClusterPolicyResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["policy_id"] = &schema.Schema{ Type: schema.TypeString, @@ -41,6 +46,7 @@ var rcpSchema = common.StructToSchema( m["policy_family_id"].ConflictsWith = []string{"definition"} m["policy_family_definition_overrides"].RequiredWith = []string{"policy_family_id"} + common.NamespaceCustomizeSchemaMap(m) return m }) @@ -140,6 +146,9 @@ func ResourceClusterPolicy() common.Resource { } return w.ClusterPolicies.DeleteByPolicyId(ctx, d.Id()) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/repos/resource_git_credential.go b/repos/resource_git_credential.go index 1021de335a..6df34bbf43 100644 --- a/repos/resource_git_credential.go +++ b/repos/resource_git_credential.go @@ -19,8 +19,13 @@ func isOnlyOneGitCredentialForProviderError(err error) bool { (strings.Contains(errStr, "Only one Git credential is supported ") && strings.Contains(errStr, " at this time")) } +type GitCredentialResource struct { + workspace.CreateCredentialsRequest + common.Namespace +} + func ResourceGitCredential() common.Resource { - s := common.StructToSchema(workspace.CreateCredentialsRequest{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { + s := common.StructToSchema(GitCredentialResource{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { s["force"] = &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -30,6 +35,7 @@ func ResourceGitCredential() common.Resource { "GITLAB_TOKEN", // https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs "AZDO_PERSONAL_ACCESS_TOKEN", // https://registry.terraform.io/providers/microsoft/azuredevops/latest/docs }, nil) + common.NamespaceCustomizeSchemaMap(s) return s }) @@ -119,5 +125,8 @@ func ResourceGitCredential() common.Resource { } return w.GitCredentials.DeleteByCredentialId(ctx, cred_id) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/scim/data_current_user.go b/scim/data_current_user.go index 580cf95a7f..7a6066c1bd 100644 --- a/scim/data_current_user.go +++ b/scim/data_current_user.go @@ -46,7 +46,7 @@ func DataSourceCurrentUser() common.Resource { }, }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/secrets/resource_secret.go b/secrets/resource_secret.go index a1de1ecc1b..e4507c2692 100644 --- a/secrets/resource_secret.go +++ b/secrets/resource_secret.go @@ -70,7 +70,7 @@ func ResourceSecret() common.Resource { return common.Resource{ Schema: s, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -88,7 +88,7 @@ func ResourceSecret() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -104,7 +104,7 @@ func ResourceSecret() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/secrets/resource_secret_acl.go b/secrets/resource_secret_acl.go index 4c89d6d75e..e271c651d4 100644 --- a/secrets/resource_secret_acl.go +++ b/secrets/resource_secret_acl.go @@ -41,7 +41,7 @@ func ResourceSecretACL() common.Resource { return true }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -58,7 +58,7 @@ func ResourceSecretACL() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -76,7 +76,7 @@ func ResourceSecretACL() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/secrets/resource_secret_scope.go b/secrets/resource_secret_scope.go index d60a529762..041590cea0 100644 --- a/secrets/resource_secret_scope.go +++ b/secrets/resource_secret_scope.go @@ -15,11 +15,15 @@ import ( ) // SecretScope is a struct that encapsulates the secret scope -type SecretScope workspace.CreateScope +type SecretScope struct { + workspace.CreateScope + common.Namespace +} func (s SecretScope) CustomizeSchema(m *common.CustomizableSchema) *common.CustomizableSchema { m.SchemaPath("name").SetValidateFunc(validScope) m.SchemaPath("backend_type").SetComputed() + common.NamespaceCustomizeSchema(m) return m } @@ -79,7 +83,7 @@ func ResourceSecretScope() common.Resource { } else { scope.ScopeBackendType = "DATABRICKS" } - if err := w.Secrets.CreateScope(ctx, workspace.CreateScope(scope)); err != nil { + if err := w.Secrets.CreateScope(ctx, workspace.CreateScope(scope.CreateScope)); err != nil { return err } d.SetId(scope.Scope) @@ -103,5 +107,8 @@ func ResourceSecretScope() common.Resource { } return w.Secrets.DeleteScope(ctx, workspace.DeleteScope{Scope: d.Id()}) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/serving/resource_model_serving.go b/serving/resource_model_serving.go index d4e8ab745c..043e7e68c2 100644 --- a/serving/resource_model_serving.go +++ b/serving/resource_model_serving.go @@ -172,9 +172,14 @@ func cleanWorkloadSize(s map[string]*schema.Schema, d *schema.ResourceData, apiR } } +type ModelServingResource struct { + serving.CreateServingEndpoint + common.Namespace +} + func ResourceModelServing() common.Resource { s := common.StructToSchema( - serving.CreateServingEndpoint{}, + ModelServingResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { // Use the newer CustomizeSchemaPath approach for better maintainability common.CustomizeSchemaPath(m, "name").SetForceNew() @@ -222,6 +227,7 @@ func ResourceModelServing() common.Resource { Computed: true, Type: schema.TypeString, } + common.NamespaceCustomizeSchemaMap(m) return m }) @@ -321,5 +327,8 @@ func ResourceModelServing() common.Resource { Create: schema.DefaultTimeout(DefaultProvisionTimeout), Update: schema.DefaultTimeout(DefaultProvisionTimeout), }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/serving/resource_model_serving_provisioned_throughput.go b/serving/resource_model_serving_provisioned_throughput.go index c0c3605560..2cdff43cb4 100644 --- a/serving/resource_model_serving_provisioned_throughput.go +++ b/serving/resource_model_serving_provisioned_throughput.go @@ -14,9 +14,14 @@ const ( defaultPtProvisionTimeout = 10 * time.Minute ) +type ModelServingProvisionedThroughputResource struct { + serving.CreatePtEndpointRequest + common.Namespace +} + func ResourceModelServingProvisionedThroughput() common.Resource { s := common.StructToSchema( - serving.CreatePtEndpointRequest{}, + ModelServingProvisionedThroughputResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(m, "name").SetForceNew() common.CustomizeSchemaPath(m, "config", "traffic_config").SetComputed() @@ -34,6 +39,7 @@ func ResourceModelServingProvisionedThroughput() common.Resource { Computed: true, Type: schema.TypeString, } + common.NamespaceCustomizeSchemaMap(m) return m }) @@ -124,5 +130,8 @@ func ResourceModelServingProvisionedThroughput() common.Resource { Create: schema.DefaultTimeout(defaultPtProvisionTimeout), Update: schema.DefaultTimeout(defaultPtProvisionTimeout), }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/settings/generic_setting.go b/settings/generic_setting.go index 1e326436e8..91108b86eb 100644 --- a/settings/generic_setting.go +++ b/settings/generic_setting.go @@ -288,7 +288,7 @@ func (aw accountWorkspaceSetting[T]) Read(ctx context.Context, c *common.Databri } return aw.readAccFunc(ctx, a, etag) } else { - ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) + ws, err := c.WorkspaceClient() if err != nil { return nil, err } @@ -303,7 +303,7 @@ func (aw accountWorkspaceSetting[T]) Update(ctx context.Context, c *common.Datab } return aw.updateAccFunc(ctx, a, t) } else { - ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) + ws, err := c.WorkspaceClient() if err != nil { return "", err } @@ -318,7 +318,7 @@ func (aw accountWorkspaceSetting[T]) Delete(ctx context.Context, c *common.Datab } return aw.deleteAccFunc(ctx, a, etag) } else { - ws, err := c.WorkspaceClientUnifiedProvider(ctx, d) + ws, err := c.WorkspaceClient() if err != nil { return "", err } @@ -366,7 +366,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R var res string switch defn := defn.(type) { case workspaceSettingDefinition[T]: - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -425,7 +425,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R var res *T switch defn := defn.(type) { case workspaceSettingDefinition[T]: - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -472,7 +472,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R updateETag := func(req *string, newEtag string) { *req = newEtag } switch defn := defn.(type) { case workspaceSettingDefinition[T]: - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/settings/resource_notification_destination.go b/settings/resource_notification_destination.go index 778462cff3..0bf2b11360 100644 --- a/settings/resource_notification_destination.go +++ b/settings/resource_notification_destination.go @@ -108,6 +108,7 @@ func Delete(ctx context.Context, d *schema.ResourceData, w *databricks.Workspace type NDStruct struct { settings.NotificationDestination + common.Namespace } func (NDStruct) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { @@ -157,7 +158,7 @@ func (NDStruct) CustomizeSchema(s *common.CustomizableSchema) *common.Customizab s.SchemaPath("config", "slack", "url").SetSensitive() s.SchemaPath("config", "slack", "oauth_token").SetSensitive() s.SchemaPath("config", "slack", "channel_id").SetSensitive() - + common.NamespaceCustomizeSchema(s) return s } @@ -195,5 +196,8 @@ func ResourceNotificationDestination() common.Resource { } return Delete(ctx, d, w) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/sharing/data_shares_test.go b/sharing/data_shares_test.go index 8afddc0b33..7848718eb6 100644 --- a/sharing/data_shares_test.go +++ b/sharing/data_shares_test.go @@ -16,7 +16,7 @@ func TestSharesData(t *testing.T) { Response: Shares{ Shares: []ShareInfo{ { - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "a", Objects: []sharing.SharedDataObject{ { diff --git a/sharing/resource_recipient.go b/sharing/resource_recipient.go index 9ba1ffbc66..f90aa8da4d 100644 --- a/sharing/resource_recipient.go +++ b/sharing/resource_recipient.go @@ -21,8 +21,13 @@ func recepientPropertiesSuppressDiff(k, old, new string, d *schema.ResourceData) return false } +type RecipientResource struct { + sharing.RecipientInfo + common.Namespace +} + func ResourceRecipient() common.Resource { - recipientSchema := common.StructToSchema(sharing.RecipientInfo{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { + recipientSchema := common.StructToSchema(RecipientResource{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(s, "authentication_type").SetForceNew().SetRequired().SetValidateFunc( validation.StringInSlice([]string{"TOKEN", "DATABRICKS"}, false)) common.CustomizeSchemaPath(s, "sharing_code").SetSuppressDiff().SetForceNew().SetSensitive() @@ -43,6 +48,8 @@ func ResourceRecipient() common.Resource { common.CustomizeSchemaPath(s, "tokens", path).SetReadOnly() } + common.NamespaceCustomizeSchemaMap(s) + return s }) return common.Resource{ @@ -128,5 +135,8 @@ func ResourceRecipient() common.Resource { } return w.Recipients.DeleteByName(ctx, d.Id()) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/sharing/resource_share.go b/sharing/resource_share.go index e4801f46eb..4697e4e1e9 100644 --- a/sharing/resource_share.go +++ b/sharing/resource_share.go @@ -12,6 +12,7 @@ import ( type ShareInfo struct { sharing.ShareInfo + common.Namespace } func (ShareInfo) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { @@ -37,6 +38,7 @@ func (ShareInfo) CustomizeSchema(s *common.CustomizableSchema) *common.Customiza s.SchemaPath("object", "added_by").SetComputed() s.SchemaPath("object", "partition", "value", "op").SetRequired() s.SchemaPath("object", "partition", "value", "name").SetRequired() + common.NamespaceCustomizeSchema(s) return s } @@ -193,7 +195,7 @@ func ResourceShare() common.Resource { Name: d.Id(), IncludeSharedData: true, }) - si := ShareInfo{*shareInfo} + si := ShareInfo{ShareInfo: *shareInfo} si.sortSharesByName() si.suppressCDFEnabledDiff() if err != nil { @@ -216,7 +218,7 @@ func ResourceShare() common.Resource { return err } - beforeSi := ShareInfo{*si} + beforeSi := ShareInfo{ShareInfo: *si} beforeSi.sortSharesByName() beforeSi.suppressCDFEnabledDiff() var afterSi ShareInfo @@ -269,5 +271,8 @@ func ResourceShare() common.Resource { } return w.Shares.DeleteByName(ctx, d.Id()) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/sharing/resource_share_test.go b/sharing/resource_share_test.go index c4f6b9b409..6a060a0857 100644 --- a/sharing/resource_share_test.go +++ b/sharing/resource_share_test.go @@ -350,7 +350,7 @@ func TestUpdateShare(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Owner: "admin", Comment: "cba", @@ -408,7 +408,7 @@ func TestUpdateShareRollback(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Objects: []sharing.SharedDataObject{ { @@ -486,7 +486,7 @@ func TestUpdateShareRollback(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Comment: "cba", Objects: []sharing.SharedDataObject{ @@ -546,7 +546,7 @@ func TestUpdateShare_NoChanges(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Objects: []sharing.SharedDataObject{ { @@ -566,7 +566,7 @@ func TestUpdateShare_NoChanges(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Objects: []sharing.SharedDataObject{ { @@ -607,7 +607,7 @@ func TestCreateShare_ThrowError(t *testing.T) { Method: "POST", Resource: "/api/2.1/unity-catalog/shares", ExpectedRequest: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "a", }, }, @@ -645,12 +645,12 @@ func TestCreateShareButPatchFails(t *testing.T) { Method: "POST", Resource: "/api/2.1/unity-catalog/shares", ExpectedRequest: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "a", }, }, Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "a", }, }, @@ -717,7 +717,7 @@ func TestUpdateShareComplexDiff(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Objects: []sharing.SharedDataObject{ { @@ -752,7 +752,7 @@ func TestUpdateShareComplexDiff(t *testing.T) { Method: "GET", Resource: "/api/2.1/unity-catalog/shares/abc?include_shared_data=true", Response: ShareInfo{ - sharing.ShareInfo{ + ShareInfo: sharing.ShareInfo{ Name: "abc", Objects: []sharing.SharedDataObject{ { diff --git a/sql/resource_alert.go b/sql/resource_alert.go index eff321f3ef..3aa019ca46 100644 --- a/sql/resource_alert.go +++ b/sql/resource_alert.go @@ -11,8 +11,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) +type AlertResource struct { + sql.Alert + common.Namespace +} + func ResourceAlert() common.Resource { - s := common.StructToSchema(sql.Alert{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { + s := common.StructToSchema(AlertResource{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(m, "display_name").SetRequired() common.CustomizeSchemaPath(m, "query_id").SetRequired() common.CustomizeSchemaPath(m, "condition").SetRequired() @@ -45,6 +50,7 @@ func ResourceAlert() common.Resource { common.CustomizeSchemaPath(m, "state").SetReadOnly() common.CustomizeSchemaPath(m, "trigger_time").SetReadOnly() common.CustomizeSchemaPath(m, "update_time").SetReadOnly() + common.NamespaceCustomizeSchemaMap(m) return m }) @@ -124,6 +130,9 @@ func ResourceAlert() common.Resource { } return w.Alerts.DeleteById(ctx, d.Id()) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, Schema: s, } } diff --git a/sql/resource_query.go b/sql/resource_query.go index 7446dd8285..5450276fcd 100644 --- a/sql/resource_query.go +++ b/sql/resource_query.go @@ -14,6 +14,7 @@ import ( // Need a struct for Query because there are aliases we need and it'll be needed in the create method. type QueryStruct struct { sql.Query + common.Namespace } var queryAliasMap = map[string]string{ @@ -58,6 +59,7 @@ func (QueryStruct) CustomizeSchema(m *common.CustomizableSchema) *common.Customi // for _, f := range valuesAlof { // m.SchemaPath("parameter", strings.TrimPrefix(f, "parameter.0.")).SetAtLeastOneOf(valuesAlof) // } + common.NamespaceCustomizeSchema(m) return m } @@ -167,5 +169,8 @@ func ResourceQuery() common.Resource { return w.Queries.DeleteById(ctx, d.Id()) }, Schema: s, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/sql/resource_sql_alerts.go b/sql/resource_sql_alerts.go index ee0bcbfe37..02ff629930 100644 --- a/sql/resource_sql_alerts.go +++ b/sql/resource_sql_alerts.go @@ -30,6 +30,7 @@ type AlertEntity struct { Parent string `json:"parent,omitempty" tf:"suppress_diff,force_new"` CreatedAt string `json:"created_at,omitempty" tf:"computed"` UpdatedAt string `json:"updated_at,omitempty" tf:"computed"` + common.Namespace } func (a *AlertEntity) toCreateAlertApiObject(s map[string]*schema.Schema, data *schema.ResourceData) (sql.CreateAlert, error) { @@ -125,12 +126,13 @@ func (a *AlertEntity) fromAPIObject(apiAlert *sql.LegacyAlert, s map[string]*sch func ResourceSqlAlert() common.Resource { s := common.StructToSchema(AlertEntity{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { common.MustSchemaPath(m, "options", "op").ValidateFunc = validation.StringInSlice([]string{">", ">=", "<", "<=", "==", "!="}, true) + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ Create: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClientUnifiedProvider(ctx, data) if err != nil { return err } @@ -147,7 +149,7 @@ func ResourceSqlAlert() common.Resource { return nil }, Read: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClientUnifiedProvider(ctx, data) if err != nil { return err } @@ -160,7 +162,7 @@ func ResourceSqlAlert() common.Resource { return a.fromAPIObject(apiAlert, s, data) }, Update: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClientUnifiedProvider(ctx, data) if err != nil { return err } @@ -172,7 +174,7 @@ func ResourceSqlAlert() common.Resource { return w.AlertsLegacy.Update(ctx, ca) }, Delete: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClientUnifiedProvider(ctx, data) if err != nil { return err } @@ -180,5 +182,8 @@ func ResourceSqlAlert() common.Resource { }, Schema: s, DeprecationMessage: "This resource is deprecated and will be removed in the future. Please use the `databricks_alert` resource instead.", + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/sql/resource_sql_endpoint.go b/sql/resource_sql_endpoint.go index 1eba939e16..7f49e48ba0 100644 --- a/sql/resource_sql_endpoint.go +++ b/sql/resource_sql_endpoint.go @@ -21,6 +21,7 @@ var ( type SqlWarehouse struct { sql.GetWarehouseResponse + common.Namespace // The data source ID is not part of the endpoint API response. // We manually resolve it by retrieving the list of data sources @@ -98,6 +99,7 @@ func ResourceSqlEndpoint() common.Resource { }, } + common.NamespaceCustomizeSchemaMap(m) return m }) return common.Resource{ @@ -176,6 +178,7 @@ func ResourceSqlEndpoint() common.Resource { }, Schema: s, CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + common.NamespaceCustomizeDiff(d) return d.Clear("health") }, } diff --git a/storage/resource_file.go b/storage/resource_file.go index 14be2c7ebb..85121b3d2e 100644 --- a/storage/resource_file.go +++ b/storage/resource_file.go @@ -52,7 +52,7 @@ func getContentReader(data *schema.ResourceData) (*hashReadCloser, error) { } func upload(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient, path string) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -104,7 +104,7 @@ func ResourceFile() common.Resource { return nil }, Read: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -127,7 +127,7 @@ func ResourceFile() common.Resource { return upload(ctx, data, c, path) }, Delete: func(ctx context.Context, data *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index 1909ba35c8..d807cf5129 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -14,9 +14,14 @@ import ( const defaultEndpointProvisionTimeout = 75 * time.Minute const deleteCallTimeout = 10 * time.Second +type VectorSearchEndpointResource struct { + vectorsearch.EndpointInfo + common.Namespace +} + func ResourceVectorSearchEndpoint() common.Resource { s := common.StructToSchema( - vectorsearch.EndpointInfo{}, + VectorSearchEndpointResource{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(s, "name").SetRequired().SetForceNew() common.CustomizeSchemaPath(s, "endpoint_type").SetRequired().SetForceNew() @@ -36,6 +41,7 @@ func ResourceVectorSearchEndpoint() common.Resource { Computed: true, }) + common.NamespaceCustomizeSchemaMap(s) return s }) @@ -110,5 +116,8 @@ func ResourceVectorSearchEndpoint() common.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(defaultEndpointProvisionTimeout), }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/vectorsearch/resource_vector_search_index.go b/vectorsearch/resource_vector_search_index.go index b853c2fdab..b719fd67ee 100644 --- a/vectorsearch/resource_vector_search_index.go +++ b/vectorsearch/resource_vector_search_index.go @@ -45,9 +45,14 @@ func waitForSearchIndexCreation(w *databricks.WorkspaceClient, ctx context.Conte }) } +type VectorSearchIndexResource struct { + vectorsearch.VectorIndex + common.Namespace +} + func ResourceVectorSearchIndex() common.Resource { s := common.StructToSchema( - vectorsearch.VectorIndex{}, + VectorSearchIndexResource{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { common.MustSchemaPath(s, "delta_sync_index_spec", "embedding_vector_columns").MinItems = 1 exof := []string{"delta_sync_index_spec", "direct_access_index_spec"} @@ -62,6 +67,7 @@ func ResourceVectorSearchIndex() common.Resource { common.CustomizeSchemaPath(s, "name").SetRequired() common.CustomizeSchemaPath(s, "index_type").SetRequired() common.CustomizeSchemaPath(s, "delta_sync_index_spec", "pipeline_id").SetReadOnly() + common.NamespaceCustomizeSchemaMap(s) return s }) @@ -116,5 +122,8 @@ func ResourceVectorSearchIndex() common.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(defaultIndexProvisionTimeout), }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + return common.NamespaceCustomizeDiff(d) + }, } } diff --git a/workspace/resource_directory.go b/workspace/resource_directory.go index eebc58727e..2ed4bcc4df 100644 --- a/workspace/resource_directory.go +++ b/workspace/resource_directory.go @@ -40,10 +40,9 @@ func ResourceDirectory() common.Resource { Computed: true, }, } - common.NamespaceCustomizeSchemaMap(s) directoryRead := func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } @@ -67,11 +66,8 @@ func ResourceDirectory() common.Resource { return common.Resource{ Schema: s, - CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { - return common.NamespaceCustomizeDiff(d) - }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } @@ -87,7 +83,7 @@ func ResourceDirectory() common.Resource { Read: directoryRead, Update: directoryRead, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } diff --git a/workspace/resource_global_init_script.go b/workspace/resource_global_init_script.go index 16b59e03b1..37d915941f 100644 --- a/workspace/resource_global_init_script.go +++ b/workspace/resource_global_init_script.go @@ -44,12 +44,7 @@ func ResourceGlobalInitScript() common.Resource { }, } s := FileContentSchemaWithoutPath(extra) - common.NamespaceCustomizeSchemaMap(s) return common.Resource{ - Schema: s, - CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { - return common.NamespaceCustomizeDiff(d) - }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { content, err := ReadContent(d) if err != nil { @@ -59,7 +54,7 @@ func ResourceGlobalInitScript() common.Resource { return fmt.Errorf("size of the global init script (%d bytes) exceeds maximal allowed (%d bytes)", contentLen, maxScriptSize) } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -76,7 +71,7 @@ func ResourceGlobalInitScript() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -95,7 +90,7 @@ func ResourceGlobalInitScript() common.Resource { return fmt.Errorf("size of the global init script (%d bytes) exceeds maximal allowed (%d bytes)", contentLen, maxScriptSize) } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -108,12 +103,13 @@ func ResourceGlobalInitScript() common.Resource { }) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } return w.GlobalInitScripts.DeleteByScriptId(ctx, d.Id()) }, + Schema: s, SchemaVersion: 1, Timeouts: &schema.ResourceTimeout{}, } diff --git a/workspace/resource_notebook.go b/workspace/resource_notebook.go index 38d86fb2d3..1bff5895ff 100644 --- a/workspace/resource_notebook.go +++ b/workspace/resource_notebook.go @@ -341,7 +341,7 @@ func ResourceNotebook() common.Resource { oldFormat = "SOURCE" } } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } diff --git a/workspace/resource_workspace_conf.go b/workspace/resource_workspace_conf.go index 69fb70ef9b..41e720b1c2 100644 --- a/workspace/resource_workspace_conf.go +++ b/workspace/resource_workspace_conf.go @@ -64,7 +64,7 @@ func applyWorkspaceConf(ctx context.Context, d *schema.ResourceData, c *common.D } } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -96,7 +96,7 @@ func updateWorkspaceConf(ctx context.Context, d *schema.ResourceData, c *common. } func deleteWorkspaceConf(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -222,7 +222,7 @@ func ResourceWorkspaceConf() common.Resource { Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { config := d.Get("custom_config").(map[string]any) log.Printf("[DEBUG] Config available in state: %v", config) - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -244,18 +244,11 @@ func ResourceWorkspaceConf() common.Resource { return d.Set("custom_config", config) }, Delete: deleteWorkspaceConf, - Schema: func() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "custom_config": { - Type: schema.TypeMap, - Optional: true, - }, - } - common.NamespaceCustomizeSchemaMap(s) - return s - }(), - CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { - return common.NamespaceCustomizeDiff(d) + Schema: map[string]*schema.Schema{ + "custom_config": { + Type: schema.TypeMap, + Optional: true, + }, }, } } diff --git a/workspace/resource_workspace_file.go b/workspace/resource_workspace_file.go index ddebad3bb9..8a72107e1d 100644 --- a/workspace/resource_workspace_file.go +++ b/workspace/resource_workspace_file.go @@ -29,19 +29,15 @@ func ResourceWorkspaceFile() common.Resource { Computed: true, }, }) - common.NamespaceCustomizeSchemaMap(s) return common.Resource{ Schema: s, SchemaVersion: 1, - CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { - return common.NamespaceCustomizeDiff(d) - }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { content, err := ReadContent(d) if err != nil { return err } - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } @@ -72,7 +68,7 @@ func ResourceWorkspaceFile() common.Resource { return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } @@ -86,7 +82,7 @@ func ResourceWorkspaceFile() common.Resource { return common.StructToData(objectStatus, s, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } @@ -103,7 +99,7 @@ func ResourceWorkspaceFile() common.Resource { }) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - client, err := c.WorkspaceClientUnifiedProvider(ctx, d) + client, err := c.WorkspaceClient() if err != nil { return err } From e173af381cbb12ebfc27de95d2b81867bae7d2a1 Mon Sep 17 00:00:00 2001 From: Tanmay Rustagi Date: Thu, 30 Oct 2025 17:19:02 +0530 Subject: [PATCH 3/3] - --- catalog/resource_catalog.go | 56 +++++++++++++++++------------------ catalog/resource_sql_table.go | 12 ++++---- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/catalog/resource_catalog.go b/catalog/resource_catalog.go index 9445dedaf7..339367c042 100644 --- a/catalog/resource_catalog.go +++ b/catalog/resource_catalog.go @@ -68,34 +68,6 @@ func ResourceCatalog() common.Resource { }) return common.Resource{ Schema: catalogSchema, - CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { - // The only scenario in which we can update options is for the `authorized_paths` key. Any - // other changes to the options field will result in an error. - if d.HasChange("options") { - old, new := d.GetChange("options") - oldMap := old.(map[string]interface{}) - newMap := new.(map[string]interface{}) - delete(oldMap, "authorized_paths") - delete(newMap, "authorized_paths") - // If any attribute other than `authorized_paths` is removed, the resource should be recreated. - for k := range oldMap { - if _, ok := newMap[k]; !ok { - if err := d.ForceNew("options"); err != nil { - return err - } - } - } - // If any attribute other than `authorized_paths` is added or changed, the resource should be recreated. - for k, v := range newMap { - if oldV, ok := oldMap[k]; !ok || oldV != v { - if err := d.ForceNew("options"); err != nil { - return err - } - } - } - } - return common.NamespaceCustomizeDiff(d) - }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { w, err := c.WorkspaceClientUnifiedProvider(ctx, d) if err != nil { @@ -250,5 +222,33 @@ func ResourceCatalog() common.Resource { } return w.Catalogs.Delete(ctx, catalog.DeleteCatalogRequest{Force: force, Name: d.Id()}) }, + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error { + // The only scenario in which we can update options is for the `authorized_paths` key. Any + // other changes to the options field will result in an error. + if d.HasChange("options") { + old, new := d.GetChange("options") + oldMap := old.(map[string]interface{}) + newMap := new.(map[string]interface{}) + delete(oldMap, "authorized_paths") + delete(newMap, "authorized_paths") + // If any attribute other than `authorized_paths` is removed, the resource should be recreated. + for k := range oldMap { + if _, ok := newMap[k]; !ok { + if err := d.ForceNew("options"); err != nil { + return err + } + } + } + // If any attribute other than `authorized_paths` is added or changed, the resource should be recreated. + for k, v := range newMap { + if oldV, ok := oldMap[k]; !ok || oldV != v { + if err := d.ForceNew("options"); err != nil { + return err + } + } + } + } + return nil + }, } } diff --git a/catalog/resource_sql_table.go b/catalog/resource_sql_table.go index f4bf400e52..99019c7868 100644 --- a/catalog/resource_sql_table.go +++ b/catalog/resource_sql_table.go @@ -65,7 +65,6 @@ type SqlTableInfo struct { WarehouseID string `json:"warehouse_id,omitempty"` Owner string `json:"owner,omitempty" tf:"computed"` TableID string `json:"table_id" tf:"computed"` - common.Namespace exec common.CommandExecutor sqlExec sql.StatementExecutionInterface @@ -93,7 +92,6 @@ func (ti SqlTableInfo) CustomizeSchema(s *common.CustomizableSchema) *common.Cus s.SchemaPath("column", "type").SetCustomSuppressDiff(func(k, old, new string, d *schema.ResourceData) bool { return getColumnType(old) == getColumnType(new) }) - common.NamespaceCustomizeSchema(s) return s } @@ -177,7 +175,7 @@ func (ti *SqlTableInfo) initCluster(ctx context.Context, d *schema.ResourceData, } } ti.exec = c.CommandExecutor(ctx) - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -665,7 +663,7 @@ func ResourceSqlTable() common.Resource { if d.HasChange("comment") && d.Get("table_type") == "VIEW" { d.ForceNew("comment") } - return common.NamespaceCustomizeDiff(d) + return nil }, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { var ti = new(SqlTableInfo) @@ -677,7 +675,7 @@ func ResourceSqlTable() common.Resource { return err } if ti.Owner != "" { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -697,7 +695,7 @@ func ResourceSqlTable() common.Resource { if err != nil { return err } - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err } @@ -731,7 +729,7 @@ func ResourceSqlTable() common.Resource { return common.StructToData(ti, tableSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { - w, err := c.WorkspaceClientUnifiedProvider(ctx, d) + w, err := c.WorkspaceClient() if err != nil { return err }