Skip to content

Commit

Permalink
Merge pull request #942 from F5Networks/issue-936
Browse files Browse the repository at this point in the history
Fix Issue 936 -  virtual address deletion or replacement fails when t…
  • Loading branch information
RavinderReddyF5 authored Feb 28, 2024
2 parents f7c3171 + 4792537 commit d9ba3ae
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bigip/resource_bigip_ltm_virtual_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
43 changes: 43 additions & 0 deletions bigip/resource_bigip_ltm_virtual_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d9ba3ae

Please sign in to comment.