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..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, "") + resourceContext := "" // Warning or errors can be collected in a slice type var diags diag.Diagnostics @@ -110,12 +110,15 @@ 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) + } else { return diag.FromErr(val_error) } - + c := getV1ClientWithResourceContext(m, resourceContext) if cluster_uid == "" { if config["cluster_group_uid"] == "" { return diag.FromErr(val_error) @@ -183,8 +186,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())