From e49cbfea26b98f18947066f74ef34340a6ece50c Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Mon, 30 Sep 2024 16:19:06 +0530 Subject: [PATCH 1/2] PLT-1413: Fixed context issues in reosure teams & application --- spectrocloud/application_common.go | 7 ++++++- spectrocloud/resource_application.go | 14 ++++++++++++-- spectrocloud/resource_team.go | 8 ++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/spectrocloud/application_common.go b/spectrocloud/application_common.go index bbb62bf4..e01246fa 100644 --- a/spectrocloud/application_common.go +++ b/spectrocloud/application_common.go @@ -90,8 +90,13 @@ func resourceApplicationStateRefreshFunc(c *client.V1Client, d *schema.ResourceD func resourceApplicationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + configList := d.Get("config") c := getV1ClientWithResourceContext(m, "") - + if configList.([]interface{})[0] != nil { + config := configList.([]interface{})[0].(map[string]interface{}) + resourceContext := config["cluster_context"].(string) + c = getV1ClientWithResourceContext(m, resourceContext) + } var diags diag.Diagnostics err := c.DeleteApplication(d.Id()) if err != nil { diff --git a/spectrocloud/resource_application.go b/spectrocloud/resource_application.go index f03abe7f..182efa7b 100644 --- a/spectrocloud/resource_application.go +++ b/spectrocloud/resource_application.go @@ -92,7 +92,7 @@ func resourceApplication() *schema.Resource { } func resourceApplicationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + c := getV1ClientWithResourceContext(m, "tenant") // Warning or errors can be collected in a slice type var diags diag.Diagnostics @@ -110,8 +110,12 @@ func resourceApplicationCreate(ctx context.Context, d *schema.ResourceData, m in var cluster_uid interface{} configList := d.Get("config") if configList.([]interface{})[0] != nil { + config = configList.([]interface{})[0].(map[string]interface{}) cluster_uid = config["cluster_uid"] + resourceContext := config["cluster_context"].(string) + c = getV1ClientWithResourceContext(m, resourceContext) + } else { return diag.FromErr(val_error) } @@ -183,8 +187,14 @@ func resourceApplicationUpdate(ctx context.Context, d *schema.ResourceData, m in // Warning or errors can be collected in a slice type var diags diag.Diagnostics - if d.HasChanges("cluster_uid", "cluster_profile") { + if d.HasChanges("config.0.cluster_uid", "config.0.cluster_profile") { + configList := d.Get("config") c := getV1ClientWithResourceContext(m, "") + if configList.([]interface{})[0] != nil { + config := configList.([]interface{})[0].(map[string]interface{}) + resourceContext := config["cluster_context"].(string) + c = getV1ClientWithResourceContext(m, resourceContext) + } clusterUid := d.Get("cluster_uid").(string) cluster, err := c.GetCluster(clusterUid) diff --git a/spectrocloud/resource_team.go b/spectrocloud/resource_team.go index e17ab940..01de96df 100644 --- a/spectrocloud/resource_team.go +++ b/spectrocloud/resource_team.go @@ -123,7 +123,7 @@ func resourceTeam() *schema.Resource { func resourceTeamCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics uid, err := c.CreateTeam(toTeam(d)) @@ -157,7 +157,7 @@ func resourceTeamCreate(ctx context.Context, d *schema.ResourceData, m interface func resourceTeamRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics team, err := c.GetTeam(d.Id()) @@ -268,7 +268,7 @@ func setWorkspaceRoles(c *client.V1Client, d *schema.ResourceData) error { func resourceTeamUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics err := c.UpdateTeam(d.Id(), toTeam(d)) @@ -298,7 +298,7 @@ func resourceTeamUpdate(ctx context.Context, d *schema.ResourceData, m interface } func resourceTeamDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "") + c := getV1ClientWithResourceContext(m, "tenant") var diags diag.Diagnostics err := c.DeleteTeam(d.Id()) From b834d60c5755a76c0add594895ca6d71886d520a Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Mon, 30 Sep 2024 16:40:36 +0530 Subject: [PATCH 2/2] reviewble fix --- spectrocloud/resource_application.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spectrocloud/resource_application.go b/spectrocloud/resource_application.go index 182efa7b..b3cb3069 100644 --- a/spectrocloud/resource_application.go +++ b/spectrocloud/resource_application.go @@ -92,7 +92,7 @@ func resourceApplication() *schema.Resource { } func resourceApplicationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - c := getV1ClientWithResourceContext(m, "tenant") + resourceContext := "" // Warning or errors can be collected in a slice type var diags diag.Diagnostics @@ -113,13 +113,12 @@ func resourceApplicationCreate(ctx context.Context, d *schema.ResourceData, m in config = configList.([]interface{})[0].(map[string]interface{}) cluster_uid = config["cluster_uid"] - resourceContext := config["cluster_context"].(string) - c = getV1ClientWithResourceContext(m, resourceContext) + resourceContext = config["cluster_context"].(string) } else { return diag.FromErr(val_error) } - + c := getV1ClientWithResourceContext(m, resourceContext) if cluster_uid == "" { if config["cluster_group_uid"] == "" { return diag.FromErr(val_error)