From 556d8d57b1a0dc1e281dee23c69b41897143b933 Mon Sep 17 00:00:00 2001 From: chinthalapalli Date: Thu, 31 Aug 2023 21:03:34 +0530 Subject: [PATCH] adding pool attachment ipv6 support --- bigip/resource_bigip_ltm_pool_attachment.go | 24 +++++++++++---- ...resource_bigip_ltm_pool_attachment_test.go | 29 +++++++++---------- docs/resources/bigip_ltm_pool_attachment.md | 23 +++++++++++---- examples/bigip_ltm_pool_attachment.tf | 22 ++++++++++++++ 4 files changed, 72 insertions(+), 26 deletions(-) diff --git a/bigip/resource_bigip_ltm_pool_attachment.go b/bigip/resource_bigip_ltm_pool_attachment.go index 9959b4646..e7acf21ad 100644 --- a/bigip/resource_bigip_ltm_pool_attachment.go +++ b/bigip/resource_bigip_ltm_pool_attachment.go @@ -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) @@ -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, @@ -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) @@ -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{ @@ -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, @@ -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" @@ -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 + } +} diff --git a/bigip/resource_bigip_ltm_pool_attachment_test.go b/bigip/resource_bigip_ltm_pool_attachment_test.go index e35333eb3..327b8c4dc 100644 --- a/bigip/resource_bigip_ltm_pool_attachment_test.go +++ b/bigip/resource_bigip_ltm_pool_attachment_test.go @@ -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"] @@ -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"), ), }, }, @@ -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"), ), }, }, @@ -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"), ), }, }, diff --git a/docs/resources/bigip_ltm_pool_attachment.md b/docs/resources/bigip_ltm_pool_attachment.md index 381b81776..b4c34a633 100644 --- a/docs/resources/bigip_ltm_pool_attachment.md +++ b/docs/resources/bigip_ltm_pool_attachment.md @@ -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 @@ -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" { @@ -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" { diff --git a/examples/bigip_ltm_pool_attachment.tf b/examples/bigip_ltm_pool_attachment.tf index 8290ad5a7..916496d2f 100644 --- a/examples/bigip_ltm_pool_attachment.tf +++ b/examples/bigip_ltm_pool_attachment.tf @@ -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"