Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
added nodes field back to pool resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjay Shitole committed Oct 25, 2018
1 parent f10a427 commit d8db259
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
56 changes: 53 additions & 3 deletions bigip/resource_bigip_ltm_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package bigip

import (
"fmt"
"log"
"strings"

"github.com/f5devcentral/go-bigip"
"github.com/hashicorp/terraform/helper/schema"
"log"
"regexp"
"strings"
)

var nodeVALIDATION = regexp.MustCompile(":\\d{2,5}$")

func resourceBigipLtmPool() *schema.Resource {
return &schema.Resource{
Create: resourceBigipLtmPoolCreate,
Expand All @@ -28,6 +30,13 @@ func resourceBigipLtmPool() *schema.Resource {
ForceNew: true,
ValidateFunc: validateF5Name,
},
"nodes": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Optional: true,
Description: "Nodes to add to the pool. Format node_name:port. e.g. node01:443",
},
"monitors": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -117,7 +126,22 @@ func resourceBigipLtmPoolRead(d *schema.ResourceData, meta interface{}) error {
d.SetId("")
return nil
}
nodes, err := client.PoolMembers(name)
if err != nil {
return err
}

if nodes == nil {
log.Printf("[WARN] Pool Member (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

nodeNames := make([]string, 0, len(nodes.PoolMembers))

for _, node := range nodes.PoolMembers {
nodeNames = append(nodeNames, node.FullPath)
}
if err := d.Set("allow_nat", pool.AllowNAT); err != nil {
return fmt.Errorf("[DEBUG] Error saving AllowNAT to state for Pool (%s): %s", d.Id(), err)
}
Expand Down Expand Up @@ -193,6 +217,32 @@ func resourceBigipLtmPoolUpdate(d *schema.ResourceData, meta interface{}) error
return err
}

//members
nodes, err := client.PoolMembers(name)
if err != nil {
return err
}

nodeNames := make([]string, 0, len(nodes.PoolMembers))

for _, node := range nodes.PoolMembers {
nodeNames = append(nodeNames, node.Name)
}

existing := makeStringSet(&nodeNames)
incoming := d.Get("nodes").(*schema.Set)
delete := existing.Difference(incoming)
add := incoming.Difference(existing)
if delete.Len() > 0 {
for _, d := range delete.List() {
client.DeletePoolMember(name, d.(string))
}
}
if add.Len() > 0 {
for _, d := range add.List() {
client.AddPoolMember(name, d.(string))
}
}
return resourceBigipLtmPoolRead(d, meta)
}

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/bigip_ltm_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Resources should be named with their "full path". The full path is the combinati
resource "bigip_ltm_pool" "pool" {
name = "/Common/terraform-pool"
load_balancing_mode = "round-robin"
nodes = ["11.1.1.101:80", "11.1.1.102:443"]
monitors = ["${bigip_ltm_monitor.monitor.name}","${bigip_ltm_monitor.monitor2.name}"]
allow_snat = "yes"
allow_nat = "yes"
Expand All @@ -38,3 +39,5 @@ resource "bigip_ltm_pool" "pool" {
* `allow_snat` - (Optional)

* `load_balancing_mode` - (Optional, Default = round-robin)

* `nodes` - (Optional) Nodes to add to the pool. Format node_name:port. e.g. node01:443

0 comments on commit d8db259

Please sign in to comment.