@@ -11,19 +11,35 @@ import (
1111 "github.com/databricks/databricks-sdk-go"
1212)
1313
14+ const (
15+ _jobs = "jobs"
16+ _pipelines = "pipelines"
17+ _schemas = "schemas"
18+ _apps = "apps"
19+ )
20+
1421var supportedResources = map [string ]reflect.Value {
15- "jobs" : reflect .ValueOf (NewResourceJob ),
16- "pipelines" : reflect .ValueOf (NewResourcePipeline ),
17- "schemas" : reflect .ValueOf (NewResourceSchema ),
18- "apps" : reflect .ValueOf (NewResourceApp ),
22+ _jobs : reflect .ValueOf (NewResourceJob ),
23+ _pipelines : reflect .ValueOf (NewResourcePipeline ),
24+ _schemas : reflect .ValueOf (NewResourceSchema ),
25+ _apps : reflect .ValueOf (NewResourceApp ),
1926}
2027
2128// This types matches what Config() returns and should match 'config' field in the resource struct
2229var supportedResourcesTypes = map [string ]reflect.Type {
23- "jobs" : reflect .TypeOf (ResourceJob {}.config ),
24- "pipelines" : reflect .TypeOf (ResourcePipeline {}.config ),
25- "schemas" : reflect .TypeOf (ResourceSchema {}.config ),
26- "apps" : reflect .TypeOf (ResourceApp {}.config ),
30+ _jobs : reflect .TypeOf (ResourceJob {}.config ),
31+ _pipelines : reflect .TypeOf (ResourcePipeline {}.config ),
32+ _schemas : reflect .TypeOf (ResourceSchema {}.config ),
33+ _apps : reflect .TypeOf (ResourceApp {}.config ),
34+ }
35+
36+ type DeleteResourceFN = func (ctx context.Context , client * databricks.WorkspaceClient , oldID string ) error
37+
38+ var deletableResources = map [string ]DeleteResourceFN {
39+ _jobs : DeleteJob ,
40+ _pipelines : DeletePipeline ,
41+ _schemas : DeleteSchema ,
42+ _apps : DeleteApp ,
2743}
2844
2945type IResource interface {
@@ -34,9 +50,7 @@ type IResource interface {
3450
3551 // Update the resource. Returns id of the resource.
3652 // Usually returns the same id as oldId but can also return a different one (e.g. schemas and volumes when certain fields are changed)
37- DoUpdate (ctx context.Context , oldId string ) (string , error )
38-
39- DoDelete (ctx context.Context , oldId string ) error
53+ DoUpdate (ctx context.Context , oldID string ) (string , error )
4054
4155 WaitAfterCreate (ctx context.Context ) error
4256 WaitAfterUpdate (ctx context.Context ) error
@@ -59,9 +73,7 @@ func invokeConstructor(ctor reflect.Value, client *databricks.WorkspaceClient, c
5973 // Prepare the config value matching the expected type.
6074 var cfgVal reflect.Value
6175 if cfg == nil {
62- // Treat nil as a request for the zero value of the expected config type. This
63- // is useful for actions (like deletion) where the config is irrelevant.
64- cfgVal = reflect .Zero (expectedCfgType )
76+ return nil , errors .New ("internal error, config must not be nil" )
6577 } else {
6678 suppliedVal := reflect .ValueOf (cfg )
6779 if suppliedVal .Type () != expectedCfgType {
@@ -116,3 +128,11 @@ func New(client *databricks.WorkspaceClient, group, name string, config any) (IR
116128
117129 return result , cfgType , nil
118130}
131+
132+ func DeleteResource (ctx context.Context , client * databricks.WorkspaceClient , group , id string ) error {
133+ fn , ok := deletableResources [group ]
134+ if ! ok {
135+ return fmt .Errorf ("cannot delete %s" , group )
136+ }
137+ return fn (ctx , client , id )
138+ }
0 commit comments