-
Notifications
You must be signed in to change notification settings - Fork 41
/
cluster_iam.tf
44 lines (40 loc) · 1.49 KB
/
cluster_iam.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
locals {
eks_cluster_role_arn = length(var.cluster_role_arn) == 0 ? aws_iam_role.eks_cluster_role[0].arn : var.cluster_role_arn
}
resource "aws_iam_role" "eks_cluster_role" {
count = length(var.cluster_role_arn) == 0 ? 1 : 0
name = "${var.iam_role_name_prefix}EksCluster-${var.name}"
assume_role_policy = data.aws_iam_policy_document.eks_assume_role_policy.json
# Resources running on the cluster are still generating logs when destroying the module resources
# which results in the log group being re-created even after Terraform destroys it. Removing the
# ability for the cluster role to create the log group prevents this log group from being re-created
# outside of Terraform due to services still generating logs during destroy process
inline_policy {
name = "DenyLogGroupCreation"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["logs:CreateLogGroup"]
Effect = "Deny"
Resource = "*"
},
]
})
}
}
data "aws_iam_policy_document" "eks_assume_role_policy" {
statement {
principals {
type = "Service"
identifiers = ["eks.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
effect = "Allow"
}
}
resource "aws_iam_role_policy_attachment" "eks_cluster_policy" {
count = length(var.cluster_role_arn) == 0 ? 1 : 0
role = aws_iam_role.eks_cluster_role[0].name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}