-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheks-enable-iam-role-sa.tf
32 lines (27 loc) · 1009 Bytes
/
eks-enable-iam-role-sa.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
data "tls_certificate" "tst-eks" {
url = aws_eks_cluster.tst-eks.identity[0].oidc[0].issuer
}
resource "aws_iam_openid_connect_provider" "tst-eks" {
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = [data.tls_certificate.tst-eks.certificates[0].sha1_fingerprint]
url = aws_eks_cluster.tst-eks.identity[0].oidc[0].issuer
}
data "aws_iam_policy_document" "tst-eks_assume_role_policy" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "${replace(aws_iam_openid_connect_provider.tst-eks.url, "https://", "")}:sub"
values = ["system:serviceaccount:kube-system:aws-node"]
}
principals {
identifiers = [aws_iam_openid_connect_provider.tst-eks.arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "tst-eks-for-sa" {
assume_role_policy = data.aws_iam_policy_document.tst-eks_assume_role_policy.json
name = "tst-eks-for-sa"
}