-
Notifications
You must be signed in to change notification settings - Fork 1
/
subnet-public.tf
33 lines (30 loc) · 1.01 KB
/
subnet-public.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
# Public subnet Internet gateway
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.default.id}"
}
# Public subnets
resource "aws_subnet" "public" {
count = "${data.aws_availability_zones.available.names.count}"
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_cidr[count.index]}"
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.default"]
tags {
Name = "public-${count.index}"
group = "mage-sub"
}
}
# Routing table and association
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}"
}
}
resource "aws_route_table_association" "public" {
count = "${data.aws_availability_zones.available.names.count}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
route_table_id = "${aws_route_table.public.id}"
}