Skip to content

Commit

Permalink
PLT-1413: Fixed context issues in tenant resources (#519)
Browse files Browse the repository at this point in the history
* PLT-1413: Fixed context issues in reosure teams & application

* reviewble fix
  • Loading branch information
SivaanandM authored Oct 3, 2024
1 parent d1ed643 commit 2942dc9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion spectrocloud/application_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions spectrocloud/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spectrocloud/resource_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 2942dc9

Please sign in to comment.