forked from smartobi/terraform-fargate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1vpc.tf
102 lines (82 loc) · 2.95 KB
/
1vpc.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
## ========================
## Creating AWS VPC section
## ========================
resource "aws_vpc" "vpc" {
cidr_block = var.cidr_block
instance_tenancy = "default"
tags = {
Name = var.tag
}
}
## =====================================
## Creating AWS internet gateway section
## =====================================
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpc.id
}
## ==================================
## Creating AWS Public subnet section
## ==================================
resource "aws_subnet" "public" {
vpc_id = aws_vpc.vpc.id
cidr_block = element(var.public_subnets, count.index)
availability_zone = element(var.availability_zones, count.index)
count = length(var.public_subnets)
map_public_ip_on_launch = true
}
## ===================================
## Creating AWS Private subnet section
## ===================================
resource "aws_subnet" "private" {
vpc_id = aws_vpc.vpc.id
cidr_block = element(var.private_subnets, count.index)
availability_zone = element(var.availability_zones, count.index)
count = length(var.private_subnets)
}
## ================================
## Creating AWS route table section
## ================================
resource "aws_route_table" "public" {
vpc_id = aws_vpc.vpc.id
}
resource "aws_route" "public" {
route_table_id = aws_route_table.public.id
destination_cidr_block = var.all_cidr
gateway_id = aws_internet_gateway.igw.id
}
resource "aws_route_table_association" "public" {
count = length(var.public_subnets)
subnet_id = element(aws_subnet.public.*.id, count.index)
route_table_id = aws_route_table.public.id
}
## =============================================
## Creating AWS Nat gateway and EasticIP section
## =============================================
resource "aws_nat_gateway" "nat" {
count = length(var.private_subnets)
allocation_id = element(aws_eip.nat.*.id, count.index)
subnet_id = element(aws_subnet.public.*.id, count.index)
depends_on = [aws_internet_gateway.igw]
}
resource "aws_eip" "nat" {
count = length(var.private_subnets)
vpc = true
}
## ========================================
## Creating AWS private route table section
## ========================================
resource "aws_route_table" "private" {
count = length(var.private_subnets)
vpc_id = aws_vpc.vpc.id
}
resource "aws_route" "private" {
count = length(compact(var.private_subnets))
route_table_id = element(aws_route_table.private.*.id, count.index)
destination_cidr_block = var.all_cidr
nat_gateway_id = element(aws_nat_gateway.nat.*.id, count.index)
}
resource "aws_route_table_association" "private" {
count = length(var.private_subnets)
subnet_id = element(aws_subnet.private.*.id, count.index)
route_table_id = element(aws_route_table.private.*.id, count.index)
}