Skip to content

Commit f60c6d5

Browse files
authored
[Fix] Don't fail delete when databricks_system_schema can be disabled only by Databricks (#4727)
## Changes <!-- Summary of your changes that are easy to understand --> Also rewrote corresponding tests to use the mock framework from Go SDK ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [x] covered with integration tests in `internal/acceptance` - [x] using Go SDK - [ ] using TF Plugin Framework
1 parent 2dd6237 commit f60c6d5

File tree

4 files changed

+178
-265
lines changed

4 files changed

+178
-265
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Bug Fixes
88

9+
* Don't fail delete when `databricks_system_schema` can be disabled only by Databricks [#4727](https://github.com/databricks/terraform-provider-databricks/pull/4727)
10+
911
### Documentation
1012

1113
### Exporter

catalog/resource_system_schema.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"strings"
88

9+
"github.com/databricks/databricks-sdk-go"
910
"github.com/databricks/databricks-sdk-go/service/catalog"
1011
"github.com/databricks/terraform-provider-databricks/common"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -70,10 +71,7 @@ func ResourceSystemSchema() common.Resource {
7071
log.Printf("[WARN] %s is auto enabled, ignoring it", old)
7172
return nil
7273
}
73-
err = w.SystemSchemas.Disable(ctx, catalog.DisableRequest{
74-
MetastoreId: metastoreSummary.MetastoreId,
75-
SchemaName: old,
76-
})
74+
err = safeDisable(ctx, w, metastoreSummary.MetastoreId, old)
7775
if err != nil {
7876
return err
7977
}
@@ -143,10 +141,22 @@ func ResourceSystemSchema() common.Resource {
143141
if err != nil {
144142
return err
145143
}
146-
return w.SystemSchemas.Disable(ctx, catalog.DisableRequest{
147-
MetastoreId: metastoreSummary.MetastoreId,
148-
SchemaName: schemaName,
149-
})
144+
return safeDisable(ctx, w, metastoreSummary.MetastoreId, schemaName)
150145
},
151146
}
152147
}
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

Comments
 (0)