Skip to content

Commit 3d7e7ab

Browse files
GilTeraSkyramya-bangera
authored andcommitted
[Feature complete]Custom IAM Role modles, client, schema, implmementation and docs
Signed-off-by: GilTS <gil@terasky.com>
1 parent 50bbbf8 commit 3d7e7ab

File tree

24 files changed

+1622
-3
lines changed

24 files changed

+1622
-3
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'v*'
77

88
env:
9-
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections custompolicytemplate'
9+
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections custompolicytemplate customiamrole'
1010

1111
jobs:
1212
goreleaser:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test and coverage
33
on: [pull_request, push]
44

55
env:
6-
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections custompolicytemplate'
6+
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections custompolicytemplate customiamrole'
77
jobs:
88
build:
99
name: Test and coverage

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ifeq ($(TEST_FLAGS),)
2222
endif
2323

2424
ifeq ($(BUILD_TAGS),)
25-
BUILD_TAGS := 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy helmfeature helmrelease backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections custompolicytemplate'
25+
BUILD_TAGS := 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy helmfeature helmrelease backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections custompolicytemplate customiamrole'
2626
endif
2727

2828
.PHONY: build clean-up test gofmt vet lint acc-test website-lint website-lint-fix

docs/resources/custom_iam_role.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
Title: "Custom IAM Role Resource"
3+
Description: |-
4+
Creating a custom IAM role.
5+
---
6+
7+
# Custom IAM Role Resource
8+
9+
This resource enables users to create custom IAM roles in TMC.
10+
11+
For more information regarding custom roles, see [Custom Role][custom-role].
12+
13+
[custom-role]: https://docs.vmware.com/en/VMware-Tanzu-Mission-Control/services/tanzumc-using/GUID-F314ED9E-2736-48CC-A1BB-CB9C32900B30.html
14+
15+
## Example Usage
16+
17+
```terraform
18+
resource "tanzu-mission-control_custom_iam_role" "demo-role" {
19+
name = "tf-custom-role"
20+
21+
spec {
22+
is_deprecated = false
23+
24+
aggregation_rule {
25+
cluster_role_selector {
26+
match_labels = {
27+
key = "value"
28+
}
29+
}
30+
31+
cluster_role_selector {
32+
match_expression {
33+
key = "aa"
34+
operator = "Exists"
35+
values = ["aa", "bb", "cc"]
36+
}
37+
}
38+
}
39+
40+
allowed_scopes = [
41+
"ORGANIZATION",
42+
"CLUSTER_GROUP",
43+
"CLUSTER"
44+
]
45+
46+
tanzu_permissions = []
47+
48+
kubernetes_permissions {
49+
rule {
50+
resources = ["deployments"]
51+
verbs = ["get", "list"]
52+
api_groups = ["*"]
53+
}
54+
55+
rule {
56+
verbs = ["get", "list"]
57+
api_groups = ["*"]
58+
url_paths = ["/healthz"]
59+
}
60+
}
61+
}
62+
}
63+
```
64+
65+
<!-- schema generated by tfplugindocs -->
66+
## Schema
67+
68+
### Required
69+
70+
- `name` (String) The name of the iam role
71+
- `spec` (Block List, Min: 1, Max: 1) Spec block of iam role (see [below for nested schema](#nestedblock--spec))
72+
73+
### Optional
74+
75+
- `meta` (Block List, Max: 1) Metadata for the resource (see [below for nested schema](#nestedblock--meta))
76+
77+
### Read-Only
78+
79+
- `id` (String) The ID of this resource.
80+
81+
<a id="nestedblock--spec"></a>
82+
### Nested Schema for `spec`
83+
84+
Required:
85+
86+
- `allowed_scopes` (List of String) The allowed scopes for the iam role.
87+
Valid values are (ORGANIZATION, MANAGEMENT_CLUSTER, PROVISIONER, CLUSTER_GROUP, CLUSTER, WORKSPACE, NAMESPACE)
88+
89+
Optional:
90+
91+
- `aggregation_rule` (Block List, Max: 1) Aggregation rules for the iam role. (see [below for nested schema](#nestedblock--spec--aggregation_rule))
92+
- `is_deprecated` (Boolean) Flag representing whether role is deprecated.
93+
- `kubernetes_permissions` (Block List, Max: 1) Kubernetes permissions for the iam role. (see [below for nested schema](#nestedblock--spec--kubernetes_permissions))
94+
- `tanzu_permissions` (List of String) Tanzu-specific permissions for the role.
95+
96+
<a id="nestedblock--spec--aggregation_rule"></a>
97+
### Nested Schema for `spec.aggregation_rule`
98+
99+
Required:
100+
101+
- `cluster_role_selector` (Block List, Min: 1) Cluster role selector for the iam role. (see [below for nested schema](#nestedblock--spec--aggregation_rule--cluster_role_selector))
102+
103+
<a id="nestedblock--spec--aggregation_rule--cluster_role_selector"></a>
104+
### Nested Schema for `spec.aggregation_rule.cluster_role_selector`
105+
106+
Optional:
107+
108+
- `match_expression` (Block List) List of label selector requirements.
109+
The requirements are ANDed. (see [below for nested schema](#nestedblock--spec--aggregation_rule--cluster_role_selector--match_expression))
110+
- `match_labels` (Map of String) Map of {key,value} pairs.
111+
A single {key,value} in the match_labels map is equivalent to an element of match_expression, whose key field is "key", the operator is "In", and the values array contains only "value".
112+
The requirements are ANDed.
113+
114+
<a id="nestedblock--spec--aggregation_rule--cluster_role_selector--match_expression"></a>
115+
### Nested Schema for `spec.aggregation_rule.cluster_role_selector.match_expression`
116+
117+
Required:
118+
119+
- `key` (String) Key is the label key that the selector applies to.
120+
- `operator` (String) Operator represents a key's relationship to a set of values.
121+
Valid operators are "In", "NotIn", "Exists" and "DoesNotExist".
122+
123+
Optional:
124+
125+
- `values` (List of String) Values is an array of string values.
126+
If the operator is "In" or "NotIn", the values array must be non-empty.
127+
If the operator is "Exists" or "DoesNotExist", the values array must be empty.
128+
This array is replaced during a strategic merge patch.
129+
130+
131+
132+
133+
<a id="nestedblock--spec--kubernetes_permissions"></a>
134+
### Nested Schema for `spec.kubernetes_permissions`
135+
136+
Required:
137+
138+
- `rule` (Block List, Min: 1) Kubernetes rules. (see [below for nested schema](#nestedblock--spec--kubernetes_permissions--rule))
139+
140+
<a id="nestedblock--spec--kubernetes_permissions--rule"></a>
141+
### Nested Schema for `spec.kubernetes_permissions.rule`
142+
143+
Required:
144+
145+
- `verbs` (List of String) Verbs.
146+
147+
Optional:
148+
149+
- `api_groups` (List of String) API groups.
150+
- `resource_names` (List of String) Restricts the rule to resources by name.
151+
- `resources` (List of String) Resources for the role.
152+
- `url_paths` (List of String) Non-resource urls for the role.
153+
154+
155+
156+
157+
<a id="nestedblock--meta"></a>
158+
### Nested Schema for `meta`
159+
160+
Optional:
161+
162+
- `annotations` (Map of String) Annotations for the resource
163+
- `description` (String) Description of the resource
164+
- `labels` (Map of String) Labels for the resource
165+
166+
Read-Only:
167+
168+
- `resource_version` (String) Resource version of the resource
169+
- `uid` (String) UID of the resource
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
resource "tanzu-mission-control_custom_iam_role" "demo-role" {
2+
name = "tf-custom-role"
3+
4+
spec {
5+
is_deprecated = false
6+
7+
aggregation_rule {
8+
cluster_role_selector {
9+
match_labels = {
10+
key = "value"
11+
}
12+
}
13+
14+
cluster_role_selector {
15+
match_expression {
16+
key = "aa"
17+
operator = "Exists"
18+
values = ["aa", "bb", "cc"]
19+
}
20+
}
21+
}
22+
23+
allowed_scopes = [
24+
"ORGANIZATION",
25+
"CLUSTER_GROUP",
26+
"CLUSTER"
27+
]
28+
29+
tanzu_permissions = []
30+
31+
kubernetes_permissions {
32+
rule {
33+
resources = ["deployments"]
34+
verbs = ["get", "list"]
35+
api_groups = ["*"]
36+
}
37+
38+
rule {
39+
verbs = ["get", "list"]
40+
api_groups = ["*"]
41+
url_paths = ["/healthz"]
42+
}
43+
}
44+
}
45+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package customiamrole
7+
8+
import (
9+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
10+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
11+
customiamrolemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/customiamrole"
12+
)
13+
14+
const (
15+
iamRoleAPIVersionAndGroup = "v1alpha1/iam/roles"
16+
)
17+
18+
// New creates a new custom iam role resource service API client.
19+
func New(transport *transport.Client) ClientService {
20+
return &Client{Client: transport}
21+
}
22+
23+
/*
24+
Client for custom iam role resource service API.
25+
*/
26+
type Client struct {
27+
*transport.Client
28+
}
29+
30+
// ClientService is the interface for Client methods.
31+
type ClientService interface {
32+
CustomIAMRoleResourceServiceCreate(request *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData) (*customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData, error)
33+
34+
CustomIAMRoleResourceServiceUpdate(request *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData) (*customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData, error)
35+
36+
CustomIAMRoleResourceServiceDelete(fn *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleFullName) error
37+
38+
CustomIAMRoleResourceServiceGet(fn *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleFullName) (*customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData, error)
39+
}
40+
41+
/*
42+
CustomIAMRoleResourceServiceGet gets a custom iam role.
43+
*/
44+
func (c *Client) CustomIAMRoleResourceServiceGet(fullName *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleFullName) (*customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData, error) {
45+
requestURL := helper.ConstructRequestURL(iamRoleAPIVersionAndGroup, fullName.Name).String()
46+
resp := &customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData{}
47+
err := c.Get(requestURL, resp)
48+
49+
return resp, err
50+
}
51+
52+
/*
53+
CustomIAMRoleResourceServiceCreate creates a custom iam role.
54+
*/
55+
func (c *Client) CustomIAMRoleResourceServiceCreate(request *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData) (*customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData, error) {
56+
response := &customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData{}
57+
requestURL := helper.ConstructRequestURL(iamRoleAPIVersionAndGroup).String()
58+
err := c.Create(requestURL, request, response)
59+
60+
return response, err
61+
}
62+
63+
/*
64+
CustomIAMRoleResourceServiceUpdate updates a custom iam role.
65+
*/
66+
func (c *Client) CustomIAMRoleResourceServiceUpdate(request *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData) (*customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData, error) {
67+
response := &customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleData{}
68+
requestURL := helper.ConstructRequestURL(iamRoleAPIVersionAndGroup, request.Role.FullName.Name).String()
69+
err := c.Update(requestURL, request, response)
70+
71+
return response, err
72+
}
73+
74+
/*
75+
CustomIAMRoleResourceServiceDelete deletes a custom iam role.
76+
*/
77+
func (c *Client) CustomIAMRoleResourceServiceDelete(fullName *customiamrolemodels.VmwareTanzuManageV1alpha1IamRoleFullName) error {
78+
requestURL := helper.ConstructRequestURL(iamRoleAPIVersionAndGroup, fullName.Name).String()
79+
80+
return c.Delete(requestURL)
81+
}

internal/client/http_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
sourcesecretclustergroupclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/clustergroup/sourcesecret"
4040
credentialclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/credential"
4141
custompolicytemplateclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/custompolicytemplate"
42+
customiamroleclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/customiamrole"
4243
eksclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/ekscluster"
4344
eksnodepoolclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/ekscluster/nodepool"
4445
inspectionsclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/inspections"
@@ -150,6 +151,7 @@ func newHTTPClient(httpClient *transport.Client) *TanzuMissionControl {
150151
ProvisionerResourceService: provisionerclient.New(httpClient),
151152
CustomPolicyTemplateResourceService: custompolicytemplateclient.New(httpClient),
152153
RecipeResourceService: recipeclient.New(httpClient),
154+
CustomIAMRoleResourceService: customiamroleclient.New(httpClient),
153155
}
154156
}
155157

@@ -211,4 +213,5 @@ type TanzuMissionControl struct {
211213
InspectionsResourceService inspectionsclient.ClientService
212214
CustomPolicyTemplateResourceService custompolicytemplateclient.ClientService
213215
RecipeResourceService recipeclient.ClientService
216+
CustomIAMRoleResourceService customiamroleclient.ClientService
214217
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package customiamrolemodels
7+
8+
import (
9+
"github.com/go-openapi/swag"
10+
)
11+
12+
// VmwareTanzuManageV1alpha1IamRoleAggregationRule AggregationRule for a role.
13+
//
14+
// swagger:model vmware.tanzu.manage.v1alpha1.iam.role.AggregationRule
15+
type VmwareTanzuManageV1alpha1IamRoleAggregationRule struct {
16+
17+
// Label based Cluster Role Selector.
18+
ClusterRoleSelectors []*K8sIoApimachineryPkgApisMetaV1LabelSelector `json:"clusterRoleSelectors"`
19+
}
20+
21+
// MarshalBinary interface implementation.
22+
func (m *VmwareTanzuManageV1alpha1IamRoleAggregationRule) MarshalBinary() ([]byte, error) {
23+
if m == nil {
24+
return nil, nil
25+
}
26+
27+
return swag.WriteJSON(m)
28+
}
29+
30+
// UnmarshalBinary interface implementation.
31+
func (m *VmwareTanzuManageV1alpha1IamRoleAggregationRule) UnmarshalBinary(b []byte) error {
32+
var res VmwareTanzuManageV1alpha1IamRoleAggregationRule
33+
34+
if err := swag.ReadJSON(b, &res); err != nil {
35+
return err
36+
}
37+
38+
*m = res
39+
40+
return nil
41+
}

0 commit comments

Comments
 (0)