99 "github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
1010 "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1111 "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
12- "github.com/hashicorp/terraform-plugin-framework/attr"
1312 "github.com/hashicorp/terraform-plugin-framework/path"
1413 "github.com/hashicorp/terraform-plugin-framework/resource"
1514 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -26,6 +25,7 @@ import (
2625 "github.com/stackitcloud/stackit-sdk-go/services/dns/wait"
2726 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
2827 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
28+ "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
2929 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
3030)
3131
@@ -329,7 +329,7 @@ func (r *zoneResource) Create(ctx context.Context, req resource.CreateRequest, r
329329 }
330330
331331 // Map response body to schema
332- err = mapFields (waitResp , & model )
332+ err = mapFields (ctx , waitResp , & model )
333333 if err != nil {
334334 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating zone" , fmt .Sprintf ("Processing API payload: %v" , err ))
335335 return
@@ -363,7 +363,7 @@ func (r *zoneResource) Read(ctx context.Context, req resource.ReadRequest, resp
363363 }
364364
365365 // Map response body to schema
366- err = mapFields (zoneResp , & model )
366+ err = mapFields (ctx , zoneResp , & model )
367367 if err != nil {
368368 core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading zone" , fmt .Sprintf ("Processing API payload: %v" , err ))
369369 return
@@ -409,7 +409,7 @@ func (r *zoneResource) Update(ctx context.Context, req resource.UpdateRequest, r
409409 return
410410 }
411411
412- err = mapFields (waitResp , & model )
412+ err = mapFields (ctx , waitResp , & model )
413413 if err != nil {
414414 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating zone" , fmt .Sprintf ("Processing API payload: %v" , err ))
415415 return
@@ -475,7 +475,7 @@ func (r *zoneResource) ImportState(ctx context.Context, req resource.ImportState
475475 tflog .Info (ctx , "DNS zone state imported" )
476476}
477477
478- func mapFields (zoneResp * dns.ZoneResponse , model * Model ) error {
478+ func mapFields (ctx context. Context , zoneResp * dns.ZoneResponse , model * Model ) error {
479479 if zoneResp == nil || zoneResp .Zone == nil {
480480 return fmt .Errorf ("response input is nil" )
481481 }
@@ -512,15 +512,20 @@ func mapFields(zoneResp *dns.ZoneResponse, model *Model) error {
512512 if z .Primaries == nil {
513513 model .Primaries = types .ListNull (types .StringType )
514514 } else {
515- respZonePrimaries := []attr.Value {}
516- for _ , primary := range * z .Primaries {
517- respZonePrimaries = append (respZonePrimaries , types .StringValue (primary ))
518- respZonePrimariesList , diags := types .ListValue (types .StringType , respZonePrimaries )
519- if diags .HasError () {
520- return fmt .Errorf ("creating primaries list: %w" , core .DiagsToError (diags ))
521- }
522- model .Primaries = respZonePrimariesList
515+ respPrimaries := * z .Primaries
516+ modelPrimaries , err := utils .ListValuetoStringSlice (model .Primaries )
517+ if err != nil {
518+ return err
523519 }
520+
521+ reconciledPrimaries := utils .ReconcileStringSlices (modelPrimaries , respPrimaries )
522+
523+ primariesTF , diags := types .ListValueFrom (ctx , types .StringType , reconciledPrimaries )
524+ if diags .HasError () {
525+ return fmt .Errorf ("failed to map zone primaries: %w" , core .DiagsToError (diags ))
526+ }
527+
528+ model .Primaries = primariesTF
524529 }
525530 model .ZoneId = types .StringValue (zoneId )
526531 model .Description = types .StringPointerValue (z .Description )
0 commit comments