Skip to content

Commit b7ba5d2

Browse files
authored
Add support for IPv6 (#121)
1 parent 0d9d6a2 commit b7ba5d2

File tree

8 files changed

+98
-46
lines changed

8 files changed

+98
-46
lines changed

.github/renovate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
":preserveSemverRanges"
55
],
66
"labels": ["auto-update"],
7+
"dependencyDashboardAutoclose": true,
78
"enabledManagers": ["terraform"],
89
"terraform": {
910
"ignorePaths": ["**/context.tf", "examples/**"]
1011
}
1112
}
12-

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ The table below correctly indicates which inputs are required.
104104

105105
### Major Changes (breaking and otherwise)
106106

107-
With the v0.25.0 release of this module, it has undergone major breaking
108-
changes and added new features. Please see the [migration](MIGRATION.md)
107+
With the v2.0.0 (a.k.a. v0.25.0) release of this module, it has undergone major breaking
108+
changes and added new features. Please see the [migration](docs/migration-v1-v2.md)
109109
document for details.
110110

111111

112112
For a complete example, see [examples/complete](examples/complete).
113113

114-
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS),
114+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS),
115115
see [test](test).
116116

117117
### Terraform Version
118118

119119
Terraform version 1.0 is out. Before that, there was Terraform version 0.15, 0.14, 0.13 and so on.
120-
The v0.25.0 release of this module drops support for Terraform 0.13. That version is old and has lots of known issues.
120+
The v2.0.0 release of this module drops support for Terraform 0.13. That version is old and has lots of known issues.
121121
There are hardly any breaking changes between Terraform 0.13 and 1.0, so please upgrade to
122122
the latest Terraform version before raising any issues about this module.
123123

