-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.tf
67 lines (51 loc) · 1.92 KB
/
db.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
locals {
private_subnet_ids = [element(split("/", element(module.eh_vpc.private_subnet_arns ,0)),1), element(split("/", element(module.eh_vpc.private_subnet_arns ,1)),1), element(split("/", element(module.eh_vpc.private_subnet_arns ,2)),1) ]
public_subnet_ids = [element(split("/", element(module.eh_vpc.public_subnet_arns ,0)),1), element(split("/", element(module.eh_vpc.public_subnet_arns ,1)),1), element(split("/", element(module.eh_vpc.public_subnet_arns ,2)),1) ]
}
resource "aws_security_group" "eh_db_sg" {
name = "rds-${var.db_name}"
description = "rds sg for ${var.owner}"
vpc_id = module.eh_vpc.vpc_id
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = flatten([module.eh_vpc.private_subnets_cidr_blocks])
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
module "eh_db" {
create_db_instance = var.db_create
create_db_option_group = var.db_create
create_db_parameter_group = var.db_create
create_db_subnet_group = var.db_create
source = "terraform-aws-modules/rds/aws"
version = "~> 2.0"
identifier = "mysql-${var.db_instance_name}"
engine = "mysql"
engine_version = "8.0.16"
family = "mysql8.0"
major_engine_version = "8.0"
instance_class = var.db_instance_type
allocated_storage = 10
storage_encrypted = false
multi_az = false
apply_immediately = true
ca_cert_identifier = "rds-ca-2019"
name = var.db_name
username = var.db_user
password = var.db_password
port = "3306"
vpc_security_group_ids = [aws_security_group.eh_db_sg.id, module.eh_vpc.default_security_group_id ]
maintenance_window = "Sat:00:00-Sat:03:00"
backup_window = "03:00-06:00"
backup_retention_period = 30
subnet_ids = local.private_subnet_ids
final_snapshot_identifier = "mysql-${var.db_instance_name}"
tags = local.tags
}