generated from michaeldeggers/repo_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrds.tf
72 lines (61 loc) · 1.92 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
locals {
timestamp = timestamp()
timestamp_sanitized = replace("${local.timestamp}", "/[- TZ:]/", "")
}
resource "aws_db_instance" "default" {
allocated_storage = 20
storage_type = "gp2"
engine = "mysql"
engine_version = var.mysql_engine_version
instance_class = var.mysql_instance_class
db_name = var.mysql_name
username = var.mysql_username
password = random_password.mysql_password.result
parameter_group_name = aws_db_parameter_group.default.name
db_subnet_group_name = aws_db_subnet_group.default.name
vpc_security_group_ids = [aws_security_group.mysql_sg.id]
skip_final_snapshot = true
# final_snapshot_identifier = "${var.mysql_name}-${local.timestamp_sanitized}"
timeouts {
create = "60m"
delete = "2h"
}
}
resource "aws_db_parameter_group" "default" {
name = "${local.name_prefix}-pg"
family = "mysql5.7"
}
resource "random_password" "mysql_password" {
length = 16
special = true
override_special = "!#$%&*()-_=+[]{}<>:?"
}
resource "aws_db_subnet_group" "default" {
name = "${local.name_prefix}-main"
subnet_ids = [module.vpc.database_subnets[0], module.vpc.database_subnets[1]]
tags = merge(var.additional_tags,
{
"Name" = "${local.name_prefix}-mysql-subnet-group"
})
}
resource "aws_security_group" "mysql_sg" {
name = "${local.name_prefix}-mysql_sg"
description = "mysql_sg"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 3306
to_port = 3306
protocol = "TCP"
security_groups = [aws_security_group.ghost_asg_sg.id]
}
egress {
from_port = 3306
to_port = 3306
protocol = "TCP"
security_groups = [aws_security_group.ghost_asg_sg.id]
}
tags = merge(var.additional_tags,
{
"Name" = "${local.name_prefix}-mysql-subnet-group"
})
}