Skip to content

Commit

Permalink
feature(lb): support for udp protocol in load balancers
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm authored and hkantare committed Apr 14, 2022
1 parent 48459df commit 8721546
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 6 deletions.
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func DataSourceIBMISLB() *schema.Resource {
Description: "Load Balancer type",
},

isLBUdpSupported: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this load balancer supports UDP.",
},

isLBStatus: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -335,6 +341,9 @@ func lbGetByName(d *schema.ResourceData, meta interface{}, name string) error {
if lb.RouteMode != nil {
d.Set(isLBRouteMode, *lb.RouteMode)
}
if lb.UDPSupported != nil {
d.Set(isLBUdpSupported, *lb.UDPSupported)
}
d.Set(isLBCrn, *lb.CRN)
d.Set(isLBOperatingStatus, *lb.OperatingStatus)
publicIpList := make([]string, 0)
Expand Down
38 changes: 38 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lb_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ func DataSourceIBMISLbProfiles() *schema.Resource {
Computed: true,
Description: "The route mode type for this load balancer profile, one of [fixed, dependent]",
},
"udp_supported": {
Type: schema.TypeBool,
Computed: true,
Description: "The UDP support for a load balancer with this profile",
},
"udp_supported_type": {
Type: schema.TypeString,
Computed: true,
Description: "The UDP support type for a load balancer with this profile",
},
},
},
},
Expand Down Expand Up @@ -92,6 +102,34 @@ func dataSourceIBMISLbProfilesRead(d *schema.ResourceData, meta interface{}) err
"href": *profileCollector.Href,
"family": *profileCollector.Family,
}
if profileCollector.UDPSupported != nil {
udpSupport := profileCollector.UDPSupported
switch reflect.TypeOf(udpSupport).String() {
case "*vpcv1.LoadBalancerProfileUDPSupportedFixed":
{
udp := udpSupport.(*vpcv1.LoadBalancerProfileUDPSupportedFixed)
l["udp_supported"] = udp.Value
l["udp_supported_type"] = udp.Type
}
case "*vpcv1.LoadBalancerProfileUDPSupportedDependent":
{
udp := udpSupport.(*vpcv1.LoadBalancerProfileUDPSupportedDependent)
if udp.Type != nil {
l["udp_supported_type"] = *udp.Type
}
}
case "*vpcv1.LoadBalancerProfileUDPSupported":
{
udp := udpSupport.(*vpcv1.LoadBalancerProfileUDPSupported)
if udp.Type != nil {
l["udp_supported_type"] = *udp.Type
}
if udp.Value != nil {
l["udp_supported"] = *udp.Value
}
}
}
}
if profileCollector.RouteModeSupported != nil {
routeMode := profileCollector.RouteModeSupported
switch reflect.TypeOf(routeMode).String() {
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func DataSourceIBMISLBS() *schema.Resource {
Computed: true,
Description: "Load Balancer name",
},
isLBUdpSupported: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this load balancer supports UDP.",
},
isLBRouteMode: {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -293,6 +298,9 @@ func getLbs(d *schema.ResourceData, meta interface{}) error {
if lb.RouteMode != nil {
lbInfo[isLBRouteMode] = *lb.RouteMode
}
if lb.UDPSupported != nil {
lbInfo[isLBUdpSupported] = *lb.UDPSupported
}
lbInfo[CRN] = *lb.CRN
lbInfo[ProvisioningStatus] = *lb.ProvisioningStatus

Expand Down
10 changes: 10 additions & 0 deletions ibm/service/vpc/resource_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
isLBResourceGroup = "resource_group"
isLBProfile = "profile"
isLBRouteMode = "route_mode"
isLBUdpSupported = "udp_supported"
isLBLogging = "logging"
isLBSecurityGroups = "security_groups"
isLBSecurityGroupsSupported = "security_group_supported"
Expand Down Expand Up @@ -208,6 +209,12 @@ func ResourceIBMISLB() *schema.Resource {
Description: "Indicates whether route mode is enabled for this load balancer",
},

isLBUdpSupported: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this load balancer supports UDP.",
},

isLBHostName: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -522,6 +529,9 @@ func lbGet(d *schema.ResourceData, meta interface{}, id string) error {

d.Set(isLBResourceGroup, *lb.ResourceGroup.ID)
d.Set(isLBHostName, *lb.Hostname)
if lb.UDPSupported != nil {
d.Set(isLBUdpSupported, *lb.UDPSupported)
}
tags, err := flex.GetTagsUsingCRN(meta, *lb.CRN)
if err != nil {
log.Printf(
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/vpc/resource_ibm_is_lb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func ResourceIBMISLBListener() *schema.Resource {
func ResourceIBMISLBListenerValidator() *validate.ResourceValidator {

validateSchema := make([]validate.ValidateSchema, 0)
protocol := "https, http, tcp"
protocol := "https, http, tcp, udp"
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: isLBListenerProtocol,
Expand Down
54 changes: 54 additions & 0 deletions ibm/service/vpc/resource_ibm_is_lb_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,35 @@ func TestAccIBMISLBListener_basic(t *testing.T) {
},
})
}
func TestAccIBMISLBListener_basic_udp(t *testing.T) {
var lb string
vpcname := fmt.Sprintf("tflblis-vpc-%d", acctest.RandIntRange(10, 100))
subnetname := fmt.Sprintf("tflblis-subnet-%d", acctest.RandIntRange(10, 100))
lbname := fmt.Sprintf("tflblis%d", acctest.RandIntRange(10, 100))

protocol1 := "udp"
port1 := "8080"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISLBListenerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISLBUdpListenerConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, port1, protocol1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISLBListenerExists("ibm_is_lb_listener.testacc_lb_listener", lb),
resource.TestCheckResourceAttr(
"ibm_is_lb.testacc_LB", "name", lbname),
resource.TestCheckResourceAttr(
"ibm_is_lb_listener.testacc_lb_listener", "port", port1),
resource.TestCheckResourceAttr(
"ibm_is_lb_listener.testacc_lb_listener", "protocol", protocol1),
),
},
},
})
}
func TestAccIBMISNLBRouteModeListener_basic(t *testing.T) {
var lb string
vpcname := fmt.Sprintf("tflblis-vpc-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -308,6 +337,31 @@ func testAccCheckIBMISLBListenerConfig(vpcname, subnetname, zone, cidr, lbname,
accept_proxy_protocol = true
}`, vpcname, subnetname, zone, cidr, lbname, port, protocol)

}
func testAccCheckIBMISLBUdpListenerConfig(vpcname, subnetname, zone, cidr, lbname, port, protocol string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet" {
name = "%s"
vpc = "${ibm_is_vpc.testacc_vpc.id}"
zone = "%s"
ipv4_cidr_block = "%s"
}
resource "ibm_is_lb" "testacc_LB" {
name = "%s"
subnets = ["${ibm_is_subnet.testacc_subnet.id}"]
profile = "network-fixed"
type = "public"
}
resource "ibm_is_lb_listener" "testacc_lb_listener" {
lb = "${ibm_is_lb.testacc_LB.id}"
port = %s
protocol = "%s"
}`, vpcname, subnetname, zone, cidr, lbname, port, protocol)

}

