Skip to content

Commit 697c2fd

Browse files
authored
fix(lb): avoid recreation of old lb ips (scaleway#2556)
* fix(lb): avoid recreation of lb ips * update cassette
1 parent 77b32a0 commit 697c2fd

File tree

5 files changed

+2144
-1486
lines changed

5 files changed

+2144
-1486
lines changed

internal/services/lb/ip.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package lb
22

33
import (
44
"context"
5+
"net"
56

67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
@@ -139,6 +140,15 @@ func resourceLbIPRead(ctx context.Context, d *schema.ResourceData, m interface{}
139140
_ = d.Set("reverse", ip.Reverse)
140141
_ = d.Set("lb_id", types.FlattenStringPtr(ip.LBID))
141142

143+
isIPv6 := false
144+
if ip.IPAddress != "" {
145+
parsedIP := net.ParseIP(ip.IPAddress)
146+
if parsedIP != nil && parsedIP.To4() == nil {
147+
isIPv6 = true
148+
}
149+
}
150+
_ = d.Set("is_ipv6", isIPv6)
151+
142152
return nil
143153
}
144154

internal/services/lb/ip_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAccIP_Basic(t *testing.T) {
3030
isIPPresent(tt, "scaleway_lb_ip.ipZone"),
3131
acctest.CheckResourceAttrIPv4("scaleway_lb_ip.ipZone", "ip_address"),
3232
resource.TestCheckResourceAttrSet("scaleway_lb_ip.ipZone", "reverse"),
33+
resource.TestCheckResourceAttr("scaleway_lb_ip.ipZone", "is_ipv6", "false"),
3334
resource.TestCheckResourceAttr("scaleway_lb_ip.ipZone", "zone", "nl-ams-1"),
3435
),
3536
},
@@ -95,6 +96,7 @@ func TestAccIP_IPv6(t *testing.T) {
9596
Check: resource.ComposeTestCheckFunc(
9697
isIPPresent(tt, "scaleway_lb_ip.ipv6"),
9798
acctest.CheckResourceAttrIPv6("scaleway_lb_ip.ipv6", "ip_address"),
99+
resource.TestCheckResourceAttr("scaleway_lb_ip.ipv6", "is_ipv6", "true"),
98100
),
99101
},
100102
},

0 commit comments

Comments
 (0)