Skip to content

Commit 0a36674

Browse files
Merge pull request #56 from max-rocket-internet/aws-auth_enhancemnts
Fully manage aws-auth configmap file
2 parents 75904e4 + 4046455 commit 0a36674

11 files changed

+136
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
66
project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [[v1.4.0](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v1.3.0...v1.4.0)] - 2018-07-12]
9+
10+
### Added
11+
12+
- New variables `map_accounts`, `map_roles` and `map_users` in order to manage additional entries in the `aws-auth` configmap. (by @max-rocket-internet)
13+
814
## [[v1.3.0](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v1.2.0...v1.3.0)] - 2018-07-??]
915

1016
### Added

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
9898
| cluster_security_group_id | If provided, the EKS cluster will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the workers and provide API access to your current IP/32. | string | `` | no |
9999
| cluster_version | Kubernetes version to use for the EKS cluster. | string | `1.10` | no |
100100
| config_output_path | Determines where config files are placed if using configure_kubectl_session and you want config files to land outside the current working directory. | string | `./` | no |
101-
| configure_kubectl_session | Configure the current session's kubectl to use the instantiated EKS cluster. | string | `true` | no |
102-
| kubeconfig_aws_authenticator_command | Command to use to to fetch AWS EKS credentials | string | `aws-iam-authenticator` | no |
103-
| kubeconfig_aws_authenticator_additional_args | Any additional arguments to pass to the authenticator such as the role to assume. ["-r", "MyEksRole"] | list | `<list>` | no |
104-
| kubeconfig_aws_authenticator_env_variables | Environment variables that should be used when executing the authenticator. e.g. { AWS_PROFILE = "eks"} | map | `<map>` | no |
101+
| kubeconfig_aws_authenticator_additional_args | Any additional arguments to pass to the authenticator such as the role to assume ["-r", "MyEksRole"] | list | `<list>` | no |
102+
| kubeconfig_aws_authenticator_command | Command to use to to fetch AWS EKS credentials | string | `heptio-authenticator-aws` | no |
103+
| kubeconfig_aws_authenticator_env_variables | Environment variables that should be used when executing the authenticator i.e. { AWS_PROFILE = "eks"} | map | `<map>` | no |
105104
| kubeconfig_name | Override the default name used for items kubeconfig. | string | `` | no |
106105
| manage_aws_auth | Whether to write and apply the aws-auth configmap file. | string | `true` | no |
106+
| map_accounts | Additional AWS account numbers to add to the aws-auth configmap. See examples/eks_test_fixture/variables.tf for example format. | list | `<list>` | no |
107+
| map_roles | Additional IAM roles to add to the aws-auth configmap. See examples/eks_test_fixture/variables.tf for example format. | list | `<list>` | no |
108+
| map_users | Additional IAM users to add to the aws-auth configmap. See examples/eks_test_fixture/variables.tf for example format. | list | `<list>` | no |
107109
| subnets | A list of subnets to place the EKS cluster and workers within. | list | - | yes |
108110
| tags | A map of tags to add to all resources. | map | `<map>` | no |
109111
| vpc_id | VPC where the cluster and workers will be deployed. | string | - | yes |
@@ -112,7 +114,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
112114
| worker_sg_ingress_from_port | Minimum port number from which pods will accept communication. Must be changed to a lower value if some pods in your cluster will expose a port lower than 1025 (e.g. 22, 80, or 443). | string | `1025` | no |
113115
| workers_group_defaults | Default values for target groups as defined by the list of maps. | map | `<map>` | no |
114116
| workstation_cidr | Override the default ingress rule that allows communication with the EKS cluster API. If not given, will use current IP/32. | string | `` | no |
115-
| write_kubeconfig | Whether to write a kubeconfig file containing the cluster configuration | string | `true` | no |
117+
| write_kubeconfig | Whether to write a kubeconfig file containing the cluster configuration. | string | `true` | no |
116118
117119
## Outputs
118120

aws_auth.tf

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
resource "local_file" "config_map_aws_auth" {
22
content = "${data.template_file.config_map_aws_auth.rendered}"
3-
filename = "${var.config_output_path}/config-map-aws-auth.yaml"
3+
filename = "${var.config_output_path}/config-map-aws-auth_${var.cluster_name}.yaml"
44
count = "${var.manage_aws_auth ? 1 : 0}"
55
}
66

