-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam_aws_vpc_cni.tf
36 lines (32 loc) · 1.1 KB
/
iam_aws_vpc_cni.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
locals {
handle_aws_vpc_cni = var.handle_iam_resources && var.handle_iam_aws_vpc_cni
}
resource "aws_iam_role" "aws_vpc_cni" {
count = local.handle_aws_vpc_cni ? 1 : 0
name = var.aws_vpc_cni_role_name
description = "IAM Role required for Amazon VPC CNI."
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Federated = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${local.cluster_oidc_issuer}"
}
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
StringEquals = {
"${local.cluster_oidc_issuer}:aud" : "sts.amazonaws.com"
"${local.cluster_oidc_issuer}:sub" : "system:serviceaccount:${var.aws_vpc_cni_sa.namespace}:${var.aws_vpc_cni_sa.name}"
}
}
}
]
})
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "aws_vpc_cni" {
count = local.handle_aws_vpc_cni ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.aws_vpc_cni[0].name
}