Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 936 - virtual address deletion or replacement fails when t… #942

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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