Skip to content

Commit ee2cccf

Browse files
adding validation for tmc-block-rolebinding-subjects recipe schema
Signed-off-by: Vasundhara Shukla <vasundharas@vmware.com>
1 parent e1c5110 commit ee2cccf

7 files changed

+16
-14
lines changed

docs/resources/custom_policy.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ resource "tanzu-mission-control_custom_policy" "cluster_scoped_tmc-block-rolebin
172172
audit = false
173173
parameters {
174174
disallowed_subjects {
175-
kind = "node"
175+
kind = "Group"
176176
name = "subject-1"
177177
}
178178
}
@@ -513,7 +513,7 @@ resource "tanzu-mission-control_custom_policy" "cluster_group_scoped_tmc-block-r
513513
audit = false
514514
parameters {
515515
disallowed_subjects {
516-
kind = "node"
516+
kind = "User"
517517
name = "subject-1"
518518
}
519519
}
@@ -848,7 +848,7 @@ resource "tanzu-mission-control_custom_policy" "organization_scoped_tmc-block-ro
848848
audit = false
849849
parameters {
850850
disallowed_subjects {
851-
kind = "node"
851+
kind = "ServiceAccount"
852852
name = "subject-1"
853853
}
854854
}

examples/resources/custom_policy/resource_cluster_group_tmc_block_rolebinding_subjects_custom_policy.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "tanzu-mission-control_custom_policy" "cluster_group_scoped_tmc-block-r
1818
audit = false
1919
parameters {
2020
disallowed_subjects {
21-
kind = "node"
21+
kind = "User"
2222
name = "subject-1"
2323
}
2424
}

examples/resources/custom_policy/resource_cluster_tmc_block_rolebinding_subjects_custom_policy.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "tanzu-mission-control_custom_policy" "cluster_scoped_tmc-block-rolebin
2020
audit = false
2121
parameters {
2222
disallowed_subjects {
23-
kind = "node"
23+
kind = "Group"
2424
name = "subject-1"
2525
}
2626
}

examples/resources/custom_policy/resource_organization_tmc_block_rolebinding_subjects_custom_policy.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "tanzu-mission-control_custom_policy" "organization_scoped_tmc-block-ro
1818
audit = false
1919
parameters {
2020
disallowed_subjects {
21-
kind = "node"
21+
kind = "ServiceAccount"
2222
name = "subject-1"
2323
}
2424
}

internal/resources/policy/kind/custom/recipe/tmc_block_rolebinding_subjects_flatten_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestFlattenTMCBlockRolebindingSubjects(t *testing.T) {
3535
Parameters: &policyrecipecustommodel.VmwareTanzuManageV1alpha1CommonPolicySpecCustomV1TMCBlockRoleBindingSubjectsParameters{
3636
DisallowedSubjects: []*policyrecipecustommodel.VmwareTanzuManageV1alpha1CommonPolicySpecCustomV1TMCBlockRoleBindingSubjectsParametersDisallowedSubjects{
3737
{
38-
Kind: "nodes",
38+
Kind: "User",
3939
Name: "test",
4040
},
4141
},
@@ -54,7 +54,7 @@ func TestFlattenTMCBlockRolebindingSubjects(t *testing.T) {
5454
map[string]interface{}{
5555
disallowedSubjectsKey: []interface{}{
5656
map[string]interface{}{
57-
kindKey: "nodes",
57+
kindKey: "User",
5858
nameKey: "test",
5959
},
6060
},

internal/resources/policy/kind/custom/recipe/tmc_block_rolebinding_subjects_schema.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package recipe
99

1010
import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1213

1314
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
1415
policyrecipecustommodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/policy/recipe/custom"
@@ -43,9 +44,10 @@ var TMCBlockRolebindingSubjects = &schema.Schema{
4344
Elem: &schema.Resource{
4445
Schema: map[string]*schema.Schema{
4546
kindKey: {
46-
Type: schema.TypeString,
47-
Description: "The kind of subject to disallow, can be User/Group/ServiceAccount.",
48-
Required: true,
47+
Type: schema.TypeString,
48+
Description: "The kind of subject to disallow, can be User/Group/ServiceAccount.",
49+
Required: true,
50+
ValidateFunc: validation.StringInSlice([]string{"User", "Group", "ServiceAccount"}, false),
4951
},
5052
nameKey: {
5153
Type: schema.TypeString,
@@ -136,11 +138,11 @@ func expandDisallowedSubjects(data interface{}) (disallowedSubjects *policyrecip
136138

137139
disallowedSubjects = &policyrecipecustommodel.VmwareTanzuManageV1alpha1CommonPolicySpecCustomV1TMCBlockRoleBindingSubjectsParametersDisallowedSubjects{}
138140

139-
if v, ok := disallowedSubjectsData[labelKey]; ok {
141+
if v, ok := disallowedSubjectsData[kindKey]; ok {
140142
helper.SetPrimitiveValue(v, &disallowedSubjects.Kind, kindKey)
141143
}
142144

143-
if v, ok := disallowedSubjectsData[labelValueKey]; ok {
145+
if v, ok := disallowedSubjectsData[nameKey]; ok {
144146
helper.SetPrimitiveValue(v, &disallowedSubjects.Name, nameKey)
145147
}
146148

internal/resources/policy/kind/custom/resource/resource_custom_policy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (testConfig *testAcceptanceConfig) getTestCustomPolicyResourceInput(recipe
375375
audit = false
376376
parameters {
377377
disallowed_subjects {
378-
kind = "node"
378+
kind = "User"
379379
name = "subject-1"
380380
}
381381
}

0 commit comments

Comments
 (0)