@@ -28,6 +28,10 @@ resource "random_password" "cluster_secret" {
2828resource "aws_vpc" "aws_vpc" {
2929 cidr_block = " 10.0.0.0/16"
3030
31+ assign_generated_ipv6_cidr_block = true
32+ enable_dns_support = true
33+ enable_dns_hostnames = true
34+
3135 tags = {
3236 Name = " ${ var . aws_vpc_name } -${ random_string . random_suffix . id } "
3337 Owner = var.resources_owner
@@ -55,16 +59,23 @@ resource "aws_route_table" "aws_public_rt" {
5559 gateway_id = aws_internet_gateway. aws_igw . id
5660 }
5761
62+ route {
63+ ipv6_cidr_block = " ::/0"
64+ gateway_id = aws_internet_gateway. aws_igw . id
65+ }
66+
5867 tags = {
5968 Name = " lh_aws_public_rt-${ random_string . random_suffix . id } "
6069 Owner = var.resources_owner
6170 }
6271}
6372
6473resource "aws_subnet" "aws_subnet_1" {
65- vpc_id = aws_vpc. aws_vpc . id
66- availability_zone = " us-east-1c"
67- cidr_block = " 10.0.1.0/24"
74+ vpc_id = aws_vpc. aws_vpc . id
75+ availability_zone = " us-east-1c"
76+ cidr_block = " 10.0.1.0/24"
77+ ipv6_cidr_block = cidrsubnet (aws_vpc. aws_vpc . ipv6_cidr_block , 8 , 0 )
78+ assign_ipv6_address_on_creation = true
6879
6980 tags = {
7081 Name = " lh_subnet_1-${ random_string . random_suffix . id } "
@@ -73,9 +84,11 @@ resource "aws_subnet" "aws_subnet_1" {
7384}
7485
7586resource "aws_subnet" "aws_subnet_2" {
76- vpc_id = aws_vpc. aws_vpc . id
77- availability_zone = " us-east-1c"
78- cidr_block = " 10.0.2.0/24"
87+ vpc_id = aws_vpc. aws_vpc . id
88+ availability_zone = " us-east-1c"
89+ cidr_block = " 10.0.2.0/24"
90+ ipv6_cidr_block = cidrsubnet (aws_vpc. aws_vpc . ipv6_cidr_block , 8 , 1 )
91+ assign_ipv6_address_on_creation = true
7992
8093 tags = {
8194 Name = " lh_subnet_2-${ random_string . random_suffix . id } "
@@ -109,19 +122,19 @@ resource "aws_security_group" "aws_secgrp" {
109122 vpc_id = aws_vpc. aws_vpc . id
110123
111124 ingress {
112- description = " Allow SSH "
113- from_port = 22
114- to_port = 22
115- protocol = " tcp "
125+ description = " Allow all ports "
126+ from_port = 0
127+ to_port = 0
128+ protocol = " -1 "
116129 cidr_blocks = [" 0.0.0.0/0" ]
117130 }
118131
119132 ingress {
120- description = " Allow all ports"
133+ description = " Allow all ports over IPv6 "
121134 from_port = 0
122135 to_port = 0
123136 protocol = " -1"
124- cidr_blocks = [" 0.0.0.0 /0" ]
137+ ipv6_cidr_blocks = [" :: /0" ]
125138 }
126139
127140 egress {
@@ -131,6 +144,13 @@ resource "aws_security_group" "aws_secgrp" {
131144 cidr_blocks = [" 0.0.0.0/0" ]
132145 }
133146
147+ egress {
148+ from_port = 0
149+ to_port = 0
150+ protocol = " -1"
151+ ipv6_cidr_blocks = [" ::/0" ]
152+ }
153+
134154 tags = {
135155 Name = " lh_aws_secgrp-${ random_string . random_suffix . id } "
136156 Owner = var.resources_owner
@@ -145,6 +165,7 @@ resource "aws_key_pair" "aws_pair_key" {
145165resource "aws_network_interface" "instance_eth0" {
146166 subnet_id = aws_subnet. aws_subnet_1 . id
147167 security_groups = [aws_security_group . aws_secgrp . id ]
168+ ipv6_address_count = 1
148169
149170 count = var. aws_instance_count
150171
@@ -195,6 +216,7 @@ resource "aws_network_interface" "instance_eth1" {
195216
196217 subnet_id = aws_subnet. aws_subnet_2 . id
197218 security_groups = [aws_security_group . aws_secgrp . id ]
219+ ipv6_address_count = 1
198220
199221 count = var. aws_instance_count
200222
@@ -257,7 +279,16 @@ resource "null_resource" "rsync_kubeconfig_file" {
257279 }
258280
259281 provisioner "local-exec" {
260- command = " rsync -aPvz --rsync-path=\" sudo rsync\" -e \" ssh -o StrictHostKeyChecking=no -l ec2-user -i ${ var . aws_ssh_private_key_file_path } \" ${ aws_eip . aws_eip [0 ]. public_ip } :/etc/rancher/k3s/k3s.yaml . && sed -i 's#https://127.0.0.1:6443#https://${ aws_eip . aws_eip [0 ]. public_ip } :6443#' k3s.yaml"
282+ command = << EOT
283+ export K3S_SERVER_IP=$(
284+ [ "${ var . network_stack } " = "ipv6" ] && echo "[${ aws_instance . aws_instance [0 ]. ipv6_addresses [0 ]} ]" || echo ${ aws_eip . aws_eip [0 ]. public_ip }
285+ )
286+ export LOCAL_IP=$(
287+ [ "${ var . network_stack } " = "ipv6" ] && echo "\[::1\]" || echo "127.0.0.1"
288+ )
289+ rsync -aPvz --rsync-path="sudo rsync" -e "ssh -o StrictHostKeyChecking=no -l ec2-user -i ${ var . aws_ssh_private_key_file_path } " "${ aws_eip . aws_eip [0 ]. public_ip } :/etc/rancher/k3s/k3s.yaml" . && \
290+ sed -i "s#https://$LOCAL_IP:6443#https://$K3S_SERVER_IP:6443#" k3s.yaml
291+ EOT
261292 }
262293}
263294
0 commit comments