func testAccCheckIBMISLBListenerHttpsRedirectConfig(vpcname, subnetname, zone, cidr, lbname, port, protocol string) string {
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/vpc/resource_ibm_is_lb_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func ResourceIBMISLBPoolValidator() *validate.ResourceValidator {

validateSchema := make([]validate.ValidateSchema, 0)
algorithm := "round_robin, weighted_round_robin, least_connections"
protocol := "http, tcp, https"
protocol := "http, tcp, https, udp"
persistanceType := "source_ip, app_cookie, http_cookie"
proxyProtocol := "disabled, v1, v2"
validateSchema = append(validateSchema,
Expand Down
74 changes: 74 additions & 0 deletions ibm/service/vpc/resource_ibm_is_lb_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,49 @@ func TestAccIBMISLBPool_basic(t *testing.T) {
},
})
}
func TestAccIBMISLBPool_basic_udp(t *testing.T) {
var lb string
vpcname := fmt.Sprintf("tflbp-vpc-%d", acctest.RandIntRange(10, 100))
subnetname := fmt.Sprintf("tflbpc-name-%d", acctest.RandIntRange(10, 100))
name := fmt.Sprintf("tfcreate%d", acctest.RandIntRange(10, 100))
poolName := fmt.Sprintf("tflbpoolc%d", acctest.RandIntRange(10, 100))
alg1 := "round_robin"
protocol1 := "udp"
delay1 := "5"
retries1 := "2"
timeout1 := "2"
healthType1 := "http"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISLBPoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISLBPoolUdpConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, name, poolName, alg1, protocol1, delay1, retries1, timeout1, healthType1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISLBPoolExists("ibm_is_lb_pool.testacc_lb_pool", lb),
resource.TestCheckResourceAttr(
"ibm_is_lb.testacc_LB", "name", name),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "name", poolName),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "algorithm", alg1),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "protocol", protocol1),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "health_delay", delay1),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "health_retries", retries1),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "health_timeout", timeout1),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool.testacc_lb_pool", "health_type", healthType1),
),
},
},
})
}

