-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam_cluster.tf
79 lines (68 loc) · 1.89 KB
/
iam_cluster.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
resource "aws_iam_role" "eks_cluster_role" {
name = var.cluster_iam_role_name
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = {
Service = "eks.amazonaws.com"
},
Action = "sts:AssumeRole"
}
]
})
}
resource "aws_iam_policy" "eks_cloudwatch_metrics" {
name = var.cloudwatch_iam_role_name
description = "Policy for EKS worker nodes"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Sid = "CloudWatchMetric",
Effect = "Allow",
Action = [
"cloudwatch:PutMetricData"
]
Resource = "*"
}
]
})
}
resource "aws_iam_policy" "eks_elb_perms" {
name = var.elb_iam_role_name
description = "Policy for EKS worker nodes"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Sid = "ELBPolicy",
Effect = "Allow",
Action = [
"ec2:DescribeAccountAttributes",
"ec2:DescribeAddresses",
"ec2:DescribeInternetGateways"
]
Resource = "*"
}
]
})
}
# Attach required policies to the IAM role
resource "aws_iam_role_policy_attachment" "eks_cluster_policy" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}
resource "aws_iam_role_policy_attachment" "eks_vpc_rc" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
}
resource "aws_iam_role_policy_attachment" "eks_cloud_watch" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = aws_iam_policy.eks_cloudwatch_metrics.arn
}
resource "aws_iam_role_policy_attachment" "eks_elb" {
role = aws_iam_role.eks_cluster_role.name
policy_arn = aws_iam_policy.eks_elb_perms.arn
}