Skip to content

Commit ffb74c5

Browse files
committed
add space around core.InitProviderContext and core.LogResponse
1 parent da67dcc commit ffb74c5

File tree

136 files changed

+961
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+961
-0
lines changed

stackit/internal/services/authorization/roleassignments/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (r *roleAssignmentResource) Create(ctx context.Context, req resource.Create
153153
}
154154

155155
ctx = core.InitProviderContext(ctx)
156+
156157
ctx = r.annotateLogger(ctx, &model)
157158

158159
if err := r.checkDuplicate(ctx, model); err != nil {
@@ -171,6 +172,7 @@ func (r *roleAssignmentResource) Create(ctx context.Context, req resource.Create
171172
core.LogAndAddError(ctx, &resp.Diagnostics, fmt.Sprintf("Error creating %s role assignment", r.apiName), fmt.Sprintf("Calling API: %v", err))
172173
return
173174
}
175+
174176
ctx = core.LogResponse(ctx)
175177

176178
// Map response body to schema
@@ -197,13 +199,15 @@ func (r *roleAssignmentResource) Read(ctx context.Context, req resource.ReadRequ
197199
}
198200

199201
ctx = core.InitProviderContext(ctx)
202+
200203
ctx = r.annotateLogger(ctx, &model)
201204

202205
listResp, err := r.authorizationClient.ListMembers(ctx, r.apiName, model.ResourceId.ValueString()).Subject(model.Subject.ValueString()).Execute()
203206
if err != nil {
204207
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading authorizations", fmt.Sprintf("Calling API: %v", err))
205208
return
206209
}
210+
207211
ctx = core.LogResponse(ctx)
208212

209213
// Map response body to schema
@@ -237,6 +241,7 @@ func (r *roleAssignmentResource) Delete(ctx context.Context, req resource.Delete
237241
}
238242

239243
ctx = core.InitProviderContext(ctx)
244+
240245
ctx = r.annotateLogger(ctx, &model)
241246

242247
payload := authorization.RemoveMembersPayload{
@@ -251,6 +256,7 @@ func (r *roleAssignmentResource) Delete(ctx context.Context, req resource.Delete
251256
if err != nil {
252257
core.LogAndAddError(ctx, &resp.Diagnostics, fmt.Sprintf("Error deleting %s role assignment", r.apiName), fmt.Sprintf("Calling API: %v", err))
253258
}
259+
254260
ctx = core.LogResponse(ctx)
255261

256262
tflog.Info(ctx, fmt.Sprintf("%s role assignment deleted", r.apiName))

stackit/internal/services/cdn/customdomain/datasource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (r *customDomainDataSource) Read(ctx context.Context, req datasource.ReadRe
127127
}
128128

129129
ctx = core.InitProviderContext(ctx)
130+
130131
projectId := model.ProjectId.ValueString()
131132
ctx = tflog.SetField(ctx, "project_id", projectId)
132133
distributionId := model.DistributionId.ValueString()
@@ -146,6 +147,7 @@ func (r *customDomainDataSource) Read(ctx context.Context, req datasource.ReadRe
146147
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading CDN custom domain", fmt.Sprintf("Calling API: %v", err))
147148
return
148149
}
150+
149151
ctx = core.LogResponse(ctx)
150152

151153
// Call the new data source mapping function

stackit/internal/services/cdn/customdomain/resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ func (r *customDomainResource) Create(ctx context.Context, req resource.CreateRe
186186
if resp.Diagnostics.HasError() {
187187
return
188188
}
189+
189190
ctx = core.InitProviderContext(ctx)
191+
190192
projectId := model.ProjectId.ValueString()
191193
ctx = tflog.SetField(ctx, "project_id", projectId)
192194
distributionId := model.DistributionId.ValueString()
@@ -208,6 +210,7 @@ func (r *customDomainResource) Create(ctx context.Context, req resource.CreateRe
208210
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating CDN custom domain", fmt.Sprintf("Calling API: %v", err))
209211
return
210212
}
213+
211214
ctx = core.LogResponse(ctx)
212215

213216
_, err = wait.CreateCDNCustomDomainWaitHandler(ctx, r.client, projectId, distributionId, name).SetTimeout(5 * time.Minute).WaitWithContext(ctx)
@@ -244,6 +247,7 @@ func (r *customDomainResource) Read(ctx context.Context, req resource.ReadReques
244247
}
245248

246249
ctx = core.InitProviderContext(ctx)
250+
247251
projectId := model.ProjectId.ValueString()
248252
ctx = tflog.SetField(ctx, "project_id", projectId)
249253
distributionId := model.DistributionId.ValueString()
@@ -264,6 +268,7 @@ func (r *customDomainResource) Read(ctx context.Context, req resource.ReadReques
264268
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading CDN custom domain", fmt.Sprintf("Calling API: %v", err))
265269
return
266270
}
271+
267272
ctx = core.LogResponse(ctx)
268273

269274
err = mapCustomDomainResourceFields(customDomainResp, &model)
@@ -289,6 +294,7 @@ func (r *customDomainResource) Update(ctx context.Context, req resource.UpdateRe
289294
}
290295

291296
ctx = core.InitProviderContext(ctx)
297+
292298
projectId := model.ProjectId.ValueString()
293299
ctx = tflog.SetField(ctx, "project_id", projectId)
294300
distributionId := model.DistributionId.ValueString()
@@ -311,6 +317,7 @@ func (r *customDomainResource) Update(ctx context.Context, req resource.UpdateRe
311317
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating CDN custom domain certificate", fmt.Sprintf("Calling API: %v", err))
312318
return
313319
}
320+
314321
ctx = core.LogResponse(ctx)
315322

316323
_, err = wait.CreateCDNCustomDomainWaitHandler(ctx, r.client, projectId, distributionId, name).SetTimeout(5 * time.Minute).WaitWithContext(ctx)
@@ -346,6 +353,7 @@ func (r *customDomainResource) Delete(ctx context.Context, req resource.DeleteRe
346353
}
347354

348355
ctx = core.InitProviderContext(ctx)
356+
349357
projectId := model.ProjectId.ValueString()
350358
ctx = tflog.SetField(ctx, "project_id", projectId)
351359
distributionId := model.DistributionId.ValueString()
@@ -357,7 +365,9 @@ func (r *customDomainResource) Delete(ctx context.Context, req resource.DeleteRe
357365
if err != nil {
358366
core.LogAndAddError(ctx, &resp.Diagnostics, "Delete CDN custom domain", fmt.Sprintf("Delete custom domain: %v", err))
359367
}
368+
360369
ctx = core.LogResponse(ctx)
370+
361371
_, err = wait.DeleteCDNCustomDomainWaitHandler(ctx, r.client, projectId, distributionId, name).WaitWithContext(ctx)
362372
if err != nil {
363373
core.LogAndAddError(ctx, &resp.Diagnostics, "Delete CDN custom domain", fmt.Sprintf("Waiting for deletion: %v", err))

stackit/internal/services/cdn/distribution/datasource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func (r *distributionDataSource) Read(ctx context.Context, req datasource.ReadRe
185185
}
186186

187187
ctx = core.InitProviderContext(ctx)
188+
188189
projectId := model.ProjectId.ValueString()
189190
distributionId := model.DistributionId.ValueString()
190191
distributionResp, err := r.client.GetDistributionExecute(ctx, projectId, distributionId)
@@ -200,7 +201,9 @@ func (r *distributionDataSource) Read(ctx context.Context, req datasource.ReadRe
200201
resp.State.RemoveResource(ctx)
201202
return
202203
}
204+
203205
ctx = core.LogResponse(ctx)
206+
204207
err = mapFields(ctx, distributionResp.Distribution, &model)
205208
if err != nil {
206209
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading CDN distribution", fmt.Sprintf("Error processing API response: %v", err))

stackit/internal/services/cdn/distribution/resource.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ func (r *distributionResource) Create(ctx context.Context, req resource.CreateRe
334334
if resp.Diagnostics.HasError() {
335335
return
336336
}
337+
337338
ctx = core.InitProviderContext(ctx)
339+
338340
projectId := model.ProjectId.ValueString()
339341
ctx = tflog.SetField(ctx, "project_id", projectId)
340342

@@ -349,7 +351,9 @@ func (r *distributionResource) Create(ctx context.Context, req resource.CreateRe
349351
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating CDN distribution", fmt.Sprintf("Calling API: %v", err))
350352
return
351353
}
354+
352355
ctx = core.LogResponse(ctx)
356+
353357
waitResp, err := wait.CreateDistributionPoolWaitHandler(ctx, r.client, projectId, *createResp.Distribution.Id).SetTimeout(5 * time.Minute).WaitWithContext(ctx)
354358
if err != nil {
355359
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating CDN distribution", fmt.Sprintf("Waiting for create: %v", err))
@@ -379,6 +383,7 @@ func (r *distributionResource) Read(ctx context.Context, req resource.ReadReques
379383
}
380384

381385
ctx = core.InitProviderContext(ctx)
386+
382387
projectId := model.ProjectId.ValueString()
383388
distributionId := model.DistributionId.ValueString()
384389
ctx = tflog.SetField(ctx, "project_id", projectId)
@@ -397,7 +402,9 @@ func (r *distributionResource) Read(ctx context.Context, req resource.ReadReques
397402
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading CDN distribution", fmt.Sprintf("Calling API: %v", err))
398403
return
399404
}
405+
400406
ctx = core.LogResponse(ctx)
407+
401408
err = mapFields(ctx, cdnResp.Distribution, &model)
402409
if err != nil {
403410
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading CDN ditribution", fmt.Sprintf("Processing API payload: %v", err))
@@ -421,6 +428,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
421428
}
422429

423430
ctx = core.InitProviderContext(ctx)
431+
424432
projectId := model.ProjectId.ValueString()
425433
distributionId := model.DistributionId.ValueString()
426434
ctx = tflog.SetField(ctx, "project_id", projectId)
@@ -520,6 +528,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
520528
core.LogAndAddError(ctx, &resp.Diagnostics, "Update CDN distribution", fmt.Sprintf("Patch distribution: %v", err))
521529
return
522530
}
531+
523532
ctx = core.LogResponse(ctx)
524533

525534
waitResp, err := wait.UpdateDistributionWaitHandler(ctx, r.client, projectId, distributionId).WaitWithContext(ctx)
@@ -549,7 +558,9 @@ func (r *distributionResource) Delete(ctx context.Context, req resource.DeleteRe
549558
if resp.Diagnostics.HasError() {
550559
return
551560
}
561+
552562
ctx = core.LogResponse(ctx)
563+
553564
projectId := model.ProjectId.ValueString()
554565
distributionId := model.DistributionId.ValueString()
555566
ctx = tflog.SetField(ctx, "project_id", projectId)
@@ -559,7 +570,9 @@ func (r *distributionResource) Delete(ctx context.Context, req resource.DeleteRe
559570
if err != nil {
560571
core.LogAndAddError(ctx, &resp.Diagnostics, "Delete CDN distribution", fmt.Sprintf("Delete distribution: %v", err))
561572
}
573+
562574
ctx = core.LogResponse(ctx)
575+
563576
_, err = wait.DeleteDistributionWaitHandler(ctx, r.client, projectId, distributionId).WaitWithContext(ctx)
564577
if err != nil {
565578
core.LogAndAddError(ctx, &resp.Diagnostics, "Delete CDN distribution", fmt.Sprintf("Waiting for deletion: %v", err))

stackit/internal/services/dns/recordset/datasource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ func (d *recordSetDataSource) Read(ctx context.Context, req datasource.ReadReque
136136
if resp.Diagnostics.HasError() {
137137
return
138138
}
139+
139140
ctx = core.InitProviderContext(ctx)
141+
140142
projectId := model.ProjectId.ValueString()
141143
zoneId := model.ZoneId.ValueString()
142144
recordSetId := model.RecordSetId.ValueString()
@@ -158,7 +160,9 @@ func (d *recordSetDataSource) Read(ctx context.Context, req datasource.ReadReque
158160
resp.State.RemoveResource(ctx)
159161
return
160162
}
163+
161164
ctx = core.LogResponse(ctx)
165+
162166
if recordSetResp != nil && recordSetResp.Rrset.State != nil && *recordSetResp.Rrset.State == dns.RECORDSETSTATE_DELETE_SUCCEEDED {
163167
resp.State.RemoveResource(ctx)
164168
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading record set", "Record set was deleted successfully")

stackit/internal/services/dns/recordset/resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (r *recordSetResource) Create(ctx context.Context, req resource.CreateReque
201201
}
202202

203203
ctx = core.InitProviderContext(ctx)
204+
204205
projectId := model.ProjectId.ValueString()
205206
zoneId := model.ZoneId.ValueString()
206207
ctx = tflog.SetField(ctx, "project_id", projectId)
@@ -218,6 +219,7 @@ func (r *recordSetResource) Create(ctx context.Context, req resource.CreateReque
218219
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating record set", fmt.Sprintf("Calling API: %v", err))
219220
return
220221
}
222+
221223
ctx = core.LogResponse(ctx)
222224

223225
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
@@ -259,7 +261,9 @@ func (r *recordSetResource) Read(ctx context.Context, req resource.ReadRequest,
259261
if resp.Diagnostics.HasError() {
260262
return
261263
}
264+
262265
ctx = core.InitProviderContext(ctx)
266+
263267
projectId := model.ProjectId.ValueString()
264268
zoneId := model.ZoneId.ValueString()
265269
recordSetId := model.RecordSetId.ValueString()
@@ -276,6 +280,7 @@ func (r *recordSetResource) Read(ctx context.Context, req resource.ReadRequest,
276280
resp.State.RemoveResource(ctx)
277281
return
278282
}
283+
279284
ctx = core.LogResponse(ctx)
280285

281286
// Map response body to schema
@@ -305,6 +310,7 @@ func (r *recordSetResource) Update(ctx context.Context, req resource.UpdateReque
305310
}
306311

307312
ctx = core.InitProviderContext(ctx)
313+
308314
projectId := model.ProjectId.ValueString()
309315
zoneId := model.ZoneId.ValueString()
310316
recordSetId := model.RecordSetId.ValueString()
@@ -324,7 +330,9 @@ func (r *recordSetResource) Update(ctx context.Context, req resource.UpdateReque
324330
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating record set", err.Error())
325331
return
326332
}
333+
327334
ctx = core.LogResponse(ctx)
335+
328336
waitResp, err := wait.PartialUpdateRecordSetWaitHandler(ctx, r.client, projectId, zoneId, recordSetId).WaitWithContext(ctx)
329337
if err != nil {
330338
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating record set", fmt.Sprintf("Instance update waiting: %v", err))
@@ -355,6 +363,7 @@ func (r *recordSetResource) Delete(ctx context.Context, req resource.DeleteReque
355363
}
356364

357365
ctx = core.InitProviderContext(ctx)
366+
358367
projectId := model.ProjectId.ValueString()
359368
zoneId := model.ZoneId.ValueString()
360369
recordSetId := model.RecordSetId.ValueString()
@@ -367,7 +376,9 @@ func (r *recordSetResource) Delete(ctx context.Context, req resource.DeleteReque
367376
if err != nil {
368377
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting record set", fmt.Sprintf("Calling API: %v", err))
369378
}
379+
370380
ctx = core.LogResponse(ctx)
381+
371382
_, err = wait.DeleteRecordSetWaitHandler(ctx, r.client, projectId, zoneId, recordSetId).WaitWithContext(ctx)
372383
if err != nil {
373384
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting record set", fmt.Sprintf("Instance deletion waiting: %v", err))

stackit/internal/services/dns/zone/datasource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
179179
if resp.Diagnostics.HasError() {
180180
return
181181
}
182+
182183
ctx = core.InitProviderContext(ctx)
184+
183185
projectId := model.ProjectId.ValueString()
184186
zoneId := model.ZoneId.ValueString()
185187
dnsName := model.DnsName.ValueString()
@@ -206,7 +208,9 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
206208
resp.State.RemoveResource(ctx)
207209
return
208210
}
211+
209212
ctx = core.LogResponse(ctx)
213+
210214
} else {
211215
listZoneResp, err := d.client.ListZones(ctx, projectId).
212216
DnsNameEq(dnsName).
@@ -226,7 +230,9 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
226230
resp.State.RemoveResource(ctx)
227231
return
228232
}
233+
229234
ctx = core.LogResponse(ctx)
235+
230236
if *listZoneResp.TotalItems != 1 {
231237
utils.LogError(
232238
ctx,

0 commit comments

Comments
 (0)