Skip to content

Commit

Permalink
PLT-723: Fixed RBAC day 2 operation
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Oct 6, 2023
1 parent 161ef0f commit 14da38d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spectrocloud/cluster_common_rbac.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spectrocloud

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/spectrocloud/hapi/models"
Expand Down Expand Up @@ -134,7 +135,10 @@ func flattenClusterRBAC(items []*models.V1ClusterRbac) []interface{} {
}

func updateClusterRBAC(c *client.V1Client, d *schema.ResourceData) error {
ClusterContext := d.Get("cluster").(string)
ClusterContext := d.Get("context").(string)
if ClusterContext != "project" && ClusterContext != "tenant" {
return fmt.Errorf("invalid Context set - %s", ClusterContext)
}
if rbacs := toClusterRBACsInputEntities(d); rbacs != nil {
return c.ApplyClusterRbacConfig(d.Id(), rbacs, ClusterContext)
}
Expand Down
11 changes: 11 additions & 0 deletions spectrocloud/cluster_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,14 @@ func TestFlattenAdditionalLabelsAndTaints(t *testing.T) {
})
}
}

func TestUpdateClusterRBAC(t *testing.T) {
d := resourceClusterVsphere().TestResourceData()

// Case 1: rbacs context is invalid
d.Set("context", "invalid")
err := updateClusterRBAC(nil, d)
if err == nil || err.Error() != "invalid Context set - invalid" {
t.Errorf("Expected 'invalid Context set - invalid', got %v", err)
}
}

0 comments on commit 14da38d

Please sign in to comment.