Skip to content

Commit

Permalink
Merge pull request #859 from F5Networks/devel_31082023
Browse files Browse the repository at this point in the history
adding pool attachment ipv6 support
  • Loading branch information
RavinderReddyF5 authored Aug 31, 2023
2 parents 1307d7b + 556d8d5 commit 88294a1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
24 changes: 19 additions & 5 deletions bigip/resource_bigip_ltm_pool_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func resourceBigipLtmPoolAttachmentCreate(ctx context.Context, d *schema.Resourc
poolName := d.Get("pool").(string)
nodeName := d.Get("node").(string)
poolPartition := strings.Split(poolName, "/")[1]
parts := strings.Split(nodeName, ":")
parts := SplitNodePort(nodeName)
log.Printf("[INFO][CREATE] Attaching Node :%+v to pool : %+v", nodeName, poolName)
re := regexp.MustCompile(`/([a-zA-z0-9?_-]+)/([a-zA-z0-9.?_-]+):(\d+)`)
match := re.FindStringSubmatch(nodeName)
Expand Down Expand Up @@ -146,6 +146,7 @@ func resourceBigipLtmPoolAttachmentCreate(ctx context.Context, d *schema.Resourc
return resourceBigipLtmPoolAttachmentUpdate(ctx, d, meta)
} else {
log.Println("[DEBUG] creating node from pool attachment resource")
// split IP address for route domains
ipNode := strings.Split(parts[0], "%")[0]
config := &bigip.PoolMember{
Name: nodeName,
Expand Down Expand Up @@ -179,7 +180,7 @@ func resourceBigipLtmPoolAttachmentUpdate(ctx context.Context, d *schema.Resourc
re := regexp.MustCompile(`/([a-zA-z0-9?_-]+)/([a-zA-z0-9.?_-]+):(\d+)`)
match := re.FindStringSubmatch(nodeName)
if match != nil {
parts := strings.Split(nodeName, ":")
parts := SplitNodePort(nodeName)
node1, err := client.GetNode(parts[0])
if err != nil {
return diag.FromErr(err)
Expand All @@ -190,7 +191,7 @@ func resourceBigipLtmPoolAttachmentUpdate(ctx context.Context, d *schema.Resourc
return nil
}

poolMem := strings.Split(nodeName, ":")[0]
poolMem := SplitNodePort(nodeName)[0]
nodeName1 := strings.Split(poolMem, "/")[2]
poolName := d.Get("pool").(string)
config := &bigip.PoolMember{
Expand Down Expand Up @@ -237,9 +238,10 @@ func resourceBigipLtmPoolAttachmentUpdate(ctx context.Context, d *schema.Resourc
poolName := d.Id()
poolPartition := strings.Split(poolName, "/")[1]
nodeName := d.Get("node").(string)
parts := strings.Split(nodeName, ":")
parts := SplitNodePort(nodeName)
ipNode := strings.Split(parts[0], "%")[0]
poolMem := fmt.Sprintf("/%s/%s", poolPartition, nodeName)
log.Printf("[DEBUG] Modifying pool member (%+v) from pool (%+v)", poolMem, poolName)
config := &bigip.PoolMember{
Name: nodeName,
FullPath: poolMem,
Expand All @@ -251,7 +253,7 @@ func resourceBigipLtmPoolAttachmentUpdate(ctx context.Context, d *schema.Resourc
Ratio: d.Get("ratio").(int),
Monitor: d.Get("monitor").(string),
}
log.Printf("[INFO] Modifying pool member (%+v) from pool (%+v)", poolMem, poolName)
log.Printf("[DEBUG] Modifying pool member config:%+v", config)
userState := d.Get("state").(string)
if userState == "enabled" {
config.Session = "user-enabled"
Expand Down Expand Up @@ -416,3 +418,15 @@ func resourceBigipLtmPoolAttachmentImport(ctx context.Context, d *schema.Resourc

return []*schema.ResourceData{d}, nil
}
func SplitNodePort(s string) []string {
m := strings.Index(s, ":")
n := strings.Index(s, ".")
switch {
case m > n:
return strings.Split(s, ":")
case m < n:
return strings.Split(s, ".")
default:
return nil
}
}
29 changes: 13 additions & 16 deletions bigip/resource_bigip_ltm_pool_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ resource "bigip_ltm_pool" "test-pool" {
}
`
var TestPoolResource5 = `
resource "bigip_ltm_node" "test-node" {
name = "` + TestNodeName + `"
address = "10.10.100.11"
connection_limit = "0"
dynamic_ratio = "1"
monitor = "default"
rate_limit = "disabled"
}
resource "bigip_ltm_pool" "test-pool" {
name = "` + TestPoolName + `"
monitors = ["/Common/http"]
Expand Down Expand Up @@ -349,10 +341,10 @@ func TestAccBigipLtmPoolAttachment_StateSet(t *testing.T) {
testCheckPoolAttachment("/Common/test_pool_pa_tc1", "/Common/10.10.100.13:80", true),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "state", "disabled"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "pool", "/Common/test_pool_pa_tc2"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "state", "forced_offline"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "pool", "/Common/test_pool_pa_tc3"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "state", "enabled"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc2", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc2", "state", "forced_offline"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc3", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc3", "state", "enabled"),
),
},
},
Expand All @@ -375,10 +367,10 @@ func TestAccBigipLtmPoolAttachment_ModifyState(t *testing.T) {
testCheckPoolAttachment("/Common/test_pool_pa_tc1", "/Common/10.10.100.13:80", true),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "state", "forced_offline"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "pool", "/Common/test_pool_pa_tc2"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "state", "enabled"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "pool", "/Common/test_pool_pa_tc3"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc1", "state", "disabled"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc2", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc2", "state", "enabled"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc3", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc3", "state", "disabled"),
),
},
},
Expand All @@ -399,10 +391,15 @@ func TestAccBigipLtmPoolAttachmentTestCases(t *testing.T) {
testCheckPoolAttachment("/Common/test_pool_pa_tc1", "/Common/test3.com:80", true),
testCheckPoolAttachment("/Common/test_pool_pa_tc1", "/Common/test_node_pa_tc5:80", true),
testCheckPoolAttachment("/TEST3/test_pool_pa_tc10", "/TEST3/2.3.2.2%50:8080", true),
testCheckPoolAttachment("/Common/tf-mypool", "/Common/2003::4.80", true),
testCheckPoolAttachment("/Common/tf-mypool", "/Common/fe80:0:0:0:0:0:0:12.80", true),
testCheckPoolAttachment("/Common/tf-mypool", "/Common/192.168.100.11:80", true),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc9", "pool", "/Common/test_pool_pa_tc9"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc8", "pool", "/Common/test_pool_pa_tc1"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc8", "node", "1.1.12.2:80"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.pa_tc6", "node", "/Common/test3.com:80"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.ipv6attach2", "node", "2003::4.80"),
resource.TestCheckResourceAttr("bigip_ltm_pool_attachment.ipv6attach3", "node", "fe80:0:0:0:0:0:0:12.80"),
),
},
},
Expand Down
23 changes: 18 additions & 5 deletions docs/resources/bigip_ltm_pool_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: "bigip"
page_title: "BIG-IP: bigip_ltm_pool_attachment"
subcategory: "Local Traffic Manager(LTM)"
description: |-
Provides details about bigip_ltm_pool_attachment resource
Provides details about bigip_ltm_pool_attachment resource
---

# bigip\_ltm\_pool\_attachment
Expand All @@ -12,11 +12,18 @@ description: |-

## Example Usage

There are two ways to use `bigip_ltm_pool_attachment` resource for `node` attribute

There are two ways to use ltm_pool_attachment resource, where we can take node reference from ltm_node or we can specify node directly with ip:port/fqdn:port which will also create node and atach to pool.
* It can be reference from `bigip_ltm_node` (or)
* It can be specify directly with `ipv4:port`/`fqdn:port`/`ipv6.port` which will also create node and attach member to pool.

~> For adding IPv6 node/member to pool it should be specific in `node` attribute in format like `ipv6_address.port`.
IPv4 should be specified as `ipv4_address:port`

### Pool attachment with node directly taking `ip:port` / `fqdn:port`

### Usage Pool attachment with node/member directly attaching to pool.

node can be specified in format `ipv4:port` / `fqdn:port` / `ipv6.port`

```hcl
resource "bigip_ltm_monitor" "monitor" {
Expand All @@ -34,14 +41,20 @@ resource "bigip_ltm_pool" "pool" {
allow_nat = "yes"
}
resource "bigip_ltm_pool_attachment" "attach_node" {
# attaching ipv4 address with service port
resource "bigip_ltm_pool_attachment" "ipv4_node_attach" {
pool = bigip_ltm_pool.pool.name
node = "1.1.1.1:80"
}
# attaching ipv6 address with service port
resource "bigip_ltm_pool_attachment" "ipv6_node_attach" {
pool = bigip_ltm_pool.pool.name
node = "2003::4.80"
}
```

### Pool attachment with node referenced from `bigip_ltm_node`
### Usage Pool attachment with node referenced from `bigip_ltm_node`

```hcl
resource "bigip_ltm_monitor" "monitor" {
Expand Down
22 changes: 22 additions & 0 deletions examples/bigip_ltm_pool_attachment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ resource "bigip_ltm_pool_attachment" "pa_tc11" {
connection_limit = 11
}

resource "bigip_ltm_pool" "tf-mypool" {
name = "/Common/tf-mypool"
monitors = ["/Common/http"]
allow_nat = "yes"
allow_snat = "yes"
load_balancing_mode = "round-robin"
}

resource "bigip_ltm_pool_attachment" "ipv6attach2" {
pool = bigip_ltm_pool.tf-mypool.name
node = "2003::4.80"
}
resource "bigip_ltm_pool_attachment" "ipv6attach3" {
pool = bigip_ltm_pool.tf-mypool.name
node = "fe80:0:0:0:0:0:0:12.80"
}
resource "bigip_ltm_pool_attachment" "ipv4attach2" {
pool = bigip_ltm_pool.tf-mypool.name
node = "192.168.100.11:80"
}


//resource "bigip_ltm_pool" "pool" {
// name = "/Common/Axiom_Environment_APP1_Pool"
// load_balancing_mode = "round-robin"
Expand Down

0 comments on commit 88294a1

Please sign in to comment.