func TestAccIBMISLBPool_port(t *testing.T) {
var lb string
Expand Down Expand Up @@ -376,6 +419,37 @@ func testAccCheckIBMISLBPoolConfig(vpcname, subnetname, zone, cidr, name, poolNa
health_type = "%s"
}`, vpcname, subnetname, zone, cidr, name, poolName, algorithm, protocol, delay, retries, timeout, healthType)

}
func testAccCheckIBMISLBPoolUdpConfig(vpcname, subnetname, zone, cidr, name, poolName, algorithm, protocol, delay, retries, timeout, healthType string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet" {
name = "%s"
vpc = "${ibm_is_vpc.testacc_vpc.id}"
zone = "%s"
ipv4_cidr_block = "%s"
}
resource "ibm_is_lb" "testacc_LB" {
name = "%s"
subnets = ["${ibm_is_subnet.testacc_subnet.id}"]
profile = "network-fixed"
type = "public"
}
resource "ibm_is_lb_pool" "testacc_lb_pool" {
name = "%s"
lb = "${ibm_is_lb.testacc_LB.id}"
algorithm = "%s"
protocol = "%s"
health_delay = %s
health_retries = %s
health_timeout = %s
health_type = "%s"
health_monitor_url = "/"
}`, vpcname, subnetname, zone, cidr, name, poolName, algorithm, protocol, delay, retries, timeout, healthType)

}

