Skip to content

Commit

Permalink
Merge pull request #952 from F5Networks/devel
Browse files Browse the repository at this point in the history
devel sync to master
  • Loading branch information
RavinderReddyF5 authored Mar 27, 2024
2 parents f7c3171 + 1dcc25b commit e92b18c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
37 changes: 26 additions & 11 deletions bigip/resource_bigip_as3.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ func resourceBigipAs3() *schema.Resource {
"tenant_name": {
Type: schema.TypeString,
Optional: true,
Deprecated: "this attribute is no longer in use",
Description: "Name of Tenant",
Description: "Name of Tenant. This name is used only in the case of Per-Application Deployment. If it is not provided, then a random name would be generated.",
},
"tenant_filter": {
Type: schema.TypeString,
Expand Down Expand Up @@ -195,24 +194,33 @@ func resourceBigipAs3Create(ctx context.Context, d *schema.ResourceData, meta in
log.Printf("[DEBUG] perApplication:%+v", perApplication)

if perApplication && len(tenantList) == 0 {
tenant, err := GenerateRandomString(10)
log.Printf("[DEBUG] tenant name generated:%+v", tenant)
if err != nil {
return diag.FromErr(fmt.Errorf("could not generate random tenant name"))
log.Printf("[INFO] Creating As3 config perApplication : tenant name :%+v", d.Get("tenant_name").(string))
var tenant string
if d.Get("tenant_name").(string) != "" {
tenant = d.Get("tenant_name").(string)
} else {
tenant, err = GenerateRandomString(10)
if err != nil {
return diag.FromErr(fmt.Errorf("could not generate random tenant name"))
}
}
log.Printf("[DEBUG] tenant name :%+v", tenant)

applicationList := client.GetAppsList(as3Json)
err, taskID := client.PostPerAppBigIp(as3Json, tenant)
log.Printf("[DEBUG] task Id from deployment :%+v", taskID)
if err != nil {
return diag.FromErr(fmt.Errorf("posting as3 config failed for tenants:(%s) with error: %v", tenantFilter, err))
}
tenantCount = append(tenantCount, tenant)
_ = d.Set("tenant_filter", tenant)
_ = d.Set("tenant_name", tenant)
_ = d.Set("tenant_list", tenant)
_ = d.Set("task_id", taskID)
_ = d.Set("application_list", applicationList)
_ = d.Set("per_app_mode", true)
} else {
log.Printf("[INFO] Creating As3 config for tenants:%+v", tenantList)
log.Printf("[INFO] Creating As3 config traditionally for tenants:%+v", tenantList)
tenantCount := strings.Split(tenantList, ",")
if tenantFilter != "" {
log.Printf("[DEBUG] tenantFilter:%+v", tenantFilter)
Expand Down Expand Up @@ -244,6 +252,7 @@ func resourceBigipAs3Create(ctx context.Context, d *schema.ResourceData, meta in
log.Printf("[DEBUG] ID for resource :%+v", d.Get("tenant_list").(string))
_ = d.Set("task_id", taskID)
_ = d.Set("per_app_mode", false)
_ = d.Set("tenant_name", tenantList)
}

if !client.Teem {
Expand Down Expand Up @@ -353,7 +362,7 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
log.Printf("[DEBUG] perApplication:%+v", perApplication)
if d.Get("per_app_mode").(bool) {
if perApplication && len(tenantList) == 0 {
oldTenantList := d.Get("tenant_list").(string)
oldTenantList := d.Id()
log.Printf("[INFO] Updating As3 Config for tenant:%s with Per-Application Mode:%v", oldTenantList, perApplication)
err, task_id := client.PostPerAppBigIp(as3Json, oldTenantList)
log.Printf("[DEBUG] task_id from PostPerAppBigIp:%+v", task_id)
Expand All @@ -363,6 +372,7 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
// tenantCount = append(tenantCount, tenant)
_ = d.Set("tenant_list", oldTenantList)
_ = d.Set("task_id", task_id)
_ = d.Set("tenant_filter", oldTenantList)
} else {
if !perApplication {
return diag.FromErr(fmt.Errorf("Per-Application should be true in Big-IP Setting"))
Expand All @@ -371,7 +381,7 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
}
}
} else {
log.Printf("[INFO] Updating As3 Config for tenants:%s", tenantList)
log.Printf("[INFO] Updating As3 Config Traditionally for tenants:%s", tenantList)
oldTenantList := d.Get("tenant_list").(string)
tenantFilter := d.Get("tenant_filter").(string)
if tenantFilter == "" {
Expand Down Expand Up @@ -403,16 +413,21 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
log.Printf("[DEBUG] successfulTenants :%+v", successfulTenants)
if err != nil {
if successfulTenants == "" {
return diag.FromErr(fmt.Errorf("Error updating json %s: %v", tenantList, err))
return diag.FromErr(fmt.Errorf("error updating json %s: %v", tenantList, err))
}
_ = d.Set("tenant_list", successfulTenants)
if len(successfulTenants) != len(tenantList) {
return diag.FromErr(err)
}
}
_ = d.Set("task_id", taskID)
_ = d.Set("tenant_name", tenantList)
}
if d.Get("tenant_filter").(string) != "" {
createdTenants = d.Get("tenant_filter").(string)
} else {
createdTenants = d.Get("tenant_list").(string)
}
createdTenants = d.Get("tenant_list").(string)
return resourceBigipAs3Read(ctx, d, meta)
}

Expand Down
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 e92b18c

Please sign in to comment.