forked from terraform-aws-modules/terraform-aws-eks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_auth.tf
73 lines (58 loc) · 2.57 KB
/
aws_auth.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
resource "local_file" "config_map_aws_auth" {
content = "${data.template_file.config_map_aws_auth.rendered}"
filename = "${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml"
count = "${var.manage_aws_auth ? 1 : 0}"
}
resource "null_resource" "update_config_map_aws_auth" {
depends_on = ["aws_eks_cluster.this"]
provisioner "local-exec" {
command = "for i in {1..5}; do kubectl apply -f ${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml --kubeconfig ${var.config_output_path}kubeconfig_${var.cluster_name} && break || sleep 10; done"
interpreter = ["${var.local_exec_interpreter}"]
}
triggers {
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
}
count = "${var.manage_aws_auth ? 1 : 0}"
}
data "aws_caller_identity" "current" {}
data "template_file" "worker_role_arns" {
count = "${var.worker_group_count}"
template = "${file("${path.module}/templates/worker-role.tpl")}"
vars {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(aws_iam_instance_profile.workers.*.role, count.index)}"
}
}
data "template_file" "config_map_aws_auth" {
template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}"
vars {
worker_role_arn = "${join("", distinct(data.template_file.worker_role_arns.*.rendered))}"
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)}"
}
}
data "template_file" "map_users" {
count = "${var.map_users_count}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl")}"
vars {
user_arn = "${lookup(var.map_users[count.index], "user_arn")}"
username = "${lookup(var.map_users[count.index], "username")}"
group = "${lookup(var.map_users[count.index], "group")}"
}
}
data "template_file" "map_roles" {
count = "${var.map_roles_count}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl")}"
vars {
role_arn = "${lookup(var.map_roles[count.index], "role_arn")}"
username = "${lookup(var.map_roles[count.index], "username")}"
group = "${lookup(var.map_roles[count.index], "group")}"
}
}
data "template_file" "map_accounts" {
count = "${var.map_accounts_count}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl")}"
vars {
account_number = "${element(var.map_accounts, count.index)}"
}
}