This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
127 lines (102 loc) · 2.64 KB
/
main.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
121
122
123
124
125
126
127
provider "aws" {
region = "ap-southeast-2"
profile = "event-calendar"
}
// For RDS DB
variable "db_username" {}
variable "db_password" {}
resource "aws_db_instance" "event-calendar-db" {
allocated_storage = 20
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7"
instance_class = "db.t2.micro"
username = var.db_username
password = var.db_password
parameter_group_name = "default.mysql5.7"
skip_final_snapshot = true
vpc_security_group_ids = [aws_security_group.rds_sg.id]
}
resource "aws_security_group" "express_sg" {
name = "express_sg"
egress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "rds_sg" {
name = "rds_sg"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
security_groups = [aws_security_group.express_sg.id, aws_security_group.ec2_sg.id]
}
depends_on = [aws_security_group.express_sg, aws_security_group.ec2_sg]
}
// For CRON Job
resource "aws_instance" "cron-job" {
ami = "ami-00f3471feb1f3897e" // Default AMI from AWS
instance_type = "t2.micro"
key_name = "event-calendar"
vpc_security_group_ids = [aws_security_group.ec2_sg.id]
tags = {
Name = "cron-job"
}
}
resource "aws_security_group" "ec2_sg" {
description = "Allow inbound SSH traffic"
tags = {
Name = "ec2_sg"
}
ingress {
description = "SSH from anywhere"
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"]
}
}
// For React EC2 instance
resource "aws_instance" "react-app" {
ami = "ami-00f3471feb1f3897e" // Default AMI from AWS
instance_type = "t2.micro" # Hopefully builds my react app in under 5 minutes (!!)
key_name = "event-calendar"
vpc_security_group_ids = [aws_security_group.ec2_sg.id, aws_security_group.react_ec2_public_access.id]
tags = {
Name = "react-app"
}
}
resource "aws_security_group" "react_ec2_public_access" {
description = "Allows inbound HTTP traffic to the express proxy server"
tags = {
Name = "react_ec2_public_access"
}
ingress {
description = "Access express proxy server from anywhere"
from_port = 3001
to_port = 3001
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
output "react-app-public-dns" {
value = aws_instance.react-app.public_dns
}
output "cron-job-public-dns" {
value = aws_instance.cron-job.public_dns
}
output "db-endpoint" {
value = aws_db_instance.event-calendar-db.endpoint
}
output "lambda-express-sg-id" {
value = aws_security_group.ec2_sg.id
}