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

As3 perapp 10012024 #946

Merged
merged 2 commits into from
Mar 26, 2024
Merged
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
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