-
Notifications
You must be signed in to change notification settings - Fork 1
/
rds.tf
94 lines (78 loc) · 2.86 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# ---------------------------------------------
# RDS parameter group
# ---------------------------------------------
resource "aws_db_parameter_group" "mysql_standalone_parametergroup" {
name = "${var.project}-${var.environment}-mysql-standalone-parametergroup"
family = "${var.db_engine}${var.db_version}"
parameter {
name = "character_set_database"
value = "utf8mb4"
}
parameter {
name = "character_set_server"
value = "utf8mb4"
}
}
# ---------------------------------------------
# RDS option group
# ---------------------------------------------
resource "aws_db_option_group" "mysql_standalone_optiongroup" {
name = "${var.project}-${var.environment}-mysql-standalone-optiongroup"
engine_name = var.db_engine
major_engine_version = var.db_version
}
# ---------------------------------------------
# RDS subnet group
# ---------------------------------------------
resource "aws_db_subnet_group" "mysql_standalone_subnetgroup" {
name = "${var.project}-${var.environment}-mysql-standalone-subnetgroup"
subnet_ids = [
aws_subnet.private_subnet_1a.id,
aws_subnet.private_subnet_1c.id
]
tags = {
Name = "${var.project}-${var.environment}-mysql-standalone-subnetgroup"
Project = var.project
Env = var.environment
}
}
# ---------------------------------------------
# RDS instance
# ---------------------------------------------
resource "random_string" "db_password" {
length = 16
special = false
}
resource "aws_db_instance" "mysql_standalone" {
engine = var.db_engine
engine_version = var.db_full_version
identifier = "${var.project}-${var.environment}-mysql-standalone"
username = var.db_username
password = random_string.db_password.result
instance_class = var.db_instance_type
allocated_storage = 20
max_allocated_storage = 50
storage_type = "gp2"
storage_encrypted = false
multi_az = false
availability_zone = "ap-northeast-1a"
db_subnet_group_name = aws_db_subnet_group.mysql_standalone_subnetgroup.name
vpc_security_group_ids = [aws_security_group.db_sg.id]
publicly_accessible = false
port = var.db_port
db_name = var.db_name
parameter_group_name = aws_db_parameter_group.mysql_standalone_parametergroup.name
option_group_name = aws_db_option_group.mysql_standalone_optiongroup.name
backup_window = "04:00-05:00"
backup_retention_period = 7
maintenance_window = "Mon:05:00-Mon:08:00"
auto_minor_version_upgrade = false
deletion_protection = false
skip_final_snapshot = true
apply_immediately = true
tags = {
Name = "${var.project}-${var.environment}-mysql-standalone"
Project = var.project
Env = var.environment
}
}