-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
75 lines (59 loc) · 2.18 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
## Resources
resource "aws_vpc" "ec2_vpc" {
cidr_block = "${var.vpc_cidr_block}"
tags {
Name = "${var.vpc_name}"
}
}
resource "aws_internet_gateway" "ec2_igw" {
vpc_id = "${aws_vpc.ec2_vpc.id}"
tags {
Name = "${var.vpc_name}-IGW"
}
}
### Configure your subnets yo.
resource "aws_subnet" "ec2_private_subnet" {
vpc_id = "${aws_vpc.ec2_vpc.id}"
cidr_block = "${var.private_subnets[count.index]}"
availability_zone = "${var.avail_zones[count.index]}"
map_public_ip_on_launch = false
count = "${length(var.private_subnets)}"
tags {
Name = "${var.vpc_name}-private-${element(var.avail_zones, count.index)}"
}
}
resource "aws_subnet" "ec2_public_subnet" {
vpc_id = "${aws_vpc.ec2_vpc.id}"
cidr_block = "${var.public_subnets[count.index]}"
availability_zone = "${var.avail_zones[count.index]}"
map_public_ip_on_launch = true
count = "${length(var.public_subnets)}"
tags {
Name = "${var.vpc_name}-public-${element(var.avail_zones, count.index)}"
}
}
## Make a routing table? How about two? Why not associate it?
resource "aws_route_table" "ec2_private_route_table" {
count = "${length(var.private_subnets)}"
vpc_id = "${aws_vpc.ec2_vpc.id}"
tags {
Name = "${var.vpc_name}-${element(var.private_subnets, count.index)}-priv-RT"
}
}
resource "aws_route_table_association" "ec2_private_route_table_assn" {
count = "${length(var.private_subnets)}"
subnet_id = "${element(aws_subnet.ec2_private_subnet.*.id, count.index)}"
route_table_id = "${element(aws_route_table.ec2_private_route_table.*.id, count.index)}"
}
resource "aws_route_table" "ec2_public_route_table" {
count = "${length(var.public_subnets)}"
vpc_id = "${aws_vpc.ec2_vpc.id}"
tags {
Name = "${var.vpc_name}-${element(var.public_subnets, count.index)}-pub-RT"
}
}
resource "aws_route_table_association" "ec2_public_route_table_assn" {
count = "${length(var.public_subnets)}"
subnet_id = "${element(aws_subnet.ec2_public_subnet.*.id, count.index)}"
route_table_id = "${element(aws_route_table.ec2_public_route_table.*.id, count.index)}"
}