From 14da38d5848c788c27d101bae5a6ec5aa57a0683 Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Fri, 6 Oct 2023 23:46:26 +0530 Subject: [PATCH] PLT-723: Fixed RBAC day 2 operation --- spectrocloud/cluster_common_rbac.go | 6 +++++- spectrocloud/cluster_common_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/spectrocloud/cluster_common_rbac.go b/spectrocloud/cluster_common_rbac.go index 3c46aa44..dabdb610 100644 --- a/spectrocloud/cluster_common_rbac.go +++ b/spectrocloud/cluster_common_rbac.go @@ -1,6 +1,7 @@ package spectrocloud import ( + "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/spectrocloud/hapi/models" @@ -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) } diff --git a/spectrocloud/cluster_common_test.go b/spectrocloud/cluster_common_test.go index cc2936f1..79acc442 100644 --- a/spectrocloud/cluster_common_test.go +++ b/spectrocloud/cluster_common_test.go @@ -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) + } +}