Skip to content

Commit

Permalink
Ensure sorted values within nameservers (#250)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Hoppe <robert.hoppe@mail.schwarz>
  • Loading branch information
roberth1988 and Robert Hoppe authored Jul 31, 2024
1 parent 12deca2 commit 339bcdc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion stackit/internal/data-sources/network/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/attr"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -49,8 +50,14 @@ func (d DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *
}

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

if network.Nameservers != nil && len(*network.Nameservers) > 0 {
for _, ns := range *network.Nameservers {
// ensure we have a sorted list, stackit seems to give us
// things randomly back which confuses TF
nsData := *network.Nameservers
sort.Strings(nsData)

for _, ns := range nsData {
nameservers = append(nameservers, types.StringValue(ns))
}
}
Expand Down
11 changes: 10 additions & 1 deletion stackit/internal/resources/network/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"net/http"
"reflect"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -60,6 +61,9 @@ func (r Resource) createNetwork(ctx context.Context, resp *resource.CreateRespon
ns = append(ns, nsVal)
}

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

pl := int(plan.PrefixLengthV4.ValueInt64())
name := plan.Name.ValueString()

Expand Down Expand Up @@ -147,9 +151,14 @@ 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 {
for _, ns := range *n.Nameservers {
nsData := *n.Nameservers
sort.Strings(nsData)

for _, ns := range nsData {
nameservers = append(nameservers, types.StringValue(ns))
}
}
Expand Down

0 comments on commit 339bcdc

Please sign in to comment.