-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
86 lines (70 loc) · 2.17 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
82
83
84
85
86
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "Prometheus VPC"
}
}
resource "aws_internet_gateway" "internet_gateway" {
vpc_id = aws_vpc.vpc.id
}
resource "aws_subnet" "pub_subnet-1" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.0.0.0/24"
availability_zone = "${var.aws_region}b"
}
resource "aws_subnet" "pub_subnet-2" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "${var.aws_region}c"
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
}
}
resource "aws_route_table_association" "route_table_association-1" {
subnet_id = aws_subnet.pub_subnet-1.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "route_table_association-2" {
subnet_id = aws_subnet.pub_subnet-2.id
route_table_id = aws_route_table.public.id
}
# private
resource "aws_subnet" "priv-subnet-1" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.0.10.0/24"
availability_zone = "${var.aws_region}b"
}
resource "aws_subnet" "priv-subnet-2" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.0.11.0/24"
availability_zone = "${var.aws_region}c"
}
resource "aws_eip" "nat_eip" {
vpc = true
}
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat_eip.id
subnet_id = aws_subnet.pub_subnet-1.id
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.vpc.id
}
resource "aws_route" "private_nat_gateway" {
route_table_id = aws_route_table.private.id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat.id
}
resource "aws_route_table_association" "priv-subnet-1" {
subnet_id = aws_subnet.priv-subnet-1.id
route_table_id = aws_route_table.private.id
}
resource "aws_route_table_association" "priv-subnet-2" {
subnet_id = aws_subnet.priv-subnet-2.id
route_table_id = aws_route_table.private.id
}