Skip to content

Support map users and roles to multiple groups #424

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

Merged
merged 8 commits into from
Aug 19, 2019
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: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

## Next release

## [[v5.?.?](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v5.1.0...HEAD)] - 2019-08-??]
## [[v6.?.?](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v5.1.0...HEAD)] - 2019-08-??]

### Added

Expand All @@ -19,6 +19,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Support map users and roles to multiple groups (by @nauxliu)
- Fixed errors sometimes happening during destroy due to usage of coalesce() in local.tf (by @petrikero)
- Write your awesome change here (by @you)

Expand Down
44 changes: 3 additions & 41 deletions aws_auth.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,8 @@ data "template_file" "config_map_aws_auth" {
),
),
)
map_users = join("", data.template_file.map_users.*.rendered)
map_roles = join("", data.template_file.map_roles.*.rendered)
map_accounts = join("", data.template_file.map_accounts.*.rendered)
map_users = yamlencode(var.map_users),
map_roles = yamlencode(var.map_roles),
map_accounts = yamlencode(var.map_accounts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice

}
}

data "template_file" "map_users" {
count = length(var.map_users)
template = file(
"${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl",
)

vars = {
user_arn = var.map_users[count.index]["user_arn"]
username = var.map_users[count.index]["username"]
group = var.map_users[count.index]["group"]
}
}

data "template_file" "map_roles" {
count = length(var.map_roles)
template = file(
"${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl",
)

vars = {
role_arn = var.map_roles[count.index]["role_arn"]
username = var.map_roles[count.index]["username"]
group = var.map_roles[count.index]["group"]
}
}

data "template_file" "map_accounts" {
count = length(var.map_accounts)
template = file(
"${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl",
)

vars = {
account_number = var.map_accounts[count.index]
}
}

24 changes: 16 additions & 8 deletions examples/basic/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,39 @@ variable "map_accounts" {

variable "map_roles" {
description = "Additional IAM roles to add to the aws-auth configmap."
type = list(map(string))
type = list(object({
rolearn = string
username = string
groups = list(string)
}))

default = [
{
role_arn = "arn:aws:iam::66666666666:role/role1"
rolearn = "arn:aws:iam::66666666666:role/role1"
username = "role1"
group = "system:masters"
groups = ["system:masters"]
},
]
}

variable "map_users" {
description = "Additional IAM users to add to the aws-auth configmap."
type = list(map(string))
type = list(object({
userarn = string
username = string
groups = list(string)
}))

default = [
{
user_arn = "arn:aws:iam::66666666666:user/user1"
userarn = "arn:aws:iam::66666666666:user/user1"
username = "user1"
group = "system:masters"
groups = ["system:masters"]
},
{
user_arn = "arn:aws:iam::66666666666:user/user2"
userarn = "arn:aws:iam::66666666666:user/user2"
username = "user2"
group = "system:masters"
groups = ["system:masters"]
},
]
}
1 change: 0 additions & 1 deletion templates/config-map-aws-auth-map_accounts.yaml.tpl

This file was deleted.

4 changes: 0 additions & 4 deletions templates/config-map-aws-auth-map_roles.yaml.tpl

This file was deleted.

4 changes: 0 additions & 4 deletions templates/config-map-aws-auth-map_users.yaml.tpl

This file was deleted.

12 changes: 9 additions & 3 deletions templates/config-map-aws-auth.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ metadata:
data:
mapRoles: |
${worker_role_arn}
${map_roles}
%{if chomp(map_roles) != "[]" }
${indent(4, map_roles)}
%{ endif }
%{if chomp(map_users) != "[]" }
mapUsers: |
${map_users}
${indent(4, map_users)}
%{ endif }
%{if chomp(map_accounts) != "[]" }
mapAccounts: |
${map_accounts}
${indent(4, map_accounts)}
%{ endif }
16 changes: 12 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,22 @@ variable "map_accounts" {

variable "map_roles" {
description = "Additional IAM roles to add to the aws-auth configmap. See examples/basic/variables.tf for example format."
type = list(map(string))
default = []
type = list(object({
rolearn = string
username = string
groups = list(string)
}))
default = []
}

variable "map_users" {
description = "Additional IAM users to add to the aws-auth configmap. See examples/basic/variables.tf for example format."
type = list(map(string))
default = []
type = list(object({
userarn = string
username = string
groups = list(string)
}))
default = []
}

variable "subnets" {
Expand Down