-
Notifications
You must be signed in to change notification settings - Fork 44
/
iam_cluster_autoscaler.tf
86 lines (74 loc) · 2.78 KB
/
iam_cluster_autoscaler.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
79
80
81
82
83
84
85
86
data "aws_iam_policy_document" "cluster_autoscaler_role" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "${replace(aws_iam_openid_connect_provider.eks.url, "https://", "")}:sub"
values = [
"system:serviceaccount:kube-system:cluster-autoscaler",
"system:serviceaccount:kube-system:aws-cluster-autoscaler"
]
}
principals {
identifiers = [aws_iam_openid_connect_provider.eks.arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "cluster_autoscaler_role" {
count = var.cluster_autoscaler_toggle ? 1 : 0
assume_role_policy = data.aws_iam_policy_document.cluster_autoscaler_role.json
name = format("%s-cluster-autoscaler", var.cluster_name)
}
data "aws_iam_policy_document" "cluster_autoscaler_policy" {
version = "2012-10-17"
statement {
effect = "Allow"
actions = [
"autoscaling-plans:DescribeScalingPlans",
"autoscaling-plans:GetScalingPlanResourceForecastData",
"autoscaling-plans:DescribeScalingPlanResources",
"autoscaling:DescribeAutoScalingNotificationTypes",
"autoscaling:DescribeLifecycleHookTypes",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeTerminationPolicyTypes",
"autoscaling:DescribeScalingProcessTypes",
"autoscaling:DescribePolicies",
"autoscaling:DescribeTags",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeMetricCollectionTypes",
"autoscaling:DescribeLoadBalancers",
"autoscaling:DescribeLifecycleHooks",
"autoscaling:DescribeAdjustmentTypes",
"autoscaling:DescribeScalingActivities",
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAccountLimits",
"autoscaling:DescribeScheduledActions",
"autoscaling:DescribeLoadBalancerTargetGroups",
"autoscaling:DescribeNotificationConfigurations",
"autoscaling:DescribeInstanceRefreshes",
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
"ec2:DescribeLaunchTemplateVersions"
]
resources = [
"*"
]
}
}
resource "aws_iam_policy" "cluster_autoscaler_policy" {
count = var.cluster_autoscaler_toggle ? 1 : 0
name = format("%s-cluster-autoscaler", var.cluster_name)
path = "/"
description = var.cluster_name
policy = data.aws_iam_policy_document.cluster_autoscaler_policy[count.index].json
}
resource "aws_iam_policy_attachment" "cluster_autoscaler" {
count = var.cluster_autoscaler_toggle ? 1 : 0
name = "cluster_autoscaler"
roles = [
aws_iam_role.cluster_autoscaler_role[count.index].name
]
policy_arn = aws_iam_policy.cluster_autoscaler_policy[count.index].arn
}