-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpc.tf
More file actions
110 lines (83 loc) · 2.32 KB
/
Copy pathvpc.tf
File metadata and controls
110 lines (83 loc) · 2.32 KB
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
#1 CREATE A VPC
resource "aws_vpc" "template" {
cidr_block = "10.${var.quad}.0.0/16"
tags = {
Name = "${var.application}-${var.environment}"
}
}
#2 CREATE A GATEWAY TO THE INTERNET
resource "aws_internet_gateway" "template" {
vpc_id = aws_vpc.template.id
}
# 6 SECURITY GROUP TO ALLOW INTERNET TRAFFIC
resource "aws_security_group" "template_allow_web" {
name = "allow_web_traffic"
description = "Allow web inbound traffic"
vpc_id = aws_vpc.template.id
ingress {
description = "HTTPS"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "SSH from VPC"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.application}-${var.environment}-allow-web"
}
}
#7 CREATE A NETWORK INTERFACE - to create private ip adddress
resource "aws_network_interface" "template_web_server" {
subnet_id = aws_subnet.template_pub_sub_1.id
private_ips = ["10.${var.quad}.1.50"]
security_groups = [aws_security_group.template_allow_web.id]
}
resource "aws_eip" "template" {
vpc = true
}
resource "aws_nat_gateway" "template" {
allocation_id = aws_eip.template.id
subnet_id = aws_subnet.template_pub_sub_1.id
depends_on = [aws_internet_gateway.template]
}
resource "aws_route_table" "template_private" {
vpc_id = aws_vpc.template.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.template.id
}
tags = {
Name = var.application
}
}
resource "aws_route_table_association" "template_private_1" {
subnet_id = aws_subnet.template_private_sub_1.id
route_table_id = aws_route_table.template_private.id
}
resource "aws_route_table_association" "template_private_sub_2" {
subnet_id = aws_subnet.template_private_sub_2.id
route_table_id = aws_route_table.template_private.id
}
resource "aws_route_table_association" "template_private_sub_3" {
subnet_id = aws_subnet.template_private_sub_3.id
route_table_id = aws_route_table.template_private.id
}