diff --git a/bigip/resource_bigip_as3.go b/bigip/resource_bigip_as3.go index a26802398..d08dcdd8b 100644 --- a/bigip/resource_bigip_as3.go +++ b/bigip/resource_bigip_as3.go @@ -292,7 +292,17 @@ func resourceBigipAs3Read(ctx context.Context, d *schema.ResourceData, meta inte log.Printf("[DEBUG] Tenants in AS3 get call : %s", name) log.Printf("[DEBUG] Applications in AS3 get call : %s", applicationList) if name != "" { - as3Resp, err := client.GetAs3(name, applicationList) + as3Resp, err := client.GetAs3(name, applicationList, d.Get("per_app_mode").(bool)) + if d.Get("per_app_mode").(bool) { + as3Json := make(map[string]interface{}) + _ = json.Unmarshal([]byte(as3Resp), &as3Json) + out, _ := json.Marshal(as3Json) + as3Dec := string(out) + applicationList = client.GetAppsList(fmt.Sprintf("%v", as3Dec)) + log.Printf("[DEBUG] Application List from retreived the GET call in Read function : %s", applicationList) + _ = d.Set("application_list", applicationList) + } + log.Printf("[DEBUG] AS3 json retreived from the GET call in Read function : %s", as3Resp) if err != nil { log.Printf("[ERROR] Unable to retrieve json ") @@ -329,8 +339,8 @@ 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) - tenantList, _, _ := client.GetTenantList(as3Json) - + tenantList, _, applicationList := client.GetTenantList(as3Json) + _ = d.Set("application_list", applicationList) perApplication, err := client.CheckSetting() if err != nil { return diag.FromErr(err) @@ -340,13 +350,14 @@ func resourceBigipAs3Update(ctx context.Context, d *schema.ResourceData, meta in if perApplication && len(tenantList) == 0 { oldTenantList := d.Get("tenant_list").(string) log.Printf("[INFO] Updating As3 Config for tenant:%s with Per-Application Mode:%v", oldTenantList, perApplication) - err, res := client.PostPerAppBigIp(as3Json, oldTenantList) - log.Printf("[DEBUG] res from PostPerAppBigIp:%+v", res) + err, task_id := client.PostPerAppBigIp(as3Json, oldTenantList) + log.Printf("[DEBUG] task_id from PostPerAppBigIp:%+v", task_id) if err != nil { return diag.FromErr(fmt.Errorf("posting as3 config failed for tenant:(%s) with error: %v", oldTenantList, err)) } // tenantCount = append(tenantCount, tenant) _ = d.Set("tenant_list", oldTenantList) + _ = d.Set("task_id", task_id) } else { if !perApplication { return diag.FromErr(fmt.Errorf("Per-Application should be true in Big-IP Setting")) diff --git a/vendor/github.com/f5devcentral/go-bigip/as3bigip.go b/vendor/github.com/f5devcentral/go-bigip/as3bigip.go index 9b5d9c581..8f803ea5e 100644 --- a/vendor/github.com/f5devcentral/go-bigip/as3bigip.go +++ b/vendor/github.com/f5devcentral/go-bigip/as3bigip.go @@ -288,13 +288,22 @@ func (b *BigIP) ModifyAs3(tenantFilter string, as3_json string) error { return nil } -func (b *BigIP) GetAs3(name, appList string) (string, error) { +func (b *BigIP) GetAs3(name, appList string, perAppMode bool) (string, error) { as3Json := make(map[string]interface{}) - as3Json["class"] = "AS3" - as3Json["action"] = "deploy" - as3Json["persist"] = true adcJson := make(map[string]interface{}) - err, ok := b.getForEntity(&adcJson, uriMgmt, uriShared, uriAppsvcs, uriDeclare, name) + var err error + var ok bool + + log.Printf("[DEBUG] (GetAs3) Per App Mode :%+v", perAppMode) + + if perAppMode { + err, ok = b.getForEntity(&adcJson, uriMgmt, uriShared, uriAppsvcs, uriDeclare, name, uriApplications) + } else { + as3Json["class"] = "AS3" + as3Json["action"] = "deploy" + as3Json["persist"] = true + err, ok = b.getForEntity(&adcJson, uriMgmt, uriShared, uriAppsvcs, uriDeclare, name) + } if err != nil { return "", err } @@ -303,7 +312,12 @@ func (b *BigIP) GetAs3(name, appList string) (string, error) { } delete(adcJson, "updateMode") delete(adcJson, "controls") - as3Json["declaration"] = adcJson + + if perAppMode { + as3Json = adcJson + } else { + as3Json["declaration"] = adcJson + } out, _ := json.Marshal(as3Json) as3String := string(out) tenantList := strings.Split(appList, ",")