-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiam.tf
76 lines (65 loc) · 2.17 KB
/
iam.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
/**
* Copyright (c) 2017-present SIGHUP s.r.l All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
data "aws_eks_cluster" "this" {
name = var.cluster_name
}
data "aws_iam_policy_document" "cluster_autoscaler" {
statement {
effect = "Allow"
actions = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeTags",
"ec2:DescribeLaunchTemplateVersions",
"ec2:DescribeInstanceTypes",
"ec2:DescribeImages",
"ec2:GetInstanceTypesFromInstanceRequirements",
"eks:DescribeNodegroup"
]
resources = [
"*",
]
}
statement {
effect = "Allow"
actions = [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
]
resources = [
"*",
]
condition {
test = "StringEquals"
variable = "autoscaling:ResourceTag/kubernetes.io/cluster/${var.cluster_name}"
values = [
"owned",
]
}
condition {
test = "StringEquals"
variable = "autoscaling:ResourceTag/k8s.io/cluster-autoscaler/enabled"
values = [
"true",
]
}
}
}
resource "aws_iam_policy" "cluster_autoscaler" {
name = "${var.cluster_name}-cluster-autoscaler"
description = "EKS cluster-autoscaler IAM policy for cluster ${var.cluster_name}"
policy = data.aws_iam_policy_document.cluster_autoscaler.json
}
module "cluster_autoscaler_iam_assumable_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "v3.16.0"
create_role = true
role_name = coalesce(var.autoscaler_iam_role_name_override, "${var.cluster_name}-cluster-autoscaler")
provider_url = replace(data.aws_eks_cluster.this.identity[0].oidc[0].issuer, "https://", "")
role_policy_arns = [aws_iam_policy.cluster_autoscaler.arn]
oidc_fully_qualified_subjects = ["system:serviceaccount:kube-system:cluster-autoscaler"]
}