-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
49 lines (40 loc) · 1.36 KB
/
main.tf
File metadata and controls
49 lines (40 loc) · 1.36 KB
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
# Subnet
resource "aws_subnet" "private" {
vpc_id = "${var.vpc_id}"
cidr_block = "${element(var.cidrs, count.index)}"
availability_zone = "${element(var.azs, count.index)}"
count = "${length(var.cidrs)}"
map_public_ip_on_launch = "false"
tags = "${merge(var.tags, map("Name", format("%s.%s", var.name, element(var.azs, count.index))))}"
}
# Routes
resource "aws_route_table" "private" {
vpc_id = "${var.vpc_id}"
count = "${length(var.cidrs)}"
tags = "${merge(var.tags, map("Name", format("%s.%s", var.name, element(var.azs, count.index))))}"
}
resource "aws_route_table_association" "private" {
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
count = "${length(var.cidrs)}"
}
resource "aws_route" "nat_gateway" {
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = "${element(var.nat_gateway_ids, count.index)}"
count = "${length(var.cidrs)}"
depends_on = [
"aws_route_table.private"
]
}
# Output
output "subnet_ids" {
value = [
"${aws_subnet.private.*.id}"
]
}
output "private_route_table_ids" {
value = [
"${aws_route_table.private.*.id}"
]
}