-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.tf
66 lines (58 loc) · 1.84 KB
/
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
62
63
64
65
66
resource "aws_iam_role" "this" {
name = local.resource_name
assume_role_policy = data.aws_iam_policy_document.this_assume.json
force_detach_policies = true
tags = local.tags
}
data "aws_iam_policy_document" "this_assume" {
statement {
sid = "AssumeEKS"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"eks.amazonaws.com",
"eks-fargate-pods.amazonaws.com",
]
}
}
}
resource "aws_iam_policy" "this" {
name = "${local.resource_name}-cluster_role"
policy = data.aws_iam_policy_document.this.json
tags = local.tags
}
data "aws_iam_policy_document" "this" {
#bridgecrew:skip=BC_AWS_IAM_57:Kubernetes needs to create and manage load balancers and put metric data across many resources
statement {
sid = "EnableMetrics"
effect = "Allow"
resources = ["*"]
actions = ["cloudwatch:PutMetricData"]
}
statement {
sid = "EnableLoadBalancing"
effect = "Allow"
resources = ["*"]
actions = ["elasticloadbalancing:*"]
}
}
resource "aws_iam_role_policy_attachment" "this" {
policy_arn = aws_iam_policy.this.arn
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this_basic" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this_service" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
role = aws_iam_role.this.name
}
# Enable Security Groups for Pods
# Reference: https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html
resource "aws_iam_role_policy_attachment" "this_vpc" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
role = aws_iam_role.this.name
}