-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.tf
58 lines (47 loc) · 1.55 KB
/
main.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
locals {
create_aws_auth_configmap = length(var.eks.eks_managed_node_groups) == 0 && length(var.eks.fargate_profiles) == 0
patch_aws_auth_configmap = !local.create_aws_auth_configmap
merged_map_roles = distinct(concat(
try(yamldecode(yamldecode(var.eks.aws_auth_configmap_yaml).data.mapRoles), []),
var.map_roles,
))
aws_auth_configmap_yaml = templatefile("${path.module}/templates/aws_auth_cm.tpl",
{
map_roles = local.merged_map_roles
map_users = var.map_users
map_accounts = var.map_accounts
}
)
}
data "http" "wait_for_cluster" {
url = format("%s/healthz", var.eks.cluster_endpoint)
ca_certificate = base64decode(var.eks.cluster_certificate_authority_data)
timeout = var.wait_for_cluster_timeout
}
resource "kubernetes_config_map_v1" "aws_auth" {
count = local.create_aws_auth_configmap ? 1 : 0
depends_on = [data.http.wait_for_cluster]
metadata {
name = "aws-auth"
namespace = "kube-system"
}
data = {
"mapRoles" = yamlencode(local.merged_map_roles)
"mapUsers" = yamlencode(var.map_users)
"mapAccounts" = yamlencode(var.map_accounts)
}
}
resource "kubernetes_config_map_v1_data" "aws_auth" {
count = local.patch_aws_auth_configmap ? 1 : 0
depends_on = [data.http.wait_for_cluster]
metadata {
name = "aws-auth"
namespace = "kube-system"
}
data = {
"mapRoles" = yamlencode(local.merged_map_roles)
"mapUsers" = yamlencode(var.map_users)
"mapAccounts" = yamlencode(var.map_accounts)
}
force = true
}