-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
135 lines (119 loc) · 3.7 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
resource "aws_vpc" "this" {
assign_generated_ipv6_cidr_block = false
cidr_block = var.vpc.cidr
enable_classiclink = false
enable_classiclink_dns_support = false
enable_dns_hostnames = true
enable_dns_support = true
instance_tenancy = "default"
tags = {
Name = var.vpc.name
}
}
resource "aws_internet_gateway" "this" {
vpc_id = aws_vpc.this.id
tags = {
Name = var.vpc.ig_name
}
}
data "aws_region" "current" {
#provider = "aws.region"
}
resource "aws_vpc_endpoint" "this" {
vpc_id = aws_vpc.this.id
service_name = format("com.amazonaws.%s.s3", data.aws_region.current.name)
tags = {
Name = var.vpc.s3_endpoint_name
}
}
resource "aws_subnet" "public_subnet" {
count = length(var.vpc.azs)
cidr_block = var.vpc.azs[count.index].public_subnet.cidr
vpc_id = aws_vpc.this.id
map_public_ip_on_launch = true
availability_zone = var.vpc.azs[count.index].az
tags = {
Name = var.vpc.azs[count.index].public_subnet.name
}
}
resource "aws_subnet" "private_subnet" {
count = length(var.vpc.azs)
cidr_block = var.vpc.azs[count.index].private_subnet.cidr
vpc_id = aws_vpc.this.id
map_public_ip_on_launch = false
availability_zone = var.vpc.azs[count.index].az
tags = {
Name = var.vpc.azs[count.index].private_subnet.name
}
}
resource "aws_eip" "public_subnet_nat_eip" {
count = length(var.vpc.azs)
vpc = true
tags = {
Name = var.vpc.azs[count.index].public_subnet.nat_eip_name
}
}
resource "aws_nat_gateway" "public_subnet_nat" {
count = length(var.vpc.azs)
subnet_id = aws_subnet.public_subnet[count.index].id
allocation_id = aws_eip.public_subnet_nat_eip[count.index].id
#depends_on = [aws_internet_gateway.this[count.]
tags = {
Name = var.vpc.azs[count.index].public_subnet.nat_name
}
}
resource "aws_route_table" "public_subnet_route_table" {
vpc_id = aws_vpc.this.id
route = [
{
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.this.id
nat_gateway_id = ""
ipv6_cidr_block = ""
egress_only_gateway_id = ""
instance_id = ""
network_interface_id = ""
transit_gateway_id = ""
vpc_peering_connection_id = ""
},
]
tags = {
Name = var.vpc.public_subnets_routetable_name
}
}
resource "aws_route_table" "private_subnet_route_table" {
count = length(var.vpc.azs)
vpc_id = aws_vpc.this.id
route = [
{
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.public_subnet_nat[count.index].id
gateway_id = ""
ipv6_cidr_block = ""
egress_only_gateway_id = ""
instance_id = ""
network_interface_id = ""
transit_gateway_id = ""
vpc_peering_connection_id = ""
},
]
tags = {
Name = var.vpc.azs[count.index].private_subnet.routetable_name
}
}
resource "aws_route_table_association" "public_route_table_public_subnet_association" {
count = length(var.vpc.azs)
subnet_id = aws_subnet.public_subnet[count.index].id
route_table_id = aws_route_table.public_subnet_route_table.id
}
resource "aws_route_table_association" "private_route_table_private_subnet_association" {
count = length(var.vpc.azs)
subnet_id = aws_subnet.private_subnet[count.index].id
route_table_id = aws_route_table.private_subnet_route_table[count.index].id
}
resource "aws_default_route_table" "this" {
default_route_table_id = aws_vpc.this.default_route_table_id
tags = {
Name = var.vpc.default_route_table_name
}
}