-
Notifications
You must be signed in to change notification settings - Fork 0
/
rds.tf
48 lines (43 loc) · 1.48 KB
/
rds.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
locals {
db_type = "db.t3.micro"
db_engine = "mysql"
db_storage_size = 20
db_username = "root"
db_public_accessible = false
}
resource "aws_security_group" "rds_sg" {
name = "SnapVibe-rds-sg"
description = "RDS sg only port 3306"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_db_subnet_group" "SnapVibe_subnet_group" {
name = "snapvibe-subnet-group"
subnet_ids = tolist(module.vpc.private_subnet_ids)
}
resource "aws_db_instance" "SnapVibe-rds" {
identifier = "snapvibe-rds"
allocated_storage = local.db_storage_size
engine = local.db_engine
instance_class = local.db_type
db_subnet_group_name = aws_db_subnet_group.SnapVibe_subnet_group.name
availability_zone = "${data.aws_region.current.name}a"
username = local.db_username
password = var.rds_root_password
vpc_security_group_ids = [aws_security_group.rds_sg.id]
publicly_accessible = local.db_public_accessible
apply_immediately = true
backup_retention_period = 7
}
resource "aws_db_instance" "SnapVibe-rds-read-replica" {
identifier = "snapvibe-rds-replica"
instance_class = local.db_type
replicate_source_db = aws_db_instance.SnapVibe-rds.identifier
apply_immediately = true
backup_retention_period = 7
}