Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(backend): fix iac for the database #104

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 58 additions & 20 deletions apps/backend/_infra/prod/storage/database.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,51 @@ data "doppler_secrets" "prod" {
}

resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}

resource "aws_subnet" "public" {
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
}

resource "aws_route_table" "main" {
vpc_id = aws_vpc.main.id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
}

resource "aws_subnet" "rds_subnet0" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "${var.aws_region}a"
map_public_ip_on_launch = true
}

resource "aws_subnet" "rds_subnet1" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.2.0/24"
availability_zone = "${var.aws_region}b"
map_public_ip_on_launch = true
}

resource "aws_route_table_association" "subnet0_association" {
subnet_id = aws_subnet.rds_subnet0.id
route_table_id = aws_route_table.main.id
}

resource "aws_route_table_association" "subnet1_association" {
subnet_id = aws_subnet.rds_subnet1.id
route_table_id = aws_route_table.main.id
}

resource "aws_db_subnet_group" "default" {
name = "snipcode-prod-subnet-group"
subnet_ids = [aws_subnet.public.id]
subnet_ids = [aws_subnet.rds_subnet0.id, aws_subnet.rds_subnet1.id]

tags = {
Name = "Snipcode Prod subnet group"
Expand Down Expand Up @@ -52,25 +84,31 @@ resource "aws_security_group" "rds_sg" {
}

resource "aws_db_instance" "database" {
identifier = "${var.project_name}-backend-${var.environment}"
allocated_storage = 20
engine = "mysql"
engine_version = "8.0.39"
instance_class = "db.t3.micro"
db_name = data.doppler_secrets.prod.map.DATABASE_NAME
username = data.doppler_secrets.prod.map.ADMIN_USER
password = data.doppler_secrets.prod.map.ADMIN_PASSWORD
db_subnet_group_name = aws_db_subnet_group.default.name
vpc_security_group_ids = [aws_security_group.rds_sg.id]
multi_az = false
publicly_accessible = true
performance_insights_enabled = true
performance_insights_retention_period = 7 ## 7 days to stay in the free tier
skip_final_snapshot = true
allow_major_version_upgrade = false
auto_minor_version_upgrade = true
identifier = "${var.project_name}-backend-${var.environment}"
allocated_storage = 20
engine = "mysql"
engine_version = "8.0.39"
instance_class = "db.t3.micro"
db_name = data.doppler_secrets.prod.map.DATABASE_NAME
username = data.doppler_secrets.prod.map.ADMIN_USER
password = data.doppler_secrets.prod.map.ADMIN_PASSWORD
port = data.doppler_secrets.prod.map.PORT
db_subnet_group_name = aws_db_subnet_group.default.name
vpc_security_group_ids = [aws_security_group.rds_sg.id]
multi_az = false
publicly_accessible = true
skip_final_snapshot = true
allow_major_version_upgrade = false
auto_minor_version_upgrade = true
# performance_insights_enabled = true
# performance_insights_retention_period = 7

lifecycle {
prevent_destroy = true
}

tags = {
Name = "Snipcode Prod RDS Instance"
}
}

Loading