-
Notifications
You must be signed in to change notification settings - Fork 0
/
infrastructure.tf
78 lines (67 loc) · 1.97 KB
/
infrastructure.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
provider "aws" {
region = "eu-west-2"
}
resource "aws_security_group" "web_sg" {
name = "web-sg"
description = "Allow inbound traffic on port 80 and 22"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
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"]
}
}
resource "aws_instance" "fastapi_instance" {
ami = "ami-04b9e92b5572fa0d3" # Replace with the AMI ID for your region
instance_type = "t2.micro" # Change based on your needs
key_name = "your-key-pair" # Replace with your EC2 key pair name
security_groups = [aws_security_group.web_sg.name]
tags = {
Name = "FastAPIWeatherService"
}
user_data = <<-EOF
#!/bin/bash
sudo apt-get update
sudo apt-get install -y python3-pip
sudo pip3 install fastapi uvicorn
# Add commands to clone the repository and start the service
git clone https://github.com/Parissai/fastapi-weather-service.git
cd fastapi-weather-service
pip3 install -r requirements.txt
nohup uvicorn app.main:app --host 0.0.0.0 --port 80 --reload &
EOF
}
output "instance_ip" {
value = aws_instance.fastapi_instance.public_ip
}
resource "aws_db_instance" "mydb" {
allocated_storage = 20
storage_type = "gp2"
engine = "postgres"
engine_version = "13.2"
instance_class = "db.t2.micro"
db_name = "weatherdb"
username = "admin"
password = "password"
parameter_group_name = "default.postgres13"
skip_final_snapshot = true
publicly_accessible = true
tags = {
Name = "MyDatabase"
}
}
output "db_endpoint" {
value = aws_db_instance.mydb.endpoint
}