77
resource "null_resource" "update_config_map_aws_auth" {
88
provisioner "local-exec" {
9-
command = "kubectl apply -f ${var.config_output_path}/config-map-aws-auth.yaml --kubeconfig ${var.config_output_path}/kubeconfig"
9+
command = "kubectl apply -f ${var.config_output_path}/config-map-aws-auth_${var.cluster_name}.yaml --kubeconfig ${var.config_output_path}/kubeconfig_${var.cluster_name}"
1010
}
1111

1212
triggers {
@@ -15,3 +15,45 @@ resource "null_resource" "update_config_map_aws_auth" {
1515

1616
count = "${var.manage_aws_auth ? 1 : 0}"
1717
}
18+
19+
data "template_file" "config_map_aws_auth" {
20+
template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}"
21+
22+
vars {
23+
worker_role_arn = "${aws_iam_role.workers.arn}"
24+
map_users = "${join("", data.template_file.map_users.*.rendered)}"
25+
map_roles = "${join("", data.template_file.map_roles.*.rendered)}"
26+
map_accounts = "${join("", data.template_file.map_accounts.*.rendered)}"
27+
}
28+
}
29+
30+
data "template_file" "map_users" {
31+
count = "${length(var.map_users)}"
32+
template = "${file("${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl")}"
33+
34+
vars {
35+
user_arn = "${lookup(var.map_users[count.index], "user_arn")}"
36+
username = "${lookup(var.map_users[count.index], "username")}"
37+
group = "${lookup(var.map_users[count.index], "group")}"
38+
}
39+
}
40+
41+
data "template_file" "map_roles" {
42+
count = "${length(var.map_roles)}"
43+
template = "${file("${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl")}"
44+
45+
vars {
46+
role_arn = "${lookup(var.map_roles[count.index], "role_arn")}"
47+
username = "${lookup(var.map_roles[count.index], "username")}"
48+
group = "${lookup(var.map_roles[count.index], "group")}"
49+
}
50+
}
51+
52+
data "template_file" "map_accounts" {
53+
count = "${length(var.map_accounts)}"
54+
template = "${file("${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl")}"
55+
56+
vars {
57+
account_number = "${element(var.map_accounts, count.index)}"
58+
}
59+
}

data.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ EOF
7373
}
7474
}
7575

76-
data "template_file" "config_map_aws_auth" {
77-
template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}"
78-
79-
vars {
80-
role_arn = "${aws_iam_role.workers.arn}"
81-
}
82-
}
83-
8476
data "template_file" "userdata" {
8577
template = "${file("${path.module}/templates/userdata.sh.tpl")}"
8678
count = "${length(var.worker_groups)}"

examples/eks_test_fixture/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ module "eks" {
7070
tags = "${local.tags}"
7171
vpc_id = "${module.vpc.vpc_id}"
7272
worker_groups = "${local.worker_groups}"
73+
map_roles = "${var.map_roles}"
74+
map_users = "${var.map_users}"
75+
map_accounts = "${var.map_accounts}"
7376
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
variable "region" {
22
default = "us-west-2"
33
}
4+
5+
variable "map_accounts" {
6+
description = "Additional AWS account numbers to add to the aws-auth configmap."
7+
type = "list"
8+
9+
default = [
10+
"777777777777",
11+
"888888888888",
12+
]
13+
}
14+
15+
variable "map_roles" {
16+
description = "Additional IAM roles to add to the aws-auth configmap."
17+
type = "list"
18+
19+
default = [
20+
{
21+
role_arn = "arn:aws:iam::66666666666:role/role1"
22+
username = "role1"
23+
group = "system:masters"
24+
},
25+
]
26+
}
27+
28+
variable "map_users" {
29+
description = "Additional IAM users to add to the aws-auth configmap."
30+
type = "list"
31+
32+
default = [
33+
{
34+
user_arn = "arn:aws:iam::66666666666:user/user1"
35+
username = "user1"
36+
group = "system:masters"
37+
},
38+
{
39+
user_arn = "arn:aws:iam::66666666666:user/user2"
40+
username = "user2"
41+
group = "system:masters"
42+
},
43+
]
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- "${account_number}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- rolearn: ${role_arn}
2+
username: ${username}
3+
groups:
4+
- ${group}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- userarn: ${user_arn}
2+
username: ${username}
3+
groups:
4+
- ${group}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ metadata:
55
namespace: kube-system
66
data:
77
mapRoles: |
8-
- rolearn: ${role_arn}
8+
- rolearn: ${worker_role_arn}
99
username: system:node:{{EC2PrivateDNSName}}
1010
groups:
1111
- system:bootstrappers
1212
- system:nodes
13+
${map_roles}
14+
mapUsers: |
15+
${map_users}
16+
mapAccounts: |
17+
${map_accounts}

0 commit comments

Comments
 (0)