-
Notifications
You must be signed in to change notification settings - Fork 1
/
irsa.tf
82 lines (64 loc) · 2.24 KB
/
irsa.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
data "aws_iam_policy_document" "cluster_autoscaler_sts" {
statement {
effect = "Allow"
actions = [
"sts:AssumeRoleWithWebIdentity"
]
principals {
type = "Federated"
identifiers = [module.eks.oidc_provider_arn]
}
condition {
test = "StringEquals"
variable = "${replace(module.eks.oidc_provider_arn, "/^(.*provider/)/", "")}:sub"
values = ["system:serviceaccount:kube-system:cluster-autoscaler"]
}
# https://aws.amazon.com/premiumsupport/knowledge-center/eks-troubleshoot-oidc-and-irsa/?nc1=h_ls
condition {
test = "StringEquals"
variable = "${replace(module.eks.oidc_provider_arn, "/^(.*provider/)/", "")}:aud"
values = ["sts.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "cluster_autoscaler" {
statement {
actions = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeScalingActivities",
"autoscaling:DescribeTags",
"ec2:DescribeLaunchTemplateVersions",
"ec2:DescribeInstanceTypes",
"eks:DescribeNodegroup",
]
resources = ["*"]
}
statement {
actions = [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
"autoscaling:UpdateAutoScalingGroup",
]
resources = ["*"]
condition {
test = "StringEquals"
variable = "autoscaling:ResourceTag/kubernetes.io/cluster/${module.eks.cluster_id}"
values = ["owned"]
}
}
}
resource "aws_iam_role" "cluster_autoscaler" {
name = format("%s-cluster_autoscaler-role", module.eks.cluster_id)
assume_role_policy = data.aws_iam_policy_document.cluster_autoscaler_sts.json
}
resource "aws_iam_policy" "cluster_autoscaler" {
name = format("%s-ClusterAutoscalerPolicy", module.eks.cluster_id)
description = "Cluster autoscaler policy to allow examination and modification of EC2 Auto Scaling Groups"
policy = data.aws_iam_policy_document.cluster_autoscaler.json
}
resource "aws_iam_role_policy_attachment" "cluster_autoscaler" {
role = aws_iam_role.cluster_autoscaler.name
policy_arn = aws_iam_policy.cluster_autoscaler.arn
}