diff --git a/internal/network/resource_network_lb.go b/internal/network/resource_network_lb.go index c73e14e1..2b88c5c3 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{ @@ -130,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{ 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 {