diff --git a/catalog/resource_system_schema.go b/catalog/resource_system_schema.go index 06b1ff24d..6c033fab8 100644 --- a/catalog/resource_system_schema.go +++ b/catalog/resource_system_schema.go @@ -93,10 +93,21 @@ func ResourceSystemSchema() common.Resource { if err != nil { return err } + // only track enabled/legacy schemas + if schema.State != catalog.SystemSchemaInfoStateEnableCompleted && + schema.State != catalog.SystemSchemaInfoStateEnableInitialized && + schema.State != catalog.SystemSchemaInfoStateUnavailable { + log.Printf("[WARN] %s is not enabled, ignoring it", schemaName) + d.SetId("") + return nil + } + d.Set("full_name", fmt.Sprintf("system.%s", schemaName)) return nil } } + log.Printf("[WARN] %s does not exist, ignoring it", schemaName) + d.SetId("") return nil }, Update: createOrUpdate, diff --git a/catalog/resource_system_schema_test.go b/catalog/resource_system_schema_test.go index e576eec07..8973d8727 100644 --- a/catalog/resource_system_schema_test.go +++ b/catalog/resource_system_schema_test.go @@ -239,6 +239,74 @@ func TestSystemSchemaRead_Error(t *testing.T) { assert.Equal(t, "abc|access", d.Id(), "Id should not be empty for error reads") } +func TestSystemSchemaRead_NotEnabled(t *testing.T) { + d, err := qa.ResourceFixture{ + Fixtures: []qa.HTTPFixture{ + { + Method: http.MethodGet, + Resource: "/api/2.1/unity-catalog/metastore_summary", + Response: catalog.GetMetastoreSummaryResponse{ + MetastoreId: "abc", + }, + }, + { + Method: http.MethodGet, + Resource: "/api/2.1/unity-catalog/metastores/abc/systemschemas?", + Response: catalog.ListSystemSchemasResponse{ + Schemas: []catalog.SystemSchemaInfo{ + { + Schema: "access", + State: catalog.SystemSchemaInfoStateAvailable, + }, + { + Schema: "billing", + State: catalog.SystemSchemaInfoStateEnableCompleted, + }, + }, + }, + }, + }, + Resource: ResourceSystemSchema(), + Read: true, + Removed: true, + ID: "abc|access", + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "", d.Id(), "Id should be empty if a schema is not enabled") +} + +func TestSystemSchemaRead_NotExists(t *testing.T) { + d, err := qa.ResourceFixture{ + Fixtures: []qa.HTTPFixture{ + { + Method: http.MethodGet, + Resource: "/api/2.1/unity-catalog/metastore_summary", + Response: catalog.GetMetastoreSummaryResponse{ + MetastoreId: "abc", + }, + }, + { + Method: http.MethodGet, + Resource: "/api/2.1/unity-catalog/metastores/abc/systemschemas?", + Response: catalog.ListSystemSchemasResponse{ + Schemas: []catalog.SystemSchemaInfo{ + { + Schema: "billing", + State: catalog.SystemSchemaInfoStateEnableCompleted, + }, + }, + }, + }, + }, + Resource: ResourceSystemSchema(), + Read: true, + Removed: true, + ID: "abc|access", + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "", d.Id(), "Id should be empty if a schema does not exist") +} + func TestSystemSchemaDelete(t *testing.T) { d, err := qa.ResourceFixture{ Fixtures: []qa.HTTPFixture{