forked from cloudposse/terraform-aws-eks-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc-cni.tf
62 lines (49 loc) · 1.88 KB
/
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
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
# `vpc-cni` EKS addon
# https://docs.aws.amazon.com/eks/latest/userguide/cni-iam-role.html
# https://docs.aws.amazon.com/eks/latest/userguide/managing-vpc-cni.html
# https://docs.aws.amazon.com/eks/latest/userguide/cni-iam-role.html#cni-iam-role-create-role
# https://aws.github.io/aws-eks-best-practices/networking/vpc-cni/#deploy-vpc-cni-managed-add-on
locals {
vpc_cni_sa_needed = local.enabled
}
# It is important to enable IPv6 support for the VPC CNI plugin
# even if IPv6 is not in use, because the addon may need to
# manage IPv6 addresses during a transition from IPv6 to IPv4
# or vice versa, or while destroying the cluster.
data "aws_iam_policy_document" "vpc_cni_ipv6" {
count = local.vpc_cni_sa_needed ? 1 : 0
# See https://docs.aws.amazon.com/eks/latest/userguide/cni-iam-role.html#cni-iam-role-create-ipv6-policy
statement {
sid = ""
effect = "Allow"
resources = ["*"]
actions = [
"ec2:AssignIpv6Addresses",
"ec2:DescribeInstances",
"ec2:DescribeTags",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeInstanceTypes"
]
}
statement {
sid = ""
effect = "Allow"
resources = ["arn:aws:ec2:*:*:network-interface/*"]
actions = ["ec2:CreateTags"]
}
}
resource "aws_iam_role_policy_attachment" "vpc_cni" {
count = local.vpc_cni_sa_needed ? 1 : 0
role = module.vpc_cni_eks_iam_role.service_account_role_name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
}
module "vpc_cni_eks_iam_role" {
source = "cloudposse/eks-iam-role/aws"
version = "2.1.1"
enabled = local.vpc_cni_sa_needed
eks_cluster_oidc_issuer_url = module.eks_cluster.eks_cluster_identity_oidc_issuer
service_account_name = "aws-node"
service_account_namespace = "kube-system"
aws_iam_policy_document = try([data.aws_iam_policy_document.vpc_cni_ipv6[0].json], [])
context = module.this.context
}