@@ -12,10 +12,6 @@ import (
1212 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1313)
1414
15- var (
16- defaultSettingId = "global"
17- )
18-
1915func retryOnEtagError [Req , Resp any ](f func (req Req ) (Resp , error ), firstReq Req , updateReq func (req * Req , newEtag string ), retriableErrors []error ) (Resp , error ) {
2016 req := firstReq
2117 // Retry once on etag error.
@@ -72,9 +68,6 @@ type genericSettingDefinition[T, U any] interface {
7268
7369 // Update the etag in the setting.
7470 SetETag (t * T , newEtag string )
75-
76- // Generate resource ID from settings instance
77- GetId (t * T ) string
7871}
7972
8073func getEtag [T any ](t T ) string {
@@ -111,9 +104,6 @@ type workspaceSetting[T any] struct {
111104
112105 // Delete the setting with the given etag, and return the new etag.
113106 deleteFunc func (ctx context.Context , w * databricks.WorkspaceClient , etag string ) (string , error )
114-
115- // Optional function to generate resource ID from the settings
116- generateIdFunc func (setting * T ) string
117107}
118108
119109func (w workspaceSetting [T ]) SettingStruct () T {
@@ -131,15 +121,6 @@ func (w workspaceSetting[T]) Delete(ctx context.Context, c *databricks.Workspace
131121func (w workspaceSetting [T ]) GetETag (t * T ) string {
132122 return getEtag (t )
133123}
134-
135- func (w workspaceSetting [T ]) GetId (t * T ) string {
136- id := defaultSettingId
137- if w .generateIdFunc != nil {
138- id = w .generateIdFunc (t )
139- }
140- return id
141- }
142-
143124func (w workspaceSetting [T ]) SetETag (t * T , newEtag string ) {
144125 setEtag (t , newEtag )
145126}
@@ -164,9 +145,6 @@ type accountSetting[T any] struct {
164145
165146 // Delete the setting with the given etag, and return the new etag.
166147 deleteFunc func (ctx context.Context , w * databricks.AccountClient , etag string ) (string , error )
167-
168- // Optional function to generate resource ID from the settings
169- generateIdFunc func (setting * T ) string
170148}
171149
172150func (w accountSetting [T ]) SettingStruct () T {
@@ -188,14 +166,6 @@ func (w accountSetting[T]) SetETag(t *T, newEtag string) {
188166 setEtag (t , newEtag )
189167}
190168
191- func (w accountSetting [T ]) GetId (t * T ) string {
192- id := defaultSettingId
193- if w .generateIdFunc != nil {
194- id = w .generateIdFunc (t )
195- }
196- return id
197- }
198-
199169var _ accountSettingDefinition [struct {}] = accountSetting [struct {}]{}
200170
201171func makeSettingResource [T , U any ](defn genericSettingDefinition [T , U ]) common.Resource {
@@ -247,8 +217,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
247217 default :
248218 return fmt .Errorf ("unexpected setting type: %T" , defn )
249219 }
250- d .Set ("etag" , res )
251- d .SetId (defn .GetId (& setting ))
220+ d .SetId (res )
252221 return nil
253222 }
254223
@@ -266,7 +235,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
266235 if err != nil {
267236 return err
268237 }
269- res , err = defn .Read (ctx , w , d .Get ( "etag" ).( string ))
238+ res , err = defn .Read (ctx , w , d .Id ( ))
270239 if err != nil {
271240 return err
272241 }
@@ -275,7 +244,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
275244 if err != nil {
276245 return err
277246 }
278- res , err = defn .Read (ctx , a , d .Get ( "etag" ).( string ))
247+ res , err = defn .Read (ctx , a , d .Id ( ))
279248 if err != nil {
280249 return err
281250 }
@@ -290,12 +259,12 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
290259 // with a response which is at least as recent as the etag.
291260 // Updating, while not always necessary, ensures that the
292261 // server responds with an updated response.
293- d .Set ( "etag" , defn .GetETag (res ))
262+ d .SetId ( defn .GetETag (res ))
294263 return nil
295264 },
296265 Update : func (ctx context.Context , d * schema.ResourceData , c * common.DatabricksClient ) error {
297266 var setting T
298- defn .SetETag (& setting , d .Get ( "etag" ).( string ))
267+ defn .SetETag (& setting , d .Id ( ))
299268 return createOrUpdate (ctx , d , c , setting )
300269 },
301270 Delete : func (ctx context.Context , d * schema.ResourceData , c * common.DatabricksClient ) error {
@@ -311,7 +280,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
311280 func (etag string ) (string , error ) {
312281 return defn .Delete (ctx , w , etag )
313282 },
314- d .Get ( "etag" ).( string ),
283+ d .Id ( ),
315284 updateETag ,
316285 deleteRetriableErrors )
317286 if err != nil {
@@ -326,7 +295,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
326295 func (etag string ) (string , error ) {
327296 return defn .Delete (ctx , a , etag )
328297 },
329- d .Get ( "etag" ).( string ),
298+ d .Id ( ),
330299 updateETag ,
331300 deleteRetriableErrors )
332301 if err != nil {
@@ -335,7 +304,7 @@ func makeSettingResource[T, U any](defn genericSettingDefinition[T, U]) common.R
335304 default :
336305 return fmt .Errorf ("unexpected setting type: %T" , defn )
337306 }
338- d .Set ( "etag" , etag )
307+ d .SetId ( etag )
339308 return nil
340309 },
341310 }
0 commit comments