-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
109 lines (87 loc) · 2.32 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# VPC config
resource "aws_vpc" "etl_vpc" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
tags = {
Name = "etl-vpc"
}
}
resource "aws_internet_gateway" "etl_igw" {
vpc_id = aws_vpc.etl_vpc.id
tags = {
Name = "etl-igw"
}
}
data "aws_security_group" "etl_default_sg" {
vpc_id = aws_vpc.etl_vpc.id
name = "default"
}
# Subnets
data "aws_availability_zones" "available" {
state = "available"
}
resource "aws_subnet" "etl_public_a" {
vpc_id = aws_vpc.etl_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "etl-public-a"
}
}
resource "aws_subnet" "etl_private_a" {
vpc_id = aws_vpc.etl_vpc.id
cidr_block = "10.0.3.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "etl-private-a"
}
}
resource "aws_subnet" "etl_private_b" {
vpc_id = aws_vpc.etl_vpc.id
cidr_block = "10.0.4.0/24"
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "etl-private-b"
}
}
# NAT
resource "aws_eip" "etl_nat_gw" {
vpc = true
}
resource "aws_nat_gateway" "etl_nat_gw" {
allocation_id = aws_eip.etl_nat_gw.id
subnet_id = aws_subnet.etl_public_a.id
}
# VPC Route tables
resource "aws_route_table" "etl_private_route_table" {
vpc_id = aws_vpc.etl_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.etl_nat_gw.id
}
tags = {
Name = "etl-private-route-table"
}
}
resource "aws_route_table_association" "etl_private_subnet_a_route_table" {
subnet_id = aws_subnet.etl_private_a.id
route_table_id = aws_route_table.etl_private_route_table.id
}
resource "aws_route_table_association" "etl_private_subnet_b_route_table" {
subnet_id = aws_subnet.etl_private_b.id
route_table_id = aws_route_table.etl_private_route_table.id
}
resource "aws_route_table" "etl_public_route_table" {
vpc_id = aws_vpc.etl_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.etl_igw.id
}
tags = {
Name = "etl-public-route-table"
}
}
resource "aws_route_table_association" "etl_public_subnet_a_route_table" {
subnet_id = aws_subnet.etl_public_a.id
route_table_id = aws_route_table.etl_public_route_table.id
}