@@ -163,7 +163,7 @@ locals {
163163
module "vpc" {
164164
source = "cloudposse/vpc/aws"
165165
# Cloud Posse recommends pinning every module to a specific version
166-
# version = "x.x.x"
166+
# version = "1.x.x"
167167
168168
cidr_block = "172.16.0.0/16"
169169
@@ -174,12 +174,12 @@ module "vpc" {
174174
module "subnets" {
175175
source = "cloudposse/dynamic-subnets/aws"
176176
# Cloud Posse recommends pinning every module to a specific version
177-
# version = "x.x.x"
177+
# version = "2.x.x"
178178
179179
availability_zones = var.availability_zones
180180
vpc_id = module.vpc.vpc_id
181-
igw_id = module.vpc.igw_id
182-
cidr_block = module.vpc.vpc_cidr_block
181+
igw_id = [module.vpc.igw_id]
182+
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
183183
nat_gateway_enabled = true
184184
nat_instance_enabled = false
185185
@@ -190,7 +190,7 @@ module "subnets" {
190190
module "eks_cluster" {
191191
source = "cloudposse/eks-cluster/aws"
192192
# Cloud Posse recommends pinning every module to a specific version
193-
# version = "x.x.x"
193+
# version = "2.x.x"
194194
195195
vpc_id = module.vpc.vpc_id
196196
subnet_ids = module.subnets.public_subnet_ids
@@ -204,7 +204,7 @@ module "eks_cluster" {
204204
module "eks_node_group" {
205205
source = "cloudposse/eks-node-group/aws"
206206
# Cloud Posse recommends pinning every module to a specific version
207-
# version = "x.x.x"
207+
# version = "2.x.x"
208208
209209
instance_types = [var.instance_type]
210210
subnet_ids = module.subnets.public_subnet_ids
@@ -272,16 +272,18 @@ Available targets:
272272
|------|------|
273273
| [aws_eks_node_group.cbd](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) | resource |
274274
| [aws_eks_node_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) | resource |
275+
| [aws_iam_policy.ipv6_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
275276
| [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
276277
| [aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
277-
| [aws_iam_role_policy_attachment.amazon_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
278278
| [aws_iam_role_policy_attachment.amazon_eks_worker_node_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
279279
| [aws_iam_role_policy_attachment.existing_policies_for_eks_workers_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
280+
| [aws_iam_role_policy_attachment.ipv6_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
280281
| [aws_launch_template.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |
281282
| [random_pet.cbd](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
282283
| [aws_ami.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
283284
| [aws_eks_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
284285
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
286+
| [aws_iam_policy_document.ipv6_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
285287
| [aws_launch_template.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/launch_template) | data source |
286288
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
287289

README.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ usage: |2-
6868
6969
### Major Changes (breaking and otherwise)
7070
71-
With the v0.25.0 release of this module, it has undergone major breaking
72-
changes and added new features. Please see the [migration](MIGRATION.md)
71+
With the v2.0.0 (a.k.a. v0.25.0) release of this module, it has undergone major breaking
72+
changes and added new features. Please see the [migration](docs/migration-v1-v2.md)
7373
document for details.
7474
7575
7676
For a complete example, see [examples/complete](examples/complete).
7777
78-
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS),
78+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS),
7979
see [test](test).
8080
8181
### Terraform Version
8282
8383
Terraform version 1.0 is out. Before that, there was Terraform version 0.15, 0.14, 0.13 and so on.
84-
The v0.25.0 release of this module drops support for Terraform 0.13. That version is old and has lots of known issues.
84+
The v2.0.0 release of this module drops support for Terraform 0.13. That version is old and has lots of known issues.
8585
There are hardly any breaking changes between Terraform 0.13 and 1.0, so please upgrade to
8686
the latest Terraform version before raising any issues about this module.
8787
@@ -127,7 +127,7 @@ usage: |2-
127127
module "vpc" {
128128
source = "cloudposse/vpc/aws"
129129
# Cloud Posse recommends pinning every module to a specific version
130-
# version = "x.x.x"
130+
# version = "1.x.x"
131131
132132
cidr_block = "172.16.0.0/16"
133133
@@ -138,12 +138,12 @@ usage: |2-
138138
module "subnets" {
139139
source = "cloudposse/dynamic-subnets/aws"
140140
# Cloud Posse recommends pinning every module to a specific version
141-
# version = "x.x.x"
141+
# version = "2.x.x"
142142
143143
availability_zones = var.availability_zones
144144
vpc_id = module.vpc.vpc_id
145-
igw_id = module.vpc.igw_id
146-
cidr_block = module.vpc.vpc_cidr_block
145+
igw_id = [module.vpc.igw_id]
146+
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
147147
nat_gateway_enabled = true
148148
nat_instance_enabled = false
149149
@@ -154,7 +154,7 @@ usage: |2-
154154
module "eks_cluster" {
155155
source = "cloudposse/eks-cluster/aws"
156156
# Cloud Posse recommends pinning every module to a specific version
157-
# version = "x.x.x"
157+
# version = "2.x.x"
158158
159159
vpc_id = module.vpc.vpc_id
160160
subnet_ids = module.subnets.public_subnet_ids
@@ -168,7 +168,7 @@ usage: |2-
168168
module "eks_node_group" {
169169
source = "cloudposse/eks-node-group/aws"
170170
# Cloud Posse recommends pinning every module to a specific version
171-
# version = "x.x.x"
171+
# version = "2.x.x"
172172
173173
instance_types = [var.instance_type]
174174
subnet_ids = module.subnets.public_subnet_ids

docs/terraform.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
|------|------|
2929
| [aws_eks_node_group.cbd](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) | resource |
3030
| [aws_eks_node_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group) | resource |
31+
| [aws_iam_policy.ipv6_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
3132
| [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
3233
| [aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
33-
| [aws_iam_role_policy_attachment.amazon_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
3434
| [aws_iam_role_policy_attachment.amazon_eks_worker_node_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
3535
| [aws_iam_role_policy_attachment.existing_policies_for_eks_workers_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
36+
| [aws_iam_role_policy_attachment.ipv6_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
3637
| [aws_launch_template.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource |
3738
| [random_pet.cbd](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
3839
| [aws_ami.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
3940
| [aws_eks_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
4041
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
42+
| [aws_iam_policy_document.ipv6_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
4143
| [aws_launch_template.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/launch_template) | data source |
4244
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
4345

examples/complete/main.tf

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ module "label" {
1818
locals {
1919
# The usage of the specific kubernetes.io/cluster/* resource tags below are required
2020
# for EKS and Kubernetes to discover and manage networking resources
21-
# https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#base-vpc-networking
22-
tags = try(merge(module.label.tags, tomap("kubernetes.io/cluster/${module.label.id}", "shared")), null)
21+
# https://aws.amazon.com/premiumsupport/knowledge-center/eks-vpc-subnet-discovery/
22+
# https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/docs/deploy/subnet_discovery.md
23+
tags = { "kubernetes.io/cluster/${module.label.id}" = "shared" }
2324

24-
# Unfortunately, most_recent (https://github.com/cloudposse/terraform-aws-eks-workers/blob/34a43c25624a6efb3ba5d2770a601d7cb3c0d391/main.tf#L141)
25-
# variable does not work as expected, if you are not going to use custom ami you should
26-
# enforce usage of eks_worker_ami_name_filter variable to set the right kubernetes version for EKS workers,
27-
# otherwise will be used the first version of Kubernetes supported by AWS (v1.11) for EKS workers but
28-
# EKS control plane will use the version specified by kubernetes_version variable.
29-
eks_worker_ami_name_filter = "amazon-eks-node-${var.kubernetes_version}*"
25+
# required tags to make ALB ingress work https://docs.aws.amazon.com/eks/latest/userguide/alb-ingress.html
26+
public_subnets_additional_tags = {
27+
"kubernetes.io/role/elb" : 1
28+
}
29+
private_subnets_additional_tags = {
30+
"kubernetes.io/role/internal-elb" : 1
31+
}
3032

3133
allow_all_ingress_rule = {
3234
key = "allow_all_ingress"
@@ -55,7 +57,7 @@ locals {
5557

5658
module "vpc" {
5759
source = "cloudposse/vpc/aws"
58-
version = "0.28.1"
60+
version = "1.1.0"
5961

6062
cidr_block = var.vpc_cidr_block
6163
tags = local.tags
@@ -65,13 +67,14 @@ module "vpc" {
6567

6668
module "subnets" {
6769
source = "cloudposse/dynamic-subnets/aws"
68-
version = "0.39.8"
70+
version = "2.0.2"
6971

7072
availability_zones = var.availability_zones
7173
vpc_id = module.vpc.vpc_id
72-
igw_id = module.vpc.igw_id
73-
cidr_block = module.vpc.vpc_cidr_block
74-
nat_gateway_enabled = false
74+
igw_id = [module.vpc.igw_id]
75+
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
76+
max_nats = 1
77+
nat_gateway_enabled = true
7578
nat_instance_enabled = false
7679
tags = local.tags
7780

@@ -114,7 +117,7 @@ module "https_sg" {
114117

115118
module "eks_cluster" {
116119
source = "cloudposse/eks-cluster/aws"
117-
version = "0.45.0"
120+
version = "2.2.0"
118121

119122
region = var.region
120123
vpc_id = module.vpc.vpc_id

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 0.14.11"
2+
required_version = ">= 1.1.0"
33

44
required_providers {
55
aws = {

iam.tf

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ resource "aws_iam_role_policy_attachment" "amazon_eks_worker_node_policy" {
3636
role = join("", aws_iam_role.default.*.name)
3737
}
3838

39-
resource "aws_iam_role_policy_attachment" "amazon_eks_cni_policy" {
40-
count = local.create_role && var.node_role_cni_policy_enabled ? 1 : 0
41-
policy_arn = format("%s/%s", local.aws_policy_prefix, "AmazonEKS_CNI_Policy")
42-
role = join("", aws_iam_role.default.*.name)
43-
}
44-
4539
resource "aws_iam_role_policy_attachment" "amazon_ec2_container_registry_read_only" {
4640
count = local.create_role ? 1 : 0
4741
policy_arn = format("%s/%s", local.aws_policy_prefix, "AmazonEC2ContainerRegistryReadOnly")
@@ -53,3 +47,54 @@ resource "aws_iam_role_policy_attachment" "existing_policies_for_eks_workers_rol
5347
policy_arn = local.node_role_policy_arns[count.index]
5448
role = join("", aws_iam_role.default.*.name)
5549
}
50+
51+
# Create a CNI policy that is a merger of AmazonEKS_CNI_Policy and required IPv6 permissions
52+
# https://github.com/SummitRoute/aws_managed_policies/blob/master/policies/AmazonEKS_CNI_Policy
53+
# https://docs.aws.amazon.com/eks/latest/userguide/cni-iam-role.html#cni-iam-role-create-ipv6-policy
54+
55+
data "aws_iam_policy_document" "ipv6_eks_cni_policy" {
56+
count = local.create_role && var.node_role_cni_policy_enabled ? 1 : 0
57+
58+
statement {
59+
effect = "Allow"
60+
actions = [
61+
"ec2:AssignIpv6Addresses",
62+
"ec2:AssignPrivateIpAddresses",
63+
"ec2:AttachNetworkInterface",
64+
"ec2:CreateNetworkInterface",
65+
"ec2:DeleteNetworkInterface",
66+
"ec2:DescribeInstances",
67+
"ec2:DescribeInstanceTypes",
68+
"ec2:DescribeTags",
69+
"ec2:DescribeNetworkInterfaces",
70+
"ec2:DetachNetworkInterface",
71+
"ec2:ModifyNetworkInterfaceAttribute",
72+
"ec2:UnassignPrivateIpAddresses"
73+
]
74+
resources = ["*"]
75+
}
76+
statement {
77+
effect = "Allow"
78+
actions = [
79+
"ec2:CreateTags"
80+
]
81+
resources = [
82+
"arn:${join("", data.aws_partition.current.*.partition)}:ec2:*:*:network-interface/*"
83+
]
84+
}
85+
}
86+
87+
resource "aws_iam_policy" "ipv6_eks_cni_policy" {
88+
count = local.create_role && var.node_role_cni_policy_enabled ? 1 : 0
89+
90+
name = "${module.this.id}-CNI_Policy"
91+
policy = join("", data.aws_iam_policy_document.ipv6_eks_cni_policy.*.json)
92+
}
93+
94+
resource "aws_iam_role_policy_attachment" "ipv6_eks_cni_policy" {
95+
count = local.create_role && var.node_role_cni_policy_enabled ? 1 : 0
96+
97+
policy_arn = join("", aws_iam_policy.ipv6_eks_cni_policy.*.arn)
98+
role = join("", aws_iam_role.default.*.name)
99+
}
100+

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ resource "aws_eks_node_group" "default" {
178178
# Otherwise, EKS will not be able to properly delete EC2 Instances and Elastic Network Interfaces.
179179
depends_on = [
180180
aws_iam_role_policy_attachment.amazon_eks_worker_node_policy,
181-
aws_iam_role_policy_attachment.amazon_eks_cni_policy,
181+
aws_iam_role_policy_attachment.ipv6_eks_cni_policy,
182182
aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
183183
aws_iam_role_policy_attachment.existing_policies_for_eks_workers_role,
184184
aws_launch_template.default,
@@ -257,7 +257,7 @@ resource "aws_eks_node_group" "cbd" {
257257
# Otherwise, EKS will not be able to properly delete EC2 Instances and Elastic Network Interfaces.
258258
depends_on = [
259259
aws_iam_role_policy_attachment.amazon_eks_worker_node_policy,
260-
aws_iam_role_policy_attachment.amazon_eks_cni_policy,
260+
aws_iam_role_policy_attachment.ipv6_eks_cni_policy,
261261
aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
262262
aws_launch_template.default,
263263
module.ssh_access,

0 commit comments

Comments
 (0)