-
Notifications
You must be signed in to change notification settings - Fork 43
/
public-subnet.tf
67 lines (56 loc) · 1.81 KB
/
public-subnet.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
/* Internet gateway for the public subnet */
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.default.id}"
}
/* Public subnets */
resource "aws_subnet" "public_az1" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet_az1_cidr}"
availability_zone = "eu-west-1a"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.default"]
tags {
Name = "public az1"
}
}
resource "aws_subnet" "public_az2" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet_az2_cidr}"
availability_zone = "eu-west-1b"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.default"]
tags {
Name = "public az2"
}
}
resource "aws_subnet" "public_az3" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet_az3_cidr}"
availability_zone = "eu-west-1c"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.default"]
tags {
Name = "public az3"
}
}
/* Routing table for public subnet */
resource "aws_route_table" "public" {
vpc_id = "${aws_vpc.default.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
}
/* Associate the routing table to public subnets */
resource "aws_route_table_association" "public_az1" {
subnet_id = "${aws_subnet.public_az1.id}"
route_table_id = "${aws_route_table.public.id}"
}
resource "aws_route_table_association" "public_az2" {
subnet_id = "${aws_subnet.public_az2.id}"
route_table_id = "${aws_route_table.public.id}"
}
resource "aws_route_table_association" "public_az3" {
subnet_id = "${aws_subnet.public_az3.id}"
route_table_id = "${aws_route_table.public.id}"
}