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 committed Apr 6, 2022
1 parent 3487be2 commit 98805d8
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/IBM/scc-go-sdk/v3 v3.1.6
github.com/IBM/schematics-go-sdk v0.1.3
github.com/IBM/secrets-manager-go-sdk v0.1.19
github.com/IBM/vpc-go-sdk v0.17.0
github.com/IBM/vpc-go-sdk v0.19.0
github.com/PromonLogicalis/asn1 v0.0.0-20190312173541-d60463189a56 // indirect
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/Shopify/sarama v1.29.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ github.com/IBM/secrets-manager-go-sdk v0.1.19 h1:0GPs5EoTaWNsjo4QPj64GNxlWfN8VHJ
github.com/IBM/secrets-manager-go-sdk v0.1.19/go.mod h1:eO3dBhzPrHkkt+yPex/jB2xD6qHZxBko+Aw+0tfqHeA=
github.com/IBM/vpc-go-sdk v0.17.0 h1:H9qsEx1UJoAR79s1R7n3bGPdOPW6+wLNEUyCjnesaxs=
github.com/IBM/vpc-go-sdk v0.17.0/go.mod h1:+fTuJIR/SWXru/B5XEANwV4GCLV5fRppFEzlYGwGm7k=
github.com/IBM/vpc-go-sdk v0.19.0 h1:f6fqF4W1h3dtAk+U8XLEUv1lPZ8jnvRoEFkTgOBPw8Q=
github.com/IBM/vpc-go-sdk v0.19.0/go.mod h1:KCdyxbJdWtN4pyWC1SqLH0Jk/y4ed8nv9gZb4ZxfepQ=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
Expand Down
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 @@ -51,6 +51,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 @@ -295,6 +301,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 @@ -260,6 +265,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
6 changes: 3 additions & 3 deletions ibm/service/vpc/resource_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ func instanceCreateByVolume(d *schema.ResourceData, meta interface{}, profile, n
if err != nil {
return err
}
instanceproto := &vpcv1.InstancePrototypeInstanceByVolume{
instanceproto := &vpcv1.InstancePrototypeInstanceBySourceSnapshot{
Zone: &vpcv1.ZoneIdentity{
Name: &zone,
},
Expand Down Expand Up @@ -1380,7 +1380,7 @@ func instanceCreateByVolume(d *schema.ResourceData, meta interface{}, profile, n

if boot, ok := d.GetOk(isInstanceBootVolume); ok {
bootvol := boot.([]interface{})[0].(map[string]interface{})
var volTemplate = &vpcv1.VolumeAttachmentVolumePrototypeInstanceByVolumeContext{}
var volTemplate = &vpcv1.VolumePrototypeInstanceBySourceSnapshotContext{}

name, ok := bootvol[isInstanceBootAttachmentName]
namestr := name.(string)
Expand Down Expand Up @@ -1413,7 +1413,7 @@ func instanceCreateByVolume(d *schema.ResourceData, meta interface{}, profile, n
}
}
deletebool := true
instanceproto.BootVolumeAttachment = &vpcv1.VolumeAttachmentPrototypeInstanceByVolumeContext{
instanceproto.BootVolumeAttachment = &vpcv1.VolumeAttachmentPrototypeInstanceBySourceSnapshotContext{
DeleteVolumeOnInstanceDelete: &deletebool,
Volume: volTemplate,
}
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 @@ -175,6 +176,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 @@ -469,6 +476,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 @@ -176,7 +176,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 @@ -248,6 +277,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
Loading

0 comments on commit 98805d8

Please sign in to comment.