-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
node_role.tf
76 lines (64 loc) · 2.05 KB
/
node_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
67
68
69
70
71
72
73
74
75
76
resource "aws_iam_role" "node" {
name = "${var.environment_name}-node"
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
Version = "2012-10-17"
})
tags = local.tags
}
resource "aws_iam_role_policy_attachment" "node-AmazonEKSWorkerNodePolicy" {
policy_arn = "arn:${local.partition}:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node-AmazonEKS_CNI_Policy" {
policy_arn = "arn:${local.partition}:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node-AmazonEC2ContainerRegistryReadOnly" {
policy_arn = "arn:${local.partition}:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node_role_policies" {
count = length(var.node_role_policies)
policy_arn = var.node_role_policies[count.index]
role = aws_iam_role.node.name
}
resource "aws_iam_policy" "eks_pod_logs_to_cloudwatch" {
count = var.cloudwatch_pod_logs_enabled ? 1 : 0
name = "${var.environment_name}-EksPodLogsToCloudwatch"
description = "Used by fluentbit agent to send eks pods logs to cloudwatch"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:CreateLogGroup",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "node_eks_pod_logs_to_cloudwatch" {
count = var.cloudwatch_pod_logs_enabled ? 1 : 0
policy_arn = aws_iam_policy.eks_pod_logs_to_cloudwatch[count.index].arn
role = aws_iam_role.node.name
}
resource "aws_iam_instance_profile" "node" {
name = "${var.environment_name}-node"
role = aws_iam_role.node.name
tags = local.tags
}