-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
120 lines (103 loc) · 2.75 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
110
111
112
113
114
115
116
117
118
119
120
# ==============================================================================
# VPC
# ==============================================================================
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = var.vpc_enable_dns_hostnames
tags = merge(
var.tags,
{
Name = "${var.prefix}_vpc"
}
)
}
# ==============================================================================
# SUBNETS
# ==============================================================================
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = var.public_subnet_cidr
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
tags = merge(
var.tags,
{
Name = "${var.prefix}_public_subnet"
}
)
}
resource "aws_subnet" "private" {
vpc_id = aws_vpc.main.id
cidr_block = var.private_subnet_cidr
availability_zone = "us-east-1a"
tags = merge(
var.tags,
{
Name = "${var.prefix}_private_subnet"
}
)
}
# ==============================================================================
# INTERNET GATEWAY
# ==============================================================================
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
tags = merge(
var.tags,
{
Name = "${var.prefix}_igw"
}
)
}
# ==============================================================================
# ROUTE TABLES
# ==============================================================================
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = merge(
var.tags,
{
Name = "${var.prefix}_public_route_table"
}
)
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id
tags = merge(
var.tags,
{
Name = "${var.prefix}_private_route_table"
}
)
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "private" {
subnet_id = aws_subnet.private.id
route_table_id = aws_route_table.private.id
}
# ==============================================================================
# SECURITY GROUPS
# ==============================================================================
resource "aws_security_group" "private_sg" {
vpc_id = aws_vpc.main.id
description = "${var.prefix} - Security group for private subnet"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge(
var.tags,
{
Name = "${var.prefix}_private_sg"
}
)
}