forked from terraform-community-modules/tf_aws_vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
52 lines (44 loc) · 1.54 KB
/
main.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
resource "aws_vpc" "mod" {
cidr_block = "${var.cidr}"
tags { Name = "${var.name}" }
}
resource "aws_internet_gateway" "mod" {
vpc_id = "${aws_vpc.mod.id}"
}
resource "aws_route_table" "public" {
vpc_id = "${aws_vpc.mod.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.mod.id}"
}
tags { Name = "${var.name}-public" }
}
resource "aws_route_table" "private" {
vpc_id = "${aws_vpc.mod.id}"
tags { Name = "${var.name}-private" }
}
resource "aws_subnet" "private" {
vpc_id = "${aws_vpc.mod.id}"
cidr_block = "${element(split(",", var.private_subnets), count.index)}"
availability_zone = "${element(split(",", var.azs), count.index)}"
count = "${length(split(",", var.private_subnets))}"
tags { Name = "${var.name}-private" }
}
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.mod.id}"
cidr_block = "${element(split(",", var.public_subnets), count.index)}"
availability_zone = "${element(split(",", var.azs), count.index)}"
count = "${length(split(",", var.public_subnets))}"
tags { Name = "${var.name}-public" }
map_public_ip_on_launch = true
}
resource "aws_route_table_association" "private" {
count = "${length(split(",", var.private_subnets))}"
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
route_table_id = "${aws_route_table.private.id}"
}
resource "aws_route_table_association" "public" {
count = "${length(split(",", var.private_subnets))}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
route_table_id = "${aws_route_table.public.id}"
}