@@ -18,6 +18,14 @@ var supportedResources = map[string]reflect.Value{
1818 "apps" : reflect .ValueOf (NewResourceApp ),
1919}
2020
21+ // This types matches what Config() returns and should match 'config' field in the resource struct
22+ var 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 ),
27+ }
28+
2129type IResource interface {
2230 Config () any
2331
@@ -33,9 +41,6 @@ type IResource interface {
3341 WaitAfterCreate (ctx context.Context ) error
3442 WaitAfterUpdate (ctx context.Context ) error
3543
36- // Get type of the struct that stores the state
37- GetType () reflect.Type
38-
3944 ClassifyChanges (changes []structdiff.Change ) deployplan.ActionType
4045}
4146
@@ -78,15 +83,20 @@ func invokeConstructor(ctor reflect.Value, client *databricks.WorkspaceClient, c
7883 return res , nil
7984}
8085
81- func New (client * databricks.WorkspaceClient , section , name string , config any ) (IResource , error ) {
86+ func New (client * databricks.WorkspaceClient , section , name string , config any ) (IResource , reflect. Type , error ) {
8287 ctor , ok := supportedResources [section ]
8388 if ! ok {
84- return nil , fmt .Errorf ("unsupported resource type: %s" , section )
89+ return nil , nil , fmt .Errorf ("unsupported resource type: %s" , section )
90+ }
91+
92+ cfgType , ok := supportedResourcesTypes [section ]
93+ if ! ok {
94+ return nil , nil , fmt .Errorf ("unsupported resource type: %s" , section )
8595 }
8696
8797 // Disallow nil configs (including typed nil pointers).
8898 if config == nil {
89- return nil , fmt .Errorf ("unexpected nil in config: %s.%s" , section , name )
99+ return nil , nil , fmt .Errorf ("unexpected nil in config: %s.%s" , section , name )
90100 }
91101
92102 // If the supplied config is a pointer value, dereference it so that we pass
@@ -95,9 +105,14 @@ func New(client *databricks.WorkspaceClient, section, name string, config any) (
95105 v := reflect .ValueOf (config )
96106 if v .Kind () == reflect .Ptr {
97107 if v .IsNil () {
98- return nil , fmt .Errorf ("unexpected nil in config: %s.%s" , section , name )
108+ return nil , nil , fmt .Errorf ("unexpected nil in config: %s.%s" , section , name )
99109 }
100110 }
101111
102- return invokeConstructor (ctor , client , config )
112+ result , err := invokeConstructor (ctor , client , config )
113+ if err != nil {
114+ return nil , nil , err
115+ }
116+
117+ return result , cfgType , nil
103118}
0 commit comments