-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
44 lines (34 loc) · 1.06 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
resource "aws_vpc" "vpc" {
cidr_block = "${var.cidr_block}"
enable_dns_hostnames = true
enable_dns_support = true
tags {
Name = "${var.name}"
}
}
resource "aws_internet_gateway" "gateway" {
vpc_id = "${aws_vpc.vpc.id}"
}
data "aws_availability_zones" "available" {}
resource "aws_subnet" "subnet" {
count = "${var.subnets}"
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
cidr_block = "${cidrsubnet(aws_vpc.vpc.cidr_block, var.subnets, count.index)}"
vpc_id = "${aws_vpc.vpc.id}"
map_public_ip_on_launch = true
}
resource "aws_route_table" "table" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gateway.id}"
}
}
resource "aws_route_table" "routing_table" {
vpc_id = "${aws_vpc.vpc.id}"
}
resource "aws_route_table_association" "association" {
count = "${aws_subnet.subnet.count}"
route_table_id = "${aws_route_table.table.id}"
subnet_id = "${element(aws_subnet.subnet.*.id, count.index)}"
}