Skip to content

Commit 8580b67

Browse files
nauxliumax-rocket-internet
authored andcommitted
Support map users and roles to multiple groups (#424)
* Support map users and roles to multiple groups * Simplify code by rename `user_arn` to `userarn`, `role_arn` to `rolearn` * Next version should be 6.x because PR this is a breaking change. * Update example variables.tf * Change indent to 2 * Fix map-aws-auth.yaml maybe invalid yaml.
1 parent b8b3b58 commit 8580b67

8 files changed

+42
-66
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Next release
99

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

1212
### Added
1313

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

2020
### Changed
2121

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

aws_auth.tf

+3-41
Original file line numberDiff line numberDiff line change
@@ -95,46 +95,8 @@ data "template_file" "config_map_aws_auth" {
9595
),
9696
),
9797
)
98-
map_users = join("", data.template_file.map_users.*.rendered)
99-
map_roles = join("", data.template_file.map_roles.*.rendered)
100-
map_accounts = join("", data.template_file.map_accounts.*.rendered)
98+
map_users = yamlencode(var.map_users),
99+
map_roles = yamlencode(var.map_roles),
100+
map_accounts = yamlencode(var.map_accounts)
101101
}
102102
}
103-
104-
data "template_file" "map_users" {
105-
count = length(var.map_users)
106-
template = file(
107-
"${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl",
108-
)
109-
110-
vars = {
111-
user_arn = var.map_users[count.index]["user_arn"]
112-
username = var.map_users[count.index]["username"]
113-
group = var.map_users[count.index]["group"]
114-
}
115-
}
116-
117-
data "template_file" "map_roles" {
118-
count = length(var.map_roles)
119-
template = file(
120-
"${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl",
121-
)
122-
123-
vars = {
124-
role_arn = var.map_roles[count.index]["role_arn"]
125-
username = var.map_roles[count.index]["username"]
126-
group = var.map_roles[count.index]["group"]
127-
}
128-
}
129-
130-
data "template_file" "map_accounts" {
131-
count = length(var.map_accounts)
132-
template = file(
133-
"${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl",
134-
)
135-
136-
vars = {
137-
account_number = var.map_accounts[count.index]
138-
}
139-
}
140-

examples/basic/variables.tf

+16-8
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,39 @@ variable "map_accounts" {
1414

1515
variable "map_roles" {
1616
description = "Additional IAM roles to add to the aws-auth configmap."
17-
type = list(map(string))
17+
type = list(object({
18+
rolearn = string
19+
username = string
20+
groups = list(string)
21+
}))
1822

1923
default = [
2024
{
21-
role_arn = "arn:aws:iam::66666666666:role/role1"
25+
rolearn = "arn:aws:iam::66666666666:role/role1"
2226
username = "role1"
23-
group = "system:masters"
27+
groups = ["system:masters"]
2428
},
2529
]
2630
}
2731

2832
variable "map_users" {
2933
description = "Additional IAM users to add to the aws-auth configmap."
30-
type = list(map(string))
34+
type = list(object({
35+
userarn = string
36+
username = string
37+
groups = list(string)
38+
}))
3139

3240
default = [
3341
{
34-
user_arn = "arn:aws:iam::66666666666:user/user1"
42+
userarn = "arn:aws:iam::66666666666:user/user1"
3543
username = "user1"
36-
group = "system:masters"
44+
groups = ["system:masters"]
3745
},
3846
{
39-
user_arn = "arn:aws:iam::66666666666:user/user2"
47+
userarn = "arn:aws:iam::66666666666:user/user2"
4048
username = "user2"
41-
group = "system:masters"
49+
groups = ["system:masters"]
4250
},
4351
]
4452
}

templates/config-map-aws-auth-map_accounts.yaml.tpl

-1
This file was deleted.

templates/config-map-aws-auth-map_roles.yaml.tpl

-4
This file was deleted.

templates/config-map-aws-auth-map_users.yaml.tpl

-4
This file was deleted.

templates/config-map-aws-auth.yaml.tpl

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ metadata:
66
data:
77
mapRoles: |
88
${worker_role_arn}
9-
${map_roles}
9+
%{if chomp(map_roles) != "[]" }
10+
${indent(4, map_roles)}
11+
%{ endif }
12+
%{if chomp(map_users) != "[]" }
1013
mapUsers: |
11-
${map_users}
14+
${indent(4, map_users)}
15+
%{ endif }
16+
%{if chomp(map_accounts) != "[]" }
1217
mapAccounts: |
13-
${map_accounts}
18+
${indent(4, map_accounts)}
19+
%{ endif }

variables.tf

+12-4
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,22 @@ variable "map_accounts" {
6262

6363
variable "map_roles" {
6464
description = "Additional IAM roles to add to the aws-auth configmap. See examples/basic/variables.tf for example format."
65-
type = list(map(string))
66-
default = []
65+
type = list(object({
66+
rolearn = string
67+
username = string
68+
groups = list(string)
69+
}))
70+
default = []
6771
}
6872

6973
variable "map_users" {
7074
description = "Additional IAM users to add to the aws-auth configmap. See examples/basic/variables.tf for example format."
71-
type = list(map(string))
72-
default = []
75+
type = list(object({
76+
userarn = string
77+
username = string
78+
groups = list(string)
79+
}))
80+
default = []
7381
}
7482

7583
variable "subnets" {

0 commit comments

Comments
 (0)