Skip to content

Commit

Permalink
Allow adding protocols more than 2 during creation
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
Praveengostu authored and sakshiag committed May 2, 2018
1 parent 4cb5f7c commit 6fa7b01
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 9 deletions.
27 changes: 18 additions & 9 deletions ibm/resource_ibm_lbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func resourceIBMLbaas() *schema.Resource {
Type: schema.TypeSet,
Description: "Protocols to be assigned to this load balancer.",
Optional: true,
MaxItems: 2,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"frontend_protocol": {
Expand Down Expand Up @@ -231,6 +230,24 @@ func resourceIBMLbaasCreate(d *schema.ResourceData, meta interface{}) error {

d.SetId(*lbaasLB.Uuid)

if v, ok := d.GetOk("protocols"); ok && v.(*schema.Set).Len() > 0 {
listenerService := services.GetNetworkLBaaSListenerService(sess.SetRetries(0))
protocolParam, err := expandProtocols(v.(*schema.Set).List())
if err != nil {
return fmt.Errorf("Error adding protocols to Load balancer: %s", err)
}
_, err = listenerService.UpdateLoadBalancerProtocols(sl.String(d.Id()), protocolParam)
if err != nil {
return fmt.Errorf("Error adding protocols: %#v", err)
}
_, err = waitForLbaasLBAvailable(d, meta)
if err != nil {
return fmt.Errorf(
"Error waiting for load balancer (%s) to become ready: %s", d.Id(), err)
}

}

return resourceIBMLbaasRead(d, meta)
}

Expand Down Expand Up @@ -409,14 +426,6 @@ func buildLbaasLBProductOrderContainer(d *schema.ResourceData, sess *session.Ses
productOrderContainer.Description = sl.String(d.(string))
}

if v, ok := d.GetOk("protocols"); ok && v.(*schema.Set).Len() > 0 {
protocolParam, err := expandProtocols(v.(*schema.Set).List())
if err != nil {
return &datatypes.Container_Product_Order_Network_LoadBalancer_AsAService{}, err
}
productOrderContainer.ProtocolConfigurations = protocolParam
}

return &productOrderContainer, nil
}

Expand Down
62 changes: 62 additions & 0 deletions ibm/resource_ibm_lbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,32 @@ func TestAccIBMLbaas_Basic(t *testing.T) {
})
}

func TestAccIBMLbaas_with_more_protocols(t *testing.T) {
name := fmt.Sprintf("terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIBMLbaasDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMLbaasConfig_MoreThanTwoProtocols(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ibm_lbaas.lbaas", "name", name),
resource.TestCheckResourceAttr(
"ibm_lbaas.lbaas", "description", "desc-used for terraform uat"),
resource.TestCheckResourceAttr(
"ibm_lbaas.lbaas", "datacenter", lbaasDatacenter),
resource.TestCheckResourceAttr(
"ibm_lbaas.lbaas", "subnets.#", "1"),
resource.TestCheckResourceAttr(
"ibm_lbaas.lbaas", "protocols.#", "3"),
),
},
},
})
}

func TestAccIBMLbaas_importBasic(t *testing.T) {
name := fmt.Sprintf("terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -282,6 +308,42 @@ resource "ibm_lbaas" "lbaas" {
`, name, lbaasSubnetId)
}

func testAccCheckIBMLbaasConfig_MoreThanTwoProtocols(name string) string {
return fmt.Sprintf(`
resource "ibm_lbaas" "lbaas" {
name = "%s"
description = "desc-used for terraform uat"
subnets = ["%s"]
protocols = [{
"frontend_protocol" = "HTTP"
"frontend_port" = 9090
"backend_protocol" = "HTTP"
"backend_port" = 80
"load_balancing_method" = "round_robin"
"session_stickiness" = "SOURCE_IP"
},
{
"frontend_protocol" = "HTTP"
"frontend_port" = 80
"backend_protocol" = "HTTP"
"backend_port" = 80
"load_balancing_method" = "round_robin"
},
{
"frontend_protocol" = "HTTP"
"frontend_port" = 8081
"backend_protocol" = "HTTP"
"backend_port" = 80
"load_balancing_method" = "round_robin"
}]
}
`, name, lbaasSubnetId)
}

func testAccCheckIBMLbaasConfig_update(name string) string {
return fmt.Sprintf(`
resource "ibm_lbaas" "lbaas" {
Expand Down

0 comments on commit 6fa7b01

Please sign in to comment.