-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipv6.tf
160 lines (128 loc) · 3.75 KB
/
ipv6.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
provider "aws" {
region = "${var.aws_region}"
profile = "${var.aws_profile}"
}
variable "aws_region" {
type = "string"
default = "us-east-1"
}
variable "aws_profile" {
type = "string"
default = ""
}
variable "key_name" {
type = "string"
default = "ipv6_key"
}
# Ubuntu AMIs from https://cloud-images.ubuntu.com/locator/ec2/
variable "instance_ami" {
type = "string"
default = "ami-9887c6e7" # CentOS 7 (x86_64) - with Updates HVM in us-east-1
}
variable "instance_size" {
type = "string"
default = "r3.xlarge"
}
data "aws_availability_zones" "available" {}
data "template_file" "userdata" {
template = "${file("userdata.tpl")}"
vars {}
}
# AWS will assign the VPC an IPv6 CIDR with a prefix length of /56
resource "aws_vpc" "ipv6_vpc" {
cidr_block = "10.16.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
assign_generated_ipv6_cidr_block = true
tags {
Name = "ipv6_vpc"
}
}
# The subnet IPv6 CIDR must be in the VPC CIDR and have a prefix length of /64
resource "aws_subnet" "public_ipv6" {
vpc_id = "${aws_vpc.ipv6_vpc.id}"
cidr_block = "${cidrsubnet(aws_vpc.ipv6_vpc.cidr_block, 4, 0)}"
ipv6_cidr_block = "${cidrsubnet(aws_vpc.ipv6_vpc.ipv6_cidr_block, 8, 0)}"
map_public_ip_on_launch = true
assign_ipv6_address_on_creation = true
availability_zone = "${data.aws_availability_zones.available.names[0]}"
tags {
Name = "public_ipv6"
}
}
# The security group must allow ingress and egress from IPv6
resource "aws_security_group" "ipv6_security" {
name = "ipv6_security"
description = "IPv6 Security"
vpc_id = "${aws_vpc.ipv6_vpc.id}"
revoke_rules_on_delete = true
tags {
Name = "ipv6_security"
}
# Allow connections from any IPv4 or IPv6 address; this is not secure
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.ipv6_vpc.id}"
tags {
Name = "ipv6_gateway"
}
}
resource "aws_route_table" "ipv6_route_table" {
vpc_id = "${aws_vpc.ipv6_vpc.id}"
# Route all IPv6 traffic to the Internet gateway
route {
ipv6_cidr_block = "::/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
# Route all IPv4 traffic to the Internet gateway
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
tags {
Name = "ipv6_subnet"
}
}
# The route table must be associated with the subnet
resource "aws_route_table_association" "public_ipv6" {
subnet_id = "${aws_subnet.public_ipv6.id}"
route_table_id = "${aws_route_table.ipv6_route_table.id}"
}
resource "aws_instance" "ipv6_mdw" {
ami = "${var.instance_ami}"
instance_type = "${var.instance_size}"
key_name = "${var.key_name}"
subnet_id = "${aws_subnet.public_ipv6.id}"
vpc_security_group_ids = ["${aws_security_group.ipv6_security.id}"]
associate_public_ip_address = true
user_data = "${data.template_file.userdata.rendered}"
tags {
Name = "ipv6_mdw"
}
}
resource "aws_instance" "ipv6_sdw1" {
ami = "${var.instance_ami}"
instance_type = "${var.instance_size}"
key_name = "${var.key_name}"
subnet_id = "${aws_subnet.public_ipv6.id}"
vpc_security_group_ids = ["${aws_security_group.ipv6_security.id}"]
associate_public_ip_address = true
user_data = "${data.template_file.userdata.rendered}"
tags {
Name = "ipv6_sdw1"
}
}