|
6 | 6 | "log" |
7 | 7 | "strings" |
8 | 8 |
|
| 9 | + "github.com/databricks/databricks-sdk-go" |
9 | 10 | "github.com/databricks/databricks-sdk-go/service/catalog" |
10 | 11 | "github.com/databricks/terraform-provider-databricks/common" |
11 | 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
@@ -70,10 +71,7 @@ func ResourceSystemSchema() common.Resource { |
70 | 71 | log.Printf("[WARN] %s is auto enabled, ignoring it", old) |
71 | 72 | return nil |
72 | 73 | } |
73 | | - err = w.SystemSchemas.Disable(ctx, catalog.DisableRequest{ |
74 | | - MetastoreId: metastoreSummary.MetastoreId, |
75 | | - SchemaName: old, |
76 | | - }) |
| 74 | + err = safeDisable(ctx, w, metastoreSummary.MetastoreId, old) |
77 | 75 | if err != nil { |
78 | 76 | return err |
79 | 77 | } |
@@ -143,10 +141,22 @@ func ResourceSystemSchema() common.Resource { |
143 | 141 | if err != nil { |
144 | 142 | return err |
145 | 143 | } |
146 | | - return w.SystemSchemas.Disable(ctx, catalog.DisableRequest{ |
147 | | - MetastoreId: metastoreSummary.MetastoreId, |
148 | | - SchemaName: schemaName, |
149 | | - }) |
| 144 | + return safeDisable(ctx, w, metastoreSummary.MetastoreId, schemaName) |
150 | 145 | }, |
151 | 146 | } |
152 | 147 | } |
| 148 | + |
| 149 | +func safeDisable(ctx context.Context, w *databricks.WorkspaceClient, metastoreId, schemaName string) error { |
| 150 | + err := w.SystemSchemas.Disable(ctx, catalog.DisableRequest{ |
| 151 | + MetastoreId: metastoreId, |
| 152 | + SchemaName: schemaName, |
| 153 | + }) |
| 154 | + if err != nil { |
| 155 | + //ignore "<schema-name> system schema can only be disabled by Databricks" error |
| 156 | + if !strings.Contains(err.Error(), "can only be disabled by Databricks") { |
| 157 | + return err |
| 158 | + } |
| 159 | + log.Printf("[WARN] %s can be disabled only by Databricks, ignoring it", schemaName) |
| 160 | + } |
| 161 | + return nil |
| 162 | +} |
0 commit comments