Skip to content

Commit 1eb5747

Browse files
authored
fix(lb): resolve unnecessary plan changes for LB private network (#2315)
1 parent 45658de commit 1eb5747

File tree

3 files changed

+1104
-7
lines changed

3 files changed

+1104
-7
lines changed

scaleway/helpers_lb.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net"
88
"reflect"
9-
"strconv"
109
"strings"
1110
"time"
1211

@@ -144,7 +143,7 @@ func expandPrivateNetworks(data interface{}) ([]*lbSDK.PrivateNetwork, error) {
144143
rawPn := pn.(map[string]interface{})
145144
privateNetwork := &lbSDK.PrivateNetwork{}
146145
privateNetwork.PrivateNetworkID = expandID(rawPn["private_network_id"].(string))
147-
if staticConfig, hasStaticConfig := rawPn["static_config"]; hasStaticConfig {
146+
if staticConfig, hasStaticConfig := rawPn["static_config"]; hasStaticConfig && len(staticConfig.([]interface{})) > 0 {
148147
privateNetwork.StaticConfig = expandLbPrivateNetworkStaticConfig(staticConfig)
149148
} else {
150149
privateNetwork.DHCPConfig = expandLbPrivateNetworkDHCPConfig(rawPn["dhcp_config"])
@@ -617,15 +616,11 @@ func lbPrivateNetworkSetHash(v interface{}) int {
617616
buf.WriteString(expandID(pnID))
618617
}
619618

620-
if staticConfig, ok := m["static_config"]; ok {
619+
if staticConfig, ok := m["static_config"]; ok && len(staticConfig.([]interface{})) > 0 {
621620
for _, item := range staticConfig.([]interface{}) {
622621
buf.WriteString(item.(string))
623622
}
624623
}
625624

626-
if dhcpConfig, ok := m["dhcp_config"]; ok {
627-
buf.WriteString(strconv.FormatBool(dhcpConfig.(bool)))
628-
}
629-
630625
return StringHashcode(buf.String())
631626
}

scaleway/resource_lb_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,47 @@ func TestAccScalewayLbLb_WithPrivateNetworksOnDHCPConfig(t *testing.T) {
651651
})
652652
}
653653

654+
func TestAccScalewayLbLb_WithoutPNConfig(t *testing.T) {
655+
tt := NewTestTools(t)
656+
defer tt.Cleanup()
657+
resource.ParallelTest(t, resource.TestCase{
658+
PreCheck: func() { testAccPreCheck(t) },
659+
ProviderFactories: tt.ProviderFactories,
660+
CheckDestroy: testAccCheckScalewayLbDestroy(tt),
661+
Steps: []resource.TestStep{
662+
{
663+
Config: `
664+
resource "scaleway_lb_ip" "ip01" {}
665+
666+
resource "scaleway_vpc_private_network" "pn" {
667+
name = "pn-with-lb-static"
668+
}
669+
670+
resource "scaleway_lb" "lb01" {
671+
ip_id = scaleway_lb_ip.ip01.id
672+
name = "test-lb-with-pn-static-cidr"
673+
type = "LB-S"
674+
private_network {
675+
private_network_id = scaleway_vpc_private_network.pn.id
676+
}
677+
}
678+
`,
679+
Check: resource.ComposeTestCheckFunc(
680+
testAccCheckScalewayLbExists(tt, "scaleway_lb.lb01"),
681+
testAccCheckScalewayLbIPExists(tt, "scaleway_lb_ip.ip01"),
682+
resource.TestCheckResourceAttrPair(
683+
"scaleway_lb.lb01", "private_network.0.private_network_id",
684+
"scaleway_vpc_private_network.pn", "id"),
685+
resource.TestCheckResourceAttr("scaleway_lb.lb01",
686+
"private_network.0.status", lbSDK.PrivateNetworkStatusReady.String()),
687+
resource.TestCheckResourceAttr("scaleway_lb.lb01",
688+
"private_network.0.dhcp_config", "true"),
689+
),
690+
},
691+
},
692+
})
693+
}
694+
654695
func TestAccScalewayLbLb_DifferentLocalityIPID(t *testing.T) {
655696
tt := NewTestTools(t)
656697
defer tt.Cleanup()

0 commit comments

Comments
 (0)