@@ -164,7 +164,6 @@ func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaReques
164
164
Optional : false ,
165
165
PlanModifiers : []planmodifier.String {
166
166
stringplanmodifier .RequiresReplace (),
167
- stringplanmodifier .UseStateForUnknown (),
168
167
},
169
168
},
170
169
"status" : schema.StringAttribute {
@@ -290,24 +289,16 @@ func (r *distributionResource) Read(ctx context.Context, req resource.ReadReques
290
289
if resp .Diagnostics .HasError () {
291
290
return
292
291
}
293
- if model .ProjectId .IsUnknown () || model .ProjectId .IsNull () {
294
- core .LogAndAddError (ctx , & resp .Diagnostics , "Update CDN distribution" , "No project_id in plan" )
295
- return
296
- }
297
- projectId := model .ProjectId .ValueString ()
298
292
299
- if model .DistributionId .IsUnknown () || model .DistributionId .IsNull () {
300
- core .LogAndAddError (ctx , & resp .Diagnostics , "Update CDN distribution" , "No distribution_id in plan" )
301
- return
302
- }
293
+ projectId := model .ProjectId .ValueString ()
303
294
distributionId := model .DistributionId .ValueString ()
304
295
ctx = tflog .SetField (ctx , "project_id" , projectId )
305
296
ctx = tflog .SetField (ctx , "distribution_id" , distributionId )
306
297
307
298
cdnResp , err := r .client .GetDistribution (ctx , projectId , distributionId ).Execute ()
308
299
if err != nil {
309
300
var oapiErr * oapierror.GenericOpenAPIError
310
- // n.b. err is caught here if of type ** oapierror.GenericOpenAPIError, which it is
301
+ // n.b. err is caught here if of type *oapierror.GenericOpenAPIError, which the stackit SDK client returns
311
302
if errors .As (err , & oapiErr ) {
312
303
if oapiErr .StatusCode == http .StatusNotFound {
313
304
resp .State .RemoveResource (ctx )
@@ -338,16 +329,8 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
338
329
if resp .Diagnostics .HasError () {
339
330
return
340
331
}
341
- if model .ProjectId .IsUnknown () || model .ProjectId .IsNull () {
342
- core .LogAndAddError (ctx , & resp .Diagnostics , "Update CDN distribution" , "No project_id in plan" )
343
- return
344
- }
345
- projectId := model .ProjectId .ValueString ()
346
332
347
- if model .DistributionId .IsUnknown () || model .DistributionId .IsNull () {
348
- core .LogAndAddError (ctx , & resp .Diagnostics , "Update CDN distribution" , "No distribution_id in plan" )
349
- return
350
- }
333
+ projectId := model .ProjectId .ValueString ()
351
334
distributionId := model .DistributionId .ValueString ()
352
335
ctx = tflog .SetField (ctx , "project_id" , projectId )
353
336
ctx = tflog .SetField (ctx , "distribution_id" , distributionId )
@@ -487,9 +470,9 @@ func mapFields(distribution *cdn.Distribution, model *Model) error {
487
470
return core .DiagsToError (diags )
488
471
}
489
472
originRequestHeaders := types .MapNull (types .StringType )
490
- if distribution .Config .Backend .HttpBackend .OriginRequestHeaders != nil && len (* distribution . Config . Backend . HttpBackend . OriginRequestHeaders ) > 0 {
473
+ if origHeaders := distribution .Config .Backend .HttpBackend .OriginRequestHeaders ; origHeaders != nil && len (* origHeaders ) > 0 {
491
474
headers := map [string ]attr.Value {}
492
- for k , v := range * distribution . Config . Backend . HttpBackend . OriginRequestHeaders {
475
+ for k , v := range * origHeaders {
493
476
headers [k ] = types .StringValue (v )
494
477
}
495
478
mappedHeaders , diags := types .MapValue (types .StringType , headers )
@@ -522,13 +505,19 @@ func mapFields(distribution *cdn.Distribution, model *Model) error {
522
505
domainErrors := []attr.Value {}
523
506
if d .Errors != nil {
524
507
for _ , e := range * d .Errors {
508
+ if e .En == nil {
509
+ return fmt .Errorf ("error description missing" )
510
+ }
525
511
domainErrors = append (domainErrors , types .StringValue (* e .En ))
526
512
}
527
513
}
528
514
modelDomainErrors , diags := types .ListValue (types .StringType , domainErrors )
529
515
if diags .HasError () {
530
516
return core .DiagsToError (diags )
531
517
}
518
+ if d .Name == nil || d .Status == nil || d .Type == nil {
519
+ return fmt .Errorf ("domain entry incomplete" )
520
+ }
532
521
modelDomain , diags := types .ObjectValue (domainTypes , map [string ]attr.Value {
533
522
"name" : types .StringValue (* d .Name ),
534
523
"status" : types .StringValue (string (* d .Status )),
0 commit comments