Skip to content

Commit

Permalink
Merge pull request #995 from F5Networks/per-app-as3
Browse files Browse the repository at this point in the history
Added Per-App Update Changes
  • Loading branch information
RavinderReddyF5 committed Jun 18, 2024
2 parents 66141b0 + 8966795 commit c0aef75
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
17 changes: 17 additions & 0 deletions bigip/resource_bigip_as3.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
defer m.Unlock()
as3Json := d.Get("as3_json").(string)
log.Printf("[INFO] Updating As3 Config :%s", as3Json)
oldApplicationList := d.Get("application_list").(string)
tenantList, _, applicationList := client.GetTenantList(as3Json)
_ = d.Set("application_list", applicationList)
perApplication, err := client.CheckSetting()
Expand All @@ -373,6 +374,20 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
if d.Get("per_app_mode").(bool) {
if perApplication && len(tenantList) == 0 {
oldTenantList := d.Id()
log.Printf("[INFO] oldApplicationList :%s", oldApplicationList)
curApplicationList := client.GetAppsList(as3Json)
log.Printf("[INFO] curApplicationList :%s", curApplicationList)
for _, appName := range strings.Split(oldApplicationList, ",") {
if !strings.Contains(curApplicationList, appName) {
log.Printf("[INFO] Deleting As3 Config for Application:%s in Tenant:%v", appName, oldTenantList)
err := client.DeletePerApplicationAs3Bigip(oldTenantList, appName)
if err != nil {
log.Printf("[ERROR] Unable to DeleteContext: %v :", err)
return diag.FromErr(err)
}
}
}

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 @@ -383,6 +398,8 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in
_ = d.Set("tenant_list", oldTenantList)
_ = d.Set("task_id", task_id)
_ = d.Set("tenant_filter", oldTenantList)
_ = d.Set("application_list", curApplicationList)

} else {
if !perApplication {
return diag.FromErr(fmt.Errorf("Per-Application should be true in Big-IP Setting"))
Expand Down
39 changes: 38 additions & 1 deletion bigip/resource_bigip_as3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ resource "bigip_as3" "as3-example2" {
}
`

var TestAs3PerAppResource3 = `
resource "bigip_as3" "as3-example1" {
tenant_name = "dmz"
as3_json = "${file("` + dir + `/../examples/as3/as3_per_app_example3.json")}"
}
`

func TestAccBigipAs3_create_SingleTenant(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -463,7 +470,6 @@ func testCheckAS3AppExists(tenantName, appNames string, exists bool) resource.Te
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
client := &http.Client{Transport: tr}

for _, appName := range strings.Split(appNames, ",") {
url := clientBigip.Host + "/mgmt/shared/appsvcs/declare/" + tenantName + "/applications/" + appName
req, err := http.NewRequest("GET", url, nil)
Expand Down Expand Up @@ -561,6 +567,8 @@ func TestAccBigipPer_AppAs3_update_addApplication(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAs3Exists("dmz", true),
testCheckAS3AppExists("dmz", "path_app1", true),
testCheckAs3Exists("dmztest", false),
testCheckAS3AppExists("dmztest", "path_app1", false),
),
},
{
Expand All @@ -574,6 +582,35 @@ func TestAccBigipPer_AppAs3_update_addApplication(t *testing.T) {
})
}

func TestAccBigipPer_AppAs3_remove_Application(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckAs3Destroy,
Steps: []resource.TestStep{
{
Config: TestAs3PerAppResource3,

Check: resource.ComposeTestCheckFunc(
testCheckAs3Exists("dmz", true),
testCheckAS3AppExists("dmz", "path_app1", true),
testCheckAS3AppExists("dmz", "path_app2", true),
),
},
{
Config: TestAs3PerAppResource1,
Check: resource.ComposeTestCheckFunc(
testCheckAs3Exists("dmz", true),
testCheckAS3AppExists("dmz", "path_app1", true),
testCheckAS3AppExists("dmz", "path_app2", false),
),
},
},
})
}

// Per-App mode is disabled
func TestAccBigipPer_AppAs3_update_invalidJson(t *testing.T) {
resource.Test(t, resource.TestCase{
Expand Down
14 changes: 13 additions & 1 deletion docs/resources/bigip_as3.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,21 @@ resource "bigip_as3" "as3-example2" {
}

On running above 2 resources , we will be able to deploy Applications - `path_app1 , path_app2` on Tenant `Test`
now, if we run `terraform destroy -target=bigip_as3.as3-example2` , only `path_app2` will be deleted from Tenant.
now, if we run `terraform destroy -target=bigip_as3.as3-example2` , only `path_app2` will be deleted from Tenant.


resource "bigip_as3" "as3-example1" {
tenant_name = "dmz"
as3_json = "${file("` + dir + `/../examples/as3/as3_per_app_example1.json")}"
}

resource "bigip_as3" "as3-example1" {
tenant_name = "dmz"
as3_json = "${file("` + dir + `/../examples/as3/as3_per_app_example3.json")}"
}

On running above calls , first call will create 2 applications `path_app1 , path_app2` and second call , will remove `path_app2` from Tenant

[perApplication as3](#perApplication_example)

```hcl
Expand Down
47 changes: 47 additions & 0 deletions examples/as3/as3_per_app_example3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"schemaVersion": "3.50.0",
"path_app1": {
"class": "Application",
"vs_name_app1": {
"class": "Service_HTTP",
"virtualAddresses": [
"192.1.1.24"
],
"pool": "pool"
},
"pool": {
"class": "Pool",
"members": [
{
"servicePort": 80,
"serverAddresses": [
"192.20.1.10",
"192.30.1.20"
]
}
]
}
},
"path_app2": {
"class": "Application",
"vs_name_app2": {
"class": "Service_HTTP",
"virtualAddresses": [
"192.1.1.234"
],
"pool": "pool"
},
"pool": {
"class": "Pool",
"members": [
{
"servicePort": 80,
"serverAddresses": [
"12.20.1.10",
"12.30.1.20"
]
}
]
}
}
}

0 comments on commit c0aef75

Please sign in to comment.