From efd066f9b246612dcb39708ebcc052b5771f7215 Mon Sep 17 00:00:00 2001 From: ramaniprateek Date: Fri, 16 Feb 2024 13:35:02 +0530 Subject: [PATCH 1/2] Fix Issue 936 - virtual address deletion or replacement fails when the name field contains the route domain --- bigip/resource_bigip_ltm_virtual_address.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bigip/resource_bigip_ltm_virtual_address.go b/bigip/resource_bigip_ltm_virtual_address.go index 48846a062..a9a30c913 100644 --- a/bigip/resource_bigip_ltm_virtual_address.go +++ b/bigip/resource_bigip_ltm_virtual_address.go @@ -10,6 +10,8 @@ import ( "context" "fmt" "log" + "net/url" + "strings" bigip "github.com/f5devcentral/go-bigip" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -175,7 +177,7 @@ func resourceBigipLtmVirtualAddressUpdate(ctx context.Context, d *schema.Resourc client := meta.(*bigip.BigIP) name := d.Id() - + name = modifyNameForRouteDomain(name) va := hydrateVirtualAddress(d) err := client.ModifyVirtualAddress(name, va) @@ -211,6 +213,7 @@ func resourceBigipLtmVirtualAddressDelete(ctx context.Context, d *schema.Resourc d.SetId("") return nil } + name = modifyNameForRouteDomain(name) err := client.DeleteVirtualAddress(name) if err != nil { log.Printf("[ERROR] Unable to Delete Virtual Address (%s) (%v)", name, err) @@ -219,3 +222,14 @@ func resourceBigipLtmVirtualAddressDelete(ctx context.Context, d *schema.Resourc d.SetId("") return nil } + +func modifyNameForRouteDomain(name string) string { + if idx := strings.LastIndex(name, "/"); idx != -1 { + name = name[:idx+1] + url.PathEscape(name[idx+1:]) + } else { + name = url.PathEscape(name) + } + + fmt.Printf("[INFO] updated name %v", name) + return name +} From 47925371d27be8038266d8b9ab882521886136a8 Mon Sep 17 00:00:00 2001 From: ramaniprateek Date: Fri, 16 Feb 2024 17:52:14 +0530 Subject: [PATCH 2/2] Added Acceptance Test --- bigip/resource_bigip_ltm_virtual_address.go | 2 +- ...resource_bigip_ltm_virtual_address_test.go | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/bigip/resource_bigip_ltm_virtual_address.go b/bigip/resource_bigip_ltm_virtual_address.go index a9a30c913..906d499f6 100644 --- a/bigip/resource_bigip_ltm_virtual_address.go +++ b/bigip/resource_bigip_ltm_virtual_address.go @@ -230,6 +230,6 @@ func modifyNameForRouteDomain(name string) string { name = url.PathEscape(name) } - fmt.Printf("[INFO] updated name %v", name) + log.Printf("[INFO] updated name %v", name) return name } diff --git a/bigip/resource_bigip_ltm_virtual_address_test.go b/bigip/resource_bigip_ltm_virtual_address_test.go index ba3761dc8..f3dc294de 100644 --- a/bigip/resource_bigip_ltm_virtual_address_test.go +++ b/bigip/resource_bigip_ltm_virtual_address_test.go @@ -25,6 +25,20 @@ resource "bigip_ltm_virtual_address" "test-va" { traffic_group = "/Common/none" } ` +var TEST_VA_ROUTE_DOMAIN_CONFIG = ` +resource "bigip_ltm_virtual_address" "test-va" { + name = "/Common/1.1.1.1%50" + advertize_route = "selective" + icmp_echo = "any" + } +` +var TEST_VA_ROUTE_DOMAIN_CHANGED_CONFIG = ` +resource "bigip_ltm_virtual_address" "test-va" { + name = "/Common/1.1.1.1%50" + advertize_route = "selective" + icmp_echo = "selective" + } +` var TEST_VA_RESOURCE = fmt.Sprintf(TEST_VA_CONFIG, TEST_VA_NAME) var TEST_VA_RESOURCE_NAME_CHANGED = fmt.Sprintf(TEST_VA_CONFIG, TEST_VA_NAME_CHANGED) @@ -54,6 +68,35 @@ func TestAccBigipLtmVA_create(t *testing.T) { }) } +func TestAccBigipLtmVATCIssue936(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAcctPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testCheckVAsDestroyed, + Steps: []resource.TestStep{ + { + Config: TEST_VA_ROUTE_DOMAIN_CONFIG, + Check: resource.ComposeTestCheckFunc( + testCheckVAExists("/Common/1.1.1.1%50", true), + resource.TestCheckResourceAttr("bigip_ltm_virtual_address.test-va", "name", "/Common/1.1.1.1%50"), + resource.TestCheckResourceAttr("bigip_ltm_virtual_address.test-va", "icmp_echo", "any"), + ), + }, + { + Config: TEST_VA_ROUTE_DOMAIN_CHANGED_CONFIG, + PreConfig: func() { testCheckVAExists(TEST_VA_NAME, true) }, + Check: resource.ComposeTestCheckFunc( + testCheckVAExists("/Common/1.1.1.1%50", true), + resource.TestCheckResourceAttr("bigip_ltm_virtual_address.test-va", "name", "/Common/1.1.1.1%50"), + resource.TestCheckResourceAttr("bigip_ltm_virtual_address.test-va", "icmp_echo", "selective"), + ), + }, + }, + }) +} + func TestAccBigipLtmVA_import(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() {