|
1 | 1 | resource "local_file" "config_map_aws_auth" { |
2 | | - count = "${var.write_aws_auth_config ? 1 : 0}" |
3 | | - content = "${data.template_file.config_map_aws_auth.rendered}" |
| 2 | + count = var.write_aws_auth_config ? 1 : 0 |
| 3 | + content = data.template_file.config_map_aws_auth.rendered |
4 | 4 | filename = "${var.config_output_path}config-map-aws-auth_${var.cluster_name}.yaml" |
5 | 5 | } |
6 | 6 |
|
7 | 7 | resource "null_resource" "update_config_map_aws_auth" { |
8 | | - count = "${var.manage_aws_auth ? 1 : 0}" |
9 | | - depends_on = ["aws_eks_cluster.this"] |
| 8 | + count = var.manage_aws_auth ? 1 : 0 |
| 9 | + depends_on = [aws_eks_cluster.this] |
10 | 10 |
|
11 | 11 | provisioner "local-exec" { |
12 | | - working_dir = "${path.module}" |
| 12 | + working_dir = path.module |
13 | 13 |
|
14 | 14 | command = <<EOS |
15 | 15 | for i in `seq 1 10`; do \ |
16 | | -echo "${null_resource.update_config_map_aws_auth.triggers.kube_config_map_rendered}" > kube_config.yaml & \ |
17 | | -echo "${null_resource.update_config_map_aws_auth.triggers.config_map_rendered}" > aws_auth_configmap.yaml & \ |
| 16 | +echo "${null_resource.update_config_map_aws_auth[0].triggers.kube_config_map_rendered}" > kube_config.yaml & \ |
| 17 | +echo "${null_resource.update_config_map_aws_auth[0].triggers.config_map_rendered}" > aws_auth_configmap.yaml & \ |
18 | 18 | kubectl apply -f aws_auth_configmap.yaml --kubeconfig kube_config.yaml && break || \ |
19 | 19 | sleep 10; \ |
20 | 20 | done; \ |
21 | 21 | rm aws_auth_configmap.yaml kube_config.yaml; |
22 | 22 | EOS |
23 | 23 |
|
24 | | - interpreter = ["${var.local_exec_interpreter}"] |
| 24 | + |
| 25 | + interpreter = var.local_exec_interpreter |
25 | 26 | } |
26 | 27 |
|
27 | | - triggers { |
28 | | - kube_config_map_rendered = "${data.template_file.kubeconfig.rendered}" |
29 | | - config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}" |
30 | | - endpoint = "${aws_eks_cluster.this.endpoint}" |
| 28 | + triggers = { |
| 29 | + kube_config_map_rendered = data.template_file.kubeconfig.rendered |
| 30 | + config_map_rendered = data.template_file.config_map_aws_auth.rendered |
| 31 | + endpoint = aws_eks_cluster.this.endpoint |
31 | 32 | } |
32 | 33 | } |
33 | 34 |
|
34 | | -data "aws_caller_identity" "current" {} |
| 35 | +data "aws_caller_identity" "current" { |
| 36 | +} |
35 | 37 |
|
36 | 38 | data "template_file" "launch_template_mixed_worker_role_arns" { |
37 | | - count = "${var.worker_group_launch_template_mixed_count}" |
38 | | - template = "${file("${path.module}/templates/worker-role.tpl")}" |
39 | | - |
40 | | - vars { |
41 | | - worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(coalescelist(aws_iam_instance_profile.workers_launch_template_mixed.*.role, data.aws_iam_instance_profile.custom_worker_group_launch_template_mixed_iam_instance_profile.*.role_name), count.index)}" |
| 39 | + count = local.worker_group_launch_template_mixed_count |
| 40 | + template = file("${path.module}/templates/worker-role.tpl") |
| 41 | + |
| 42 | + vars = { |
| 43 | + worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element( |
| 44 | + coalescelist( |
| 45 | + aws_iam_instance_profile.workers_launch_template_mixed.*.role, |
| 46 | + data.aws_iam_instance_profile.custom_worker_group_launch_template_mixed_iam_instance_profile.*.role_name, |
| 47 | + ), |
| 48 | + count.index, |
| 49 | + )}" |
42 | 50 | } |
43 | 51 | } |
44 | 52 |
|
45 | 53 | data "template_file" "launch_template_worker_role_arns" { |
46 | | - count = "${var.worker_group_launch_template_count}" |
47 | | - template = "${file("${path.module}/templates/worker-role.tpl")}" |
48 | | - |
49 | | - vars { |
50 | | - worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(coalescelist(aws_iam_instance_profile.workers_launch_template.*.role, data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile.*.role_name), count.index)}" |
| 54 | + count = local.worker_group_launch_template_count |
| 55 | + template = file("${path.module}/templates/worker-role.tpl") |
| 56 | + |
| 57 | + vars = { |
| 58 | + worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element( |
| 59 | + coalescelist( |
| 60 | + aws_iam_instance_profile.workers_launch_template.*.role, |
| 61 | + data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile.*.role_name, |
| 62 | + ), |
| 63 | + count.index, |
| 64 | + )}" |
51 | 65 | } |
52 | 66 | } |
53 | 67 |
|
54 | 68 | data "template_file" "worker_role_arns" { |
55 | | - count = "${var.worker_group_count}" |
56 | | - template = "${file("${path.module}/templates/worker-role.tpl")}" |
57 | | - |
58 | | - vars { |
59 | | - worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(coalescelist(aws_iam_instance_profile.workers.*.role, data.aws_iam_instance_profile.custom_worker_group_iam_instance_profile.*.role_name), count.index)}" |
| 69 | + count = local.worker_group_count |
| 70 | + template = file("${path.module}/templates/worker-role.tpl") |
| 71 | + |
| 72 | + vars = { |
| 73 | + worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element( |
| 74 | + coalescelist( |
| 75 | + aws_iam_instance_profile.workers.*.role, |
| 76 | + data.aws_iam_instance_profile.custom_worker_group_iam_instance_profile.*.role_name, |
| 77 | + [""] |
| 78 | + ), |
| 79 | + count.index, |
| 80 | + )}" |
60 | 81 | } |
61 | 82 | } |
62 | 83 |
|
63 | 84 | data "template_file" "config_map_aws_auth" { |
64 | | - template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}" |
65 | | - |
66 | | - vars { |
67 | | - worker_role_arn = "${join("", distinct(concat(data.template_file.launch_template_worker_role_arns.*.rendered, data.template_file.worker_role_arns.*.rendered, data.template_file.launch_template_mixed_worker_role_arns.*.rendered)))}" |
68 | | - map_users = "${join("", data.template_file.map_users.*.rendered)}" |
69 | | - map_roles = "${join("", data.template_file.map_roles.*.rendered)}" |
70 | | - map_accounts = "${join("", data.template_file.map_accounts.*.rendered)}" |
| 85 | + template = file("${path.module}/templates/config-map-aws-auth.yaml.tpl") |
| 86 | + |
| 87 | + vars = { |
| 88 | + worker_role_arn = join( |
| 89 | + "", |
| 90 | + distinct( |
| 91 | + concat( |
| 92 | + data.template_file.launch_template_worker_role_arns.*.rendered, |
| 93 | + data.template_file.worker_role_arns.*.rendered, |
| 94 | + data.template_file.launch_template_mixed_worker_role_arns.*.rendered, |
| 95 | + ), |
| 96 | + ), |
| 97 | + ) |
| 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) |
71 | 101 | } |
72 | 102 | } |
73 | 103 |
|
74 | 104 | data "template_file" "map_users" { |
75 | | - count = "${var.map_users_count}" |
76 | | - template = "${file("${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl")}" |
77 | | - |
78 | | - vars { |
79 | | - user_arn = "${lookup(var.map_users[count.index], "user_arn")}" |
80 | | - username = "${lookup(var.map_users[count.index], "username")}" |
81 | | - group = "${lookup(var.map_users[count.index], "group")}" |
| 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"] |
82 | 114 | } |
83 | 115 | } |
84 | 116 |
|
85 | 117 | data "template_file" "map_roles" { |
86 | | - count = "${var.map_roles_count}" |
87 | | - template = "${file("${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl")}" |
88 | | - |
89 | | - vars { |
90 | | - role_arn = "${lookup(var.map_roles[count.index], "role_arn")}" |
91 | | - username = "${lookup(var.map_roles[count.index], "username")}" |
92 | | - group = "${lookup(var.map_roles[count.index], "group")}" |
| 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"] |
93 | 127 | } |
94 | 128 | } |
95 | 129 |
|
96 | 130 | data "template_file" "map_accounts" { |
97 | | - count = "${var.map_accounts_count}" |
98 | | - template = "${file("${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl")}" |
| 131 | + count = length(var.map_accounts) |
| 132 | + template = file( |
| 133 | + "${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl", |
| 134 | + ) |
99 | 135 |
|
100 | | - vars { |
101 | | - account_number = "${element(var.map_accounts, count.index)}" |
| 136 | + vars = { |
| 137 | + account_number = var.map_accounts[count.index] |
102 | 138 | } |
103 | 139 | } |
| 140 | + |
0 commit comments