diff --git a/bigip/resource_bigip_ltm_virtual_address.go b/bigip/resource_bigip_ltm_virtual_address.go index 48846a06..906d499f 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) + } + + 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 ba3761dc..f3dc294d 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() {