From dd9c6f9a36517dbc1971029481d6fe11cf6e008f Mon Sep 17 00:00:00 2001 From: Fabian Mettler Date: Sun, 4 Aug 2024 11:55:52 +0200 Subject: [PATCH 1/3] internal/network: Allow LB backend description to be null Signed-off-by: Fabian Mettler (cherry picked from commit c8154fdb8ad57db608ee8989d8990f006255da9e) Signed-off-by: Din Music --- internal/network/resource_network_lb.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/network/resource_network_lb.go b/internal/network/resource_network_lb.go index c73e14e1..3e99f214 100644 --- a/internal/network/resource_network_lb.go +++ b/internal/network/resource_network_lb.go @@ -108,7 +108,9 @@ func (r LxdNetworkLBResource) Schema(_ context.Context, _ resource.SchemaRequest "description": schema.StringAttribute{ Optional: true, + Computed: true, Description: "LB backend description", + Default: stringdefault.StaticString(""), }, "target_address": schema.StringAttribute{ From c84036c9380287d8627fbb824a1026bce43bf261 Mon Sep 17 00:00:00 2001 From: Din Music Date: Mon, 5 Aug 2024 08:18:35 +0000 Subject: [PATCH 2/3] internal/network: Allow LB port description to be null Signed-off-by: Din Music --- internal/network/resource_network_lb.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/network/resource_network_lb.go b/internal/network/resource_network_lb.go index 3e99f214..2b88c5c3 100644 --- a/internal/network/resource_network_lb.go +++ b/internal/network/resource_network_lb.go @@ -132,7 +132,9 @@ func (r LxdNetworkLBResource) Schema(_ context.Context, _ resource.SchemaRequest Attributes: map[string]schema.Attribute{ "description": schema.StringAttribute{ Optional: true, + Computed: true, Description: "Port description", + Default: stringdefault.StaticString(""), }, "protocol": schema.StringAttribute{ From 551894aee4ce3517600e1e5b9d8368b0cd1422c2 Mon Sep 17 00:00:00 2001 From: Fabian Mettler Date: Sun, 4 Aug 2024 11:55:58 +0200 Subject: [PATCH 3/3] internal/network: Test LB null descriptions Signed-off-by: Fabian Mettler (cherry picked from commit 2ebe6b3a200f7c725b0471129a42d409b1ef6aee) Signed-off-by: Din Music --- internal/network/resource_network_lb_test.go | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/internal/network/resource_network_lb_test.go b/internal/network/resource_network_lb_test.go index 0de30128..560e29ba 100644 --- a/internal/network/resource_network_lb_test.go +++ b/internal/network/resource_network_lb_test.go @@ -116,6 +116,41 @@ func TestAccNetworkLB_withBackend(t *testing.T) { }) } +func TestAccNetworkLB_withBackend_noDescriptions(t *testing.T) { + backend := api.NetworkLoadBalancerBackend{ + Name: "backend", + TargetAddress: "10.0.0.2", + TargetPort: "80", + } + + port := api.NetworkLoadBalancerPort{ + Protocol: "tcp", + ListenPort: "8080", + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckAPIExtensions(t, "network_load_balancer") + }, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNetworkLB_withBackendAndPort_noDescription(backend, port), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("lxd_network.ovnbr", "name", "ovnbr"), + resource.TestCheckResourceAttr("lxd_network.ovn", "name", "ovn"), + resource.TestCheckResourceAttr("lxd_network_lb.test", "network", "ovn"), + resource.TestCheckResourceAttr("lxd_network_lb.test", "backend.#", "1"), + resource.TestCheckResourceAttr("lxd_network_lb.test", "backend.0.description", ""), + resource.TestCheckResourceAttr("lxd_network_lb.test", "port.#", "1"), + resource.TestCheckResourceAttr("lxd_network_lb.test", "port.0.description", ""), + ), + }, + }, + }) +} + func testAccNetworkLB_basic() string { lbRes := ` resource "lxd_network_lb" "test" { @@ -203,6 +238,38 @@ resource "lxd_network_lb" "test" { return fmt.Sprintf("%s\n%s", ovnNetworkResource(), lbRes) } +func testAccNetworkLB_withBackendAndPort_noDescription(backend api.NetworkLoadBalancerBackend, port api.NetworkLoadBalancerPort) string { + args := []any{ + backend.Name, // 1 + backend.TargetAddress, // 2 + backend.TargetPort, // 3 + port.Protocol, // 4 + port.ListenPort, // 5 + } + + lbRes := fmt.Sprintf(` +resource "lxd_network_lb" "test" { + network = lxd_network.ovn.name + listen_address = "10.10.10.200" + description = "Load Balancer with Backend and Port" + + backend { + name = "%[1]s" + target_address = "%[2]s" + target_port = "%[3]s" + } + + port { + protocol = "%[4]s" + listen_port = "%[5]s" + target_backend = ["%[1]s"] + } +} +`, args...) + + return fmt.Sprintf("%s\n%s", ovnNetworkResource(), lbRes) +} + // ovnNetworkPreset returns configuration for OVN network and its parent bridge. // Network resource "lxd_network.ovn" provides dhcp range "10.0.0.1/24". func ovnNetworkResource() string {