Skip to content

Commit 989d6b8

Browse files
authored
Implement database_catalog in direct deployment (#3488)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> This change allows to deploy database catalogs when using `direct-exp` deployment method ## Tests <!-- How have you tested the changes? --> Existing test is expanded to run using `direct-exp` <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent c8cc74e commit 989d6b8

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

acceptance/bundle/deploy/lakebase/database-catalog/out.test.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ RequiresUnityCatalog = true
66
gcp = false
77

88
[EnvMatrix]
9-
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
9+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]

acceptance/bundle/deploy/lakebase/database-catalog/test.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@ Local = true
22
Cloud = true
33

44
RecordRequests = false
5-
6-
[EnvMatrix]
7-
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]

bundle/terranova/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ var SupportedResources = map[string]ResourceSettings{
114114
ConfigType: TypeOfConfig(&tnresources.ResourceDatabaseInstance{}),
115115
DeleteFN: tnresources.DeleteDatabaseInstance,
116116
},
117+
"database_catalogs": {
118+
New: reflect.ValueOf(tnresources.NewResourceDatabaseCatalog),
119+
ConfigType: TypeOfConfig(&tnresources.ResourceDatabaseCatalog{}),
120+
DeleteFN: tnresources.DeleteDatabaseCatalog,
121+
},
117122
}
118123

119124
type IResource interface {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package tnresources
2+
3+
import (
4+
"context"
5+
6+
"github.com/databricks/cli/bundle/config/resources"
7+
"github.com/databricks/databricks-sdk-go"
8+
"github.com/databricks/databricks-sdk-go/service/database"
9+
)
10+
11+
type ResourceDatabaseCatalog struct {
12+
client *databricks.WorkspaceClient
13+
config database.DatabaseCatalog
14+
}
15+
16+
func (d ResourceDatabaseCatalog) Config() any {
17+
return d.config
18+
}
19+
20+
func (d *ResourceDatabaseCatalog) DoCreate(ctx context.Context) (string, error) {
21+
result, err := d.client.Database.CreateDatabaseCatalog(ctx, database.CreateDatabaseCatalogRequest{
22+
Catalog: d.config,
23+
})
24+
if err != nil {
25+
return "", err
26+
}
27+
return result.Name, nil
28+
}
29+
30+
func (d ResourceDatabaseCatalog) DoUpdate(ctx context.Context, id string) error {
31+
request := database.UpdateDatabaseCatalogRequest{
32+
DatabaseCatalog: d.config,
33+
Name: d.config.Name,
34+
UpdateMask: "*",
35+
}
36+
37+
_, err := d.client.Database.UpdateDatabaseCatalog(ctx, request)
38+
return err
39+
}
40+
41+
func (d ResourceDatabaseCatalog) WaitAfterCreate(_ context.Context) error {
42+
return nil
43+
}
44+
45+
func (d ResourceDatabaseCatalog) WaitAfterUpdate(_ context.Context) error {
46+
return nil
47+
}
48+
49+
func NewResourceDatabaseCatalog(client *databricks.WorkspaceClient, resource *resources.DatabaseCatalog) (*ResourceDatabaseCatalog, error) {
50+
return &ResourceDatabaseCatalog{
51+
client: client,
52+
config: resource.DatabaseCatalog,
53+
}, nil
54+
}
55+
56+
func DeleteDatabaseCatalog(ctx context.Context, client *databricks.WorkspaceClient, name string) error {
57+
return client.Database.DeleteDatabaseCatalog(ctx, database.DeleteDatabaseCatalogRequest{
58+
Name: name,
59+
})
60+
}

0 commit comments

Comments
 (0)