Skip to content

Commit

Permalink
Fix issues with Nameservers (#258)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Hoppe <[email protected]>
  • Loading branch information
roberth1988 and Robert Hoppe authored Nov 26, 2024
1 parent 748d019 commit 1547b20
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions stackit/internal/resources/network/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r Resource) createNetwork(ctx context.Context, resp *resource.CreateRespon
continue
}

ns = append(ns, nsVal)
ns = appendIfMissting(ns, nsVal)
}

// ensure we have the Nameservers sorted
Expand Down Expand Up @@ -152,8 +152,8 @@ func (r Resource) Read(ctx context.Context, req resource.ReadRequest, resp *reso
}

// ensure we have the nameservers sorted

nameservers := make([]attr.Value, 0)

if n.Nameservers != nil && len(*n.Nameservers) > 0 {
nsData := *n.Nameservers
sort.Strings(nsData)
Expand Down Expand Up @@ -243,9 +243,12 @@ func (r Resource) updateNetwork(ctx context.Context, plan, state Network, resp *
continue
}

ns = append(ns, s.String())
ns = appendIfMissting(ns, s.String())
}

// ensure we have the Nameservers sorted
sort.Strings(ns)

name := plan.Name.ValueString()

body := iaas_network.V1UpdateNetworkJSONBody{
Expand Down Expand Up @@ -327,3 +330,13 @@ func (r *Resource) ImportState(ctx context.Context, req resource.ImportStateRequ
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), projectID)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), networkID)...)
}

func appendIfMissting(valueList []string, value string) []string {
for _, v := range valueList {
if v == value {
return valueList
}
}

return append(valueList, value)
}

0 comments on commit 1547b20

Please sign in to comment.