-
Notifications
You must be signed in to change notification settings - Fork 1
/
eks-access-entries.tf
91 lines (70 loc) · 2.89 KB
/
eks-access-entries.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#################################################################################
# Access Entry for Cluster access
#################################################################################
## The resources access entry and policy association is targeting roles that require cluster admins permissions
## it can be repeated for roles that require different cluster policy
resource "aws_eks_access_entry" "cluster_admin" {
for_each = toset(var.admin_principal_arns)
cluster_name = local.name
kubernetes_groups = []
principal_arn = each.value
type = "STANDARD"
user_name = try(each.value.user_name, null)
depends_on = [module.eks_managed_node_groups]
}
resource "aws_eks_access_policy_association" "cluster_admin" {
for_each = toset(var.admin_principal_arns)
access_scope {
namespaces = []
type = "cluster"
}
cluster_name = local.name
policy_arn = "arn:${data.aws_partition.current.partition}:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy"
principal_arn = each.value
depends_on = [aws_eks_access_entry.cluster_admin]
}
## The resources access entry and policy association is targeting roles that require cluster Admin ReadOnly Permissions
resource "aws_eks_access_entry" "cluster_admin_readonly" {
for_each = toset(var.admin_readonly_principal_arns)
cluster_name = local.name
kubernetes_groups = []
principal_arn = each.value
type = "STANDARD"
user_name = try(each.value.user_name, null)
depends_on = [module.eks_managed_node_groups]
}
resource "aws_eks_access_policy_association" "cluster_admin_readonly" {
for_each = toset(var.admin_readonly_principal_arns)
access_scope {
namespaces = []
type = "cluster"
}
cluster_name = local.name
policy_arn = "arn:${data.aws_partition.current.partition}:eks::aws:cluster-access-policy/AmazonEKSAdminViewPolicy"
principal_arn = each.value
depends_on = [aws_eks_access_entry.cluster_admin_readonly]
}
## Creating access entry for delete_ebs_volumes_lambda with namespaced adminpolicy
resource "aws_eks_access_entry" "delete_ebs_volume" {
count = var.delete_ebs_volume_role_arn != "" ? 1 : 0
cluster_name = local.name
kubernetes_groups = []
principal_arn = var.delete_ebs_volume_role_arn
type = "STANDARD"
user_name = (null)
depends_on = [
module.eks_managed_node_groups,
kubectl_manifest.batcave_namespace
]
}
resource "aws_eks_access_policy_association" "delete_ebs_volume" {
count = var.delete_ebs_volume_role_arn != "" ? 1 : 0
access_scope {
namespaces = ["batcave"]
type = "namespace"
}
cluster_name = local.name
policy_arn = "arn:${data.aws_partition.current.partition}:eks::aws:cluster-access-policy/AmazonEKSAdminPolicy"
principal_arn = var.delete_ebs_volume_role_arn
depends_on = [aws_eks_access_entry.delete_ebs_volume]
}