-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpc.tf
110 lines (79 loc) · 2.23 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
resource "aws_vpc" "default" {
cidr_block = var.vpc_cidr_block
enable_dns_support = true
tags = {
Name = "wp-pvc-tf"
}
}
# Internet Gateway
resource "aws_internet_gateway" "default" {
vpc_id = aws_vpc.default.id
tags = {
Name = "wp-igw-tf"
}
}
# Subnets
resource "aws_subnet" "wp-public-tf" {
count = length(var.public_subnet_cidr_block)
vpc_id = aws_vpc.default.id
cidr_block = var.public_subnet_cidr_block[count.index]
availability_zone = var.availability_zones[count.index]
tags = {
Name = "wp-public-tf"
}
}
resource "aws_subnet" "wp-private-tf" {
count = length(var.private_subnet_cidr_block)
vpc_id = aws_vpc.default.id
cidr_block = var.private_subnet_cidr_block[count.index]
availability_zone = var.availability_zones[count.index]
tags = {
Name = "wp-private-tf"
}
}
# Route Tables
resource "aws_route_table" "wp-rt-public-tf" {
count = length(aws_subnet.wp-public-tf)
vpc_id = aws_vpc.default.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.default.id
}
tags = {
Name = "wp-rt-public-tf"
}
}
resource "aws_route_table_association" "wp-public-tf" {
count = length(aws_subnet.wp-public-tf)
subnet_id = aws_subnet.wp-public-tf[count.index].id
route_table_id = aws_route_table.wp-rt-public-tf[count.index].id
}
resource "aws_eip" "eip_gateway" {
vpc = true
depends_on = [aws_internet_gateway.default]
}
resource "aws_nat_gateway" "wp-private-tf-nat" {
subnet_id = aws_subnet.wp-public-tf[0].id
allocation_id = aws_eip.eip_gateway.id
tags = {
Name = "wp-private-tf-nat"
}
depends_on = [aws_internet_gateway.default]
}
resource "aws_route_table" "wp-rt-private-tf" {
count = length(aws_subnet.wp-private-tf)
vpc_id = aws_vpc.default.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.wp-private-tf-nat.id
}
tags = {
Name = "wp-rt-private-tf"
}
}
resource "aws_route_table_association" "wp-rt-private-tf" {
count = length(aws_subnet.wp-private-tf)
subnet_id = aws_subnet.wp-private-tf[count.index].id
route_table_id = aws_route_table.wp-rt-private-tf[count.index].id
}