-
Notifications
You must be signed in to change notification settings - Fork 0
/
eks_cluster_role.tf
61 lines (58 loc) · 1.79 KB
/
eks_cluster_role.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
# EKS cluster Permissions part
resource "aws_iam_role" "eks_cluster_role" {
name = "${var.eks_cluster_name}-cluster-role"
description = "Allow cluster to manage node groups, fargate nodes and cloudwatch logs"
force_detach_policies = true
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"eks.amazonaws.com",
"eks-fargate-pods.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
tags = merge(var.tags, var.default_tags)
}
resource "aws_iam_role_policy_attachment" "AmazonEKSClusterPolicy1" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.eks_cluster_role.name
}
resource "aws_iam_role_policy_attachment" "AmazonEKSVPCResourceController1" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
role = aws_iam_role.eks_cluster_role.name
}
resource "aws_iam_policy" "AmazonEKSClusterCloudWatchMetricsPolicy" {
name = "${var.eks_cluster_name}-cw-metrics-cust-policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"cloudwatch:PutMetricData"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
EOF
tags = merge(var.tags, var.default_tags)
}
resource "aws_iam_role_policy_attachment" "AmazonEKSCloudWatchMetricsPolicy" {
policy_arn = aws_iam_policy.AmazonEKSClusterCloudWatchMetricsPolicy.arn
role = aws_iam_role.eks_cluster_role.name
}
resource "aws_cloudwatch_log_group" "cloudwatch_log_group" {
name = "/aws/eks/${var.eks_cluster_name}/cluster"
retention_in_days = var.eks_logs_retention_in_days
}