Skip to content

Commit

Permalink
Merge pull request #946 from F5Networks/as3_perapp_10012024
Browse files Browse the repository at this point in the history
As3 perapp 10012024
  • Loading branch information
RavinderReddyF5 authored Mar 26, 2024
2 parents d9ba3ae + d3419c6 commit 1dcc25b
Showing 1 changed file with 26 additions and 11 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

0 comments on commit 1dcc25b

Please sign in to comment.