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

PLT-1413: Fixed context issues in tenant resources #519

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
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
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
Loading