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

Add admin_groups field to the containerattached resource. #16307

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
3 changes: 3 additions & 0 deletions .changelog/9300.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
containerattached: added `admin_groups` field to `google_container_attached_cluster` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ Please refer to the field 'effective_annotations' for all of the annotations pre
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"admin_groups": {
Type: schema.TypeList,
Optional: true,
Description: `Groups that can perform operations as a cluster admin. A managed
ClusterRoleBinding will be created to grant the 'cluster-admin' ClusterRole
to the groups. Up to ten admin groups can be provided.

For more info on RBAC, see
https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"admin_users": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -743,9 +756,12 @@ func resourceContainerAttachedClusterUpdate(d *schema.ResourceData, meta interfa
}
// The generated code sets the wrong masks for the following fields.
newUpdateMask := []string{}
if d.HasChange("authorization") {
if d.HasChange("authorization.0.admin_users") {
newUpdateMask = append(newUpdateMask, "authorization.admin_users")
}
if d.HasChange("authorization.0.admin_groups") {
newUpdateMask = append(newUpdateMask, "authorization.admin_groups")
}
if d.HasChange("logging_config") {
newUpdateMask = append(newUpdateMask, "logging_config.component_config.enable_components")
}
Expand Down Expand Up @@ -1079,6 +1095,10 @@ func flattenContainerAttachedClusterErrorsMessage(v interface{}, d *schema.Resou
// { username = "user1" },
// { username = "user2" }
// ]
// admin_groups [
// { group = "group1" },
// { group = "group2" },
// ]
// }
//
// The custom flattener transforms input back into something like this:
Expand All @@ -1088,6 +1108,10 @@ func flattenContainerAttachedClusterErrorsMessage(v interface{}, d *schema.Resou
// "user1",
// "user2"
// ]
// admin_groups = [
// "group1",
// "group2"
// ],
// }
func flattenContainerAttachedClusterAuthorization(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
Expand All @@ -1102,6 +1126,13 @@ func flattenContainerAttachedClusterAuthorization(v interface{}, d *schema.Resou
transformed["admin_users"][i] = u.(map[string]interface{})["username"].(string)
}
}
orig = v.(map[string]interface{})["adminGroups"].([]interface{})
transformed["admin_groups"] = make([]string, len(orig))
for i, u := range orig {
if u != nil {
transformed["admin_groups"][i] = u.(map[string]interface{})["group"].(string)
}
}

return []interface{}{transformed}
}
Expand Down Expand Up @@ -1284,13 +1315,21 @@ type attachedClusterUser struct {
Username string `json:"username"`
}

type attachedClusterGroup struct {
Group string `json:"group"`
}

// The custom expander transforms input into something like this:
//
// authorization {
// admin_users [
// { username = "user1" },
// { username = "user2" }
// ]
// admin_groups [
// { group = "group1" },
// { group = "group2" },
// ]
// }
//
// The custom flattener transforms input back into something like this:
Expand All @@ -1300,6 +1339,10 @@ type attachedClusterUser struct {
// "user1",
// "user2"
// ]
// admin_groups = [
// "group1",
// "group2"
// ],
// }
func expandContainerAttachedClusterAuthorization(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
Expand All @@ -1315,6 +1358,13 @@ func expandContainerAttachedClusterAuthorization(v interface{}, d tpgresource.Te
transformed["admin_users"][i] = attachedClusterUser{Username: u.(string)}
}
}
orig = raw.(map[string]interface{})["admin_groups"].([]interface{})
transformed["admin_groups"] = make([]interface{}, len(orig))
for i, u := range orig {
if u != nil {
transformed["admin_groups"][i] = attachedClusterGroup{Group: u.(string)}
}
}
return transformed, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ resource "google_container_attached_cluster" "primary" {
}
authorization {
admin_users = [ "user1@example.com", "user2@example.com"]
admin_groups = [ "group1@example.com", "group2@example.com"]
}
oidc_config {
issuer_url = "https://oidc.issuer.url"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ resource "google_container_attached_cluster" "primary" {
}
authorization {
admin_users = [ "user1@example.com", "user2@example.com"]
admin_groups = [ "group1@example.com", "group2@example.com"]
}
oidc_config {
issuer_url = "https://oidc.issuer.url"
Expand Down Expand Up @@ -121,6 +122,7 @@ resource "google_container_attached_cluster" "primary" {
}
authorization {
admin_users = [ "user2@example.com", "user3@example.com"]
admin_groups = [ "group3@example.com"]
}
oidc_config {
issuer_url = "https://oidc.issuer.url"
Expand Down Expand Up @@ -167,6 +169,7 @@ resource "google_container_attached_cluster" "primary" {
}
authorization {
admin_users = [ "user2@example.com", "user3@example.com"]
admin_groups = [ "group3@example.com"]
}
oidc_config {
issuer_url = "https://oidc.issuer.url"
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/container_attached_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ resource "google_container_attached_cluster" "primary" {
}
authorization {
admin_users = [ "user1@example.com", "user2@example.com"]
admin_groups = [ "group1@example.com", "group2@example.com"]
}
oidc_config {
issuer_url = "https://oidc.issuer.url"
Expand Down Expand Up @@ -281,6 +282,14 @@ The following arguments are supported:
For more info on RBAC, see
https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles

* `admin_groups` -
(Optional)
Groups that can perform operations as a cluster admin. A managed
ClusterRoleBinding will be created to grant the `cluster-admin` ClusterRole
to the groups. Up to ten admin groups can be provided.
For more info on RBAC, see
https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles

<a name="nested_monitoring_config"></a>The `monitoring_config` block supports:

* `managed_prometheus_config` -
Expand Down