func testAccCheckIBMISLBPoolPortConfig(vpcname, subnetname, zone, cidr, name, poolName, algorithm, protocol, delay, retries, timeout, healthType, port string) string {
Expand Down
63 changes: 63 additions & 0 deletions ibm/service/vpc/resource_ibm_is_lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,69 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func testAccCheckIBMISLBUdpConfig(vpcname, subnetname, zone, cidr, name string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
ipv4_cidr_block = "%s"
}
resource "ibm_is_lb" "testacc_LB" {
name = "%s"
subnets = [ibm_is_subnet.testacc_subnet.id]
profile = "network-fixed"
type = "public"
}`, vpcname, subnetname, zone, cidr, name)

}
func TestAccIBMISLB_basic_udp(t *testing.T) {
var lb string
vpcname := fmt.Sprintf("tflb-vpc-%d", acctest.RandIntRange(10, 100))
subnetname := fmt.Sprintf("tflb-subnet-name-%d", acctest.RandIntRange(10, 100))
name := fmt.Sprintf("tfcreate%d", acctest.RandIntRange(10, 100))
name1 := fmt.Sprintf("tfupdate%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISLBDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISLBUdpConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISLBExists("ibm_is_lb.testacc_LB", lb),
resource.TestCheckResourceAttr(
"ibm_is_lb.testacc_LB", "name", name),
resource.TestCheckResourceAttrSet(
"ibm_is_lb.testacc_LB", "hostname"),
resource.TestCheckResourceAttr(
"ibm_is_lb.testacc_LB", "udp_supported", "true"),
resource.TestCheckResourceAttrSet(
"ibm_is_lb.testacc_LB", "udp_supported"),
),
},

{
Config: testAccCheckIBMISLBUdpConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, name1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISLBExists("ibm_is_lb.testacc_LB", lb),
resource.TestCheckResourceAttr(
"ibm_is_lb.testacc_LB", "name", name1),
resource.TestCheckResourceAttr(
"ibm_is_lb.testacc_LB", "udp_supported", "true"),
resource.TestCheckResourceAttrSet(
"ibm_is_lb.testacc_LB", "udp_supported"),
),
},
},
})
}

func TestAccIBMISLB_basic(t *testing.T) {
var lb string
vpcname := fmt.Sprintf("tflb-vpc-%d", acctest.RandIntRange(10, 100))
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/is_lb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ In addition to all argument reference list, you can access the following attribu
- `status` - (String) The status of load balancer.
- `tags` - (String) The tags associated with the load balancer.
- `type` - (String) The type of the load balancer.
- `udp_supported`- (Bool) Indicates whether this load balancer supports UDP.
2 changes: 1 addition & 1 deletion website/docs/d/is_lb_listener.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ Nested scheme for `policies`:

- `port_min` - (Integer) The inclusive lower bound of the range of ports used by this listener.Only load balancers in the `network` family support more than one port per listener.

- `protocol` - (String) The listener protocol. Load balancers in the `network` family support `tcp`. Load balancers in the `application` family support `tcp`, `http`, and `https`. Each listener in the load balancer must have a unique `port` and `protocol` combination.
- `protocol` - (String) The listener protocol. Load balancers in the `network` family support `tcp` and `udp`. Load balancers in the `application` family support `tcp`, `http`, and `https`. Each listener in the load balancer must have a unique `port` and `protocol` combination.

- `provisioning_status` - (String) The provisioning status of this listener.
2 changes: 1 addition & 1 deletion website/docs/d/is_lb_listeners.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ In addition to all argument references listed, you can access the following attr
- `port` - (Integer) The listener port number, or the inclusive lower bound of the port range. Each listener in the load balancer must have a unique `port` and `protocol` combination.
- `port_max` - (Integer) The inclusive upper bound of the range of ports used by this listener.Only load balancers in the `network` family support more than one port per listener.
- `port_min` - (Integer) The inclusive lower bound of the range of ports used by this listener.Only load balancers in the `network` family support more than one port per listener.
- `protocol` - (String) The listener protocol. Load balancers in the `network` family support `tcp`. Load balancers in the `application` family support `tcp`, `http`, and `https`. Each listener in the load balancer must have a unique `port` and `protocol` combination.
- `protocol` - (String) The listener protocol. Load balancers in the `network` family support `tcp` and `udp`. Load balancers in the `application` family support `tcp`, `http`, and `https`. Each listener in the load balancer must have a unique `port` and `protocol` combination.
- `provisioning_status` - (String) The provisioning status of this listener.
3 changes: 3 additions & 0 deletions website/docs/d/is_lb_profiles.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ You can access the following attribute references after your data source is crea
- `name` - (String) The name for this load balancer profile.
- `route_mode_supported` - (Bool) The route mode support for a load balancer with this profile.
- `route_mode_type` - (String) The route mode type for this load balancer profile, one of [fixed, dependent]
- `udp_supported` - (Bool) The UDP support for a load balancer with this profile.
- `udp_supported_type` - (String) The UDP support type for a load balancer with this profile, one of [fixed, dependent]

Loading

0 comments on commit 8721546

Please sign in to comment.