1
1
# Create a custom VPC
2
2
resource "aws_vpc" "my_vpc" {
3
- cidr_block = " 10.0.0.0/16"
3
+ cidr_block = " 10.10.0.0/16"
4
+ enable_dns_support = " true"
5
+ enable_dns_hostnames = " true"
4
6
}
5
7
6
8
# Create Internet Gateway
@@ -21,14 +23,14 @@ resource "aws_route_table" "my_route_table" {
21
23
# Create Subnets
22
24
resource "aws_subnet" "my_subnet1" {
23
25
vpc_id = aws_vpc. my_vpc . id
24
- cidr_block = " 10.0.0 .0/24"
26
+ cidr_block = " 10.10.1 .0/24"
25
27
map_public_ip_on_launch = " true"
26
28
availability_zone = " us-east-1a"
27
29
}
28
30
29
31
resource "aws_subnet" "my_subnet2" {
30
32
vpc_id = aws_vpc. my_vpc . id
31
- cidr_block = " 10.0.1 .0/24"
33
+ cidr_block = " 10.10.2 .0/24"
32
34
map_public_ip_on_launch = " true"
33
35
availability_zone = " us-east-1b"
34
36
}
@@ -43,27 +45,12 @@ resource "aws_route_table_association" "table_association2" {
43
45
route_table_id = aws_route_table. my_route_table . id
44
46
}
45
47
46
-
47
48
# Create Security Group to allow port 80
48
49
resource "aws_security_group" "allow_web" {
49
50
name = " allow_web_traffic"
50
51
description = " Allow Web inbound traffic"
51
52
vpc_id = aws_vpc. my_vpc . id
52
53
53
- ingress {
54
- description = " HTTP"
55
- from_port = 80
56
- to_port = 80
57
- protocol = " tcp"
58
- cidr_blocks = [" 0.0.0.0/0" ]
59
- }
60
- ingress {
61
- description = " SSH"
62
- from_port = 22
63
- to_port = 22
64
- protocol = " tcp"
65
- cidr_blocks = [" 0.0.0.0/0" ]
66
- }
67
54
ingress {
68
55
from_port = 3306
69
56
to_port = 3306
@@ -92,11 +79,11 @@ resource "aws_network_acl" "bar" {
92
79
resource "aws_network_acl_rule" "bar" {
93
80
network_acl_id = aws_network_acl. bar . id
94
81
rule_number = 100
95
- protocol = " tcp "
82
+ protocol = - 1
96
83
rule_action = " deny"
97
84
cidr_block = " 50.31.252.0/24"
98
- from_port = 80
99
- to_port = 80
85
+ from_port = 0
86
+ to_port = 0
100
87
}
101
88
102
89
# Add DB subnet group
@@ -110,16 +97,19 @@ variable "MYSQL_PWD" {}
110
97
111
98
# Create RDS Instance
112
99
resource "aws_db_instance" "my_instance" {
113
- allocated_storage = 10
100
+ identifier = " mysqldb "
114
101
db_name = " dbtest"
115
102
engine = " mysql"
116
103
engine_version = " 5.7"
117
104
instance_class = " db.t2.micro"
118
105
username = " testuser"
119
106
password = var. MYSQL_PWD
120
107
port = " 3306"
108
+ storage_type = " gp2"
109
+ allocated_storage = 20
121
110
vpc_security_group_ids = [aws_security_group . allow_web . id ]
122
111
db_subnet_group_name = aws_db_subnet_group. db_sg . id
123
112
parameter_group_name = " default.mysql5.7"
124
113
skip_final_snapshot = true
114
+ publicly_accessible = true
125
115
}
0 commit comments