Skip to content

Commit

Permalink
fix(lb): avoid recreation of old lb ips (#2556)
Browse files Browse the repository at this point in the history
* fix(lb): avoid recreation of lb ips

* update cassette
  • Loading branch information
yfodil committed May 22, 2024
1 parent 77b32a0 commit 697c2fd
Show file tree
Hide file tree
Showing 5 changed files with 2,144 additions and 1,486 deletions.
10 changes: 10 additions & 0 deletions internal/services/lb/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lb

import (
"context"
"net"

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

isIPv6 := false
if ip.IPAddress != "" {
parsedIP := net.ParseIP(ip.IPAddress)
if parsedIP != nil && parsedIP.To4() == nil {
isIPv6 = true
}
}
_ = d.Set("is_ipv6", isIPv6)

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions internal/services/lb/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccIP_Basic(t *testing.T) {
isIPPresent(tt, "scaleway_lb_ip.ipZone"),
acctest.CheckResourceAttrIPv4("scaleway_lb_ip.ipZone", "ip_address"),
resource.TestCheckResourceAttrSet("scaleway_lb_ip.ipZone", "reverse"),
resource.TestCheckResourceAttr("scaleway_lb_ip.ipZone", "is_ipv6", "false"),
resource.TestCheckResourceAttr("scaleway_lb_ip.ipZone", "zone", "nl-ams-1"),
),
},
Expand Down Expand Up @@ -95,6 +96,7 @@ func TestAccIP_IPv6(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
isIPPresent(tt, "scaleway_lb_ip.ipv6"),
acctest.CheckResourceAttrIPv6("scaleway_lb_ip.ipv6", "ip_address"),
resource.TestCheckResourceAttr("scaleway_lb_ip.ipv6", "is_ipv6", "true"),
),
},
},
Expand Down

0 comments on commit 697c2fd

Please sign in to comment.