-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrds.tf
166 lines (155 loc) · 4.72 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
resource "aws_db_instance" "master" {
count = module.global_variables.is_staging ? 0 : 1
identifier = "ridi-pay-${module.global_variables.env}-master"
allocated_storage = module.global_variables.is_prod ? 250 : 16
storage_type = "gp2"
engine = "mariadb"
engine_version = "10.3.8"
instance_class = module.global_variables.is_prod ? "db.t3.medium" : "db.t3.micro"
name = "ridi_pay"
username = "ridi"
password = data.aws_kms_secrets.rds.plaintext["password_${module.global_variables.env}"]
multi_az = module.global_variables.is_prod ? true : false
parameter_group_name = aws_db_parameter_group.master[0].name
option_group_name = aws_db_option_group.master[0].name
db_subnet_group_name = aws_db_subnet_group.rds[0].name
vpc_security_group_ids = [aws_security_group.rds.id]
auto_minor_version_upgrade = false
backup_retention_period = 7
ca_cert_identifier = "rds-ca-2019"
}
resource "aws_db_instance" "slave" {
count = module.global_variables.is_prod ? 1 : 0
identifier = "ridi-pay-${module.global_variables.env}-slave"
replicate_source_db = aws_db_instance.master[0].identifier
allocated_storage = module.global_variables.is_prod ? 250 : 16
storage_type = "gp2"
engine = "mariadb"
engine_version = "10.3.8"
instance_class = module.global_variables.is_prod ? "db.t3.medium" : "db.t3.micro"
name = "ridi_pay"
username = "ridi"
password = data.aws_kms_secrets.rds.plaintext["password_${module.global_variables.env}"]
parameter_group_name = aws_db_parameter_group.slave[0].name
option_group_name = aws_db_option_group.slave[0].name
vpc_security_group_ids = [aws_security_group.rds.id]
auto_minor_version_upgrade = false
backup_retention_period = 7
ca_cert_identifier = "rds-ca-2019"
}
resource "aws_db_parameter_group" "master" {
count = module.global_variables.is_staging ? 0 : 1
name = "ridi-pay-${module.global_variables.env}-master"
family = "mariadb10.3"
parameter {
name = "general_log"
value = "1"
}
parameter {
name = "slow_query_log"
value = "1"
}
parameter {
name = "long_query_time"
value = "1"
}
parameter {
name = "read_only"
value = "0"
}
parameter {
name = "collation_server"
value = "utf8_unicode_ci"
}
parameter {
name = "init_connect"
value = "SET NAMES utf8"
}
parameter {
name = "character_set_server"
value = "utf8"
}
parameter {
name = "time_zone"
value = "Asia/Seoul"
}
parameter {
name = "log_output"
value = "file"
}
}
resource "aws_db_parameter_group" "slave" {
count = module.global_variables.is_prod ? 1 : 0
name = "ridi-pay-${module.global_variables.env}-slave"
family = "mariadb10.3"
parameter {
name = "general_log"
value = "1"
}
parameter {
name = "slow_query_log"
value = "1"
}
parameter {
name = "long_query_time"
value = "1"
}
parameter {
name = "read_only"
value = "1"
}
parameter {
name = "collation_server"
value = "utf8_unicode_ci"
}
parameter {
name = "init_connect"
value = "SET NAMES utf8"
}
parameter {
name = "character_set_server"
value = "utf8"
}
parameter {
name = "time_zone"
value = "Asia/Seoul"
}
parameter {
name = "log_output"
value = "file"
}
}
resource "aws_db_option_group" "master" {
count = module.global_variables.is_staging ? 0 : 1
name = "ridi-pay-${module.global_variables.env}-master"
engine_name = "mariadb"
major_engine_version = "10.3"
option {
option_name = "MARIADB_AUDIT_PLUGIN"
option_settings {
name = "SERVER_AUDIT_EVENTS"
value = "CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL"
}
}
}
resource "aws_db_option_group" "slave" {
count = module.global_variables.is_prod ? 1 : 0
name = "ridi-pay-${module.global_variables.env}-slave"
engine_name = "mariadb"
major_engine_version = "10.3"
option {
option_name = "MARIADB_AUDIT_PLUGIN"
option_settings {
name = "SERVER_AUDIT_EVENTS"
value = "CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL"
}
}
}
resource "aws_db_subnet_group" "rds" {
count = module.global_variables.is_staging ? 0 : 1
name = "ridi-pay-${module.global_variables.env}"
subnet_ids = [
aws_subnet.private_2a.id,
aws_subnet.private_2c.id,
]
}