Skip to content

Commit 88bd556

Browse files
committed
refactor
1 parent 2b23fad commit 88bd556

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

internal/dsf/ip.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dsf
2+
3+
import (
4+
"net"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
)
8+
9+
func DiffSuppressFuncStandaloneIPandCIDR(_, oldValue, newValue string, _ *schema.ResourceData) bool {
10+
parseIPOrCIDR := func(s string) net.IP {
11+
if ip, _, err := net.ParseCIDR(s); err == nil {
12+
return ip
13+
}
14+
15+
return net.ParseIP(s)
16+
}
17+
18+
oldIP := parseIPOrCIDR(oldValue)
19+
newIP := parseIPOrCIDR(newValue)
20+
21+
return oldIP != nil && newIP != nil && oldIP.Equal(newIP)
22+
}

internal/services/ipam/helpers_test.go renamed to internal/dsf/ip_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package ipam_test
1+
package dsf_test
22

33
import (
44
"testing"
55

6-
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
6+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
77
)
88

99
func TestDiffSuppress_IPAMIP(t *testing.T) {
@@ -77,7 +77,7 @@ func TestDiffSuppress_IPAMIP(t *testing.T) {
7777

7878
for _, tt := range tests {
7979
t.Run(tt.name, func(t *testing.T) {
80-
got := ipam.DiffSuppressFuncStandaloneIPandCIDR("", tt.oldValue, tt.newValue, nil)
80+
got := dsf.DiffSuppressFuncStandaloneIPandCIDR("", tt.oldValue, tt.newValue, nil)
8181
if got != tt.want {
8282
t.Fatalf("diffSuppress(%q, %q) = %v, want %v", tt.oldValue, tt.newValue, got, tt.want)
8383
}

internal/services/ipam/helpers.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ipam
33
import (
44
"context"
55
"fmt"
6-
"net"
76
"time"
87

98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -43,21 +42,6 @@ func NewAPIWithRegionAndID(m any, id string) (*ipam.API, scw.Region, string, err
4342
return ipamAPI, region, ID, err
4443
}
4544

46-
func DiffSuppressFuncStandaloneIPandCIDR(_, oldValue, newValue string, _ *schema.ResourceData) bool {
47-
parseIPOrCIDR := func(s string) net.IP {
48-
if ip, _, err := net.ParseCIDR(s); err == nil {
49-
return ip
50-
}
51-
52-
return net.ParseIP(s)
53-
}
54-
55-
oldIP := parseIPOrCIDR(oldValue)
56-
newIP := parseIPOrCIDR(newValue)
57-
58-
return oldIP != nil && newIP != nil && oldIP.Equal(newIP)
59-
}
60-
6145
type GetResourcePrivateIPsOptions struct {
6246
ResourceType *ipam.ResourceType
6347
ResourceID *string

internal/services/ipam/ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func ResourceIP() *schema.Resource {
3838
ForceNew: true,
3939
Description: "Request a specific IP in the requested source pool",
4040
ValidateFunc: validation.IsIPAddress,
41-
DiffSuppressFunc: DiffSuppressFuncStandaloneIPandCIDR,
41+
DiffSuppressFunc: dsf.DiffSuppressFuncStandaloneIPandCIDR,
4242
},
4343
"source": {
4444
Type: schema.TypeList,

0 commit comments

Comments
 (0)