-
Notifications
You must be signed in to change notification settings - Fork 6
/
vpc.tf
executable file
·81 lines (64 loc) · 1.74 KB
/
vpc.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
76
77
78
79
80
81
## VPC + Subnets + IGW
resource "aws_vpc" "main" {
cidr_block = "${var.cidr_prefix}.0.0/16"
enable_dns_support = "true"
enable_dns_hostnames = "true"
tags {
Name = "${var.cidr_prefix}-vpc"
}
}
resource "aws_subnet" "pub_a" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "${var.cidr_prefix}.1.0/24"
availability_zone = "${var.aws_region}a"
map_public_ip_on_launch = "true"
tags {
Name = "${var.cidr_prefix}.1-pub-a"
}
}
resource "aws_subnet" "pub_b" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "${var.cidr_prefix}.2.0/24"
availability_zone = "${var.aws_region}b"
map_public_ip_on_launch = "true"
tags {
Name = "${var.cidr_prefix}.2-pub-b"
}
}
resource "aws_subnet" "priv_a" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "${var.cidr_prefix}.3.0/24"
availability_zone = "${var.aws_region}a"
tags {
Name = "${var.cidr_prefix}.3-priv-a"
}
}
resource "aws_subnet" "priv_b" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "${var.cidr_prefix}.4.0/24"
availability_zone = "${var.aws_region}b"
tags {
Name = "${var.cidr_prefix}.4-priv-b"
}
}
resource "aws_internet_gateway" "igw" {
vpc_id = "${aws_vpc.main.id}"
}
resource "aws_route_table" "pub" {
vpc_id = "${aws_vpc.main.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.igw.id}"
}
tags {
Name = "${var.SERVICE_NAME}-publicRT"
}
}
resource "aws_route_table_association" "pub_a" {
subnet_id = "${aws_subnet.pub_a.id}"
route_table_id = "${aws_route_table.pub.id}"
}
resource "aws_route_table_association" "pub_b" {
subnet_id = "${aws_subnet.pub_b.id}"
route_table_id = "${aws_route_table.pub.id}"
}