aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'photo.jinwei.me/infra/rds.tf')
-rw-r--r--photo.jinwei.me/infra/rds.tf49
1 files changed, 49 insertions, 0 deletions
diff --git a/photo.jinwei.me/infra/rds.tf b/photo.jinwei.me/infra/rds.tf
new file mode 100644
index 0000000..f596107
--- /dev/null
+++ b/photo.jinwei.me/infra/rds.tf
@@ -0,0 +1,49 @@
1resource "aws_db_parameter_group" "jinwei-me" {
2 name = var.name
3 family = var.rds_parameter_group
4}
5
6resource "aws_db_instance" "jinwei-me" {
7 identifier = var.name
8 instance_class = var.rds_instance_class
9 allocated_storage = var.rds_storage
10 engine = var.rds_engine
11 engine_version = var.rds_engine_version
12 username = var.rds_username
13 password = random_password.rds_password.result
14 port = var.rds_port
15 db_subnet_group_name = aws_db_subnet_group.jinwei-me.name
16 vpc_security_group_ids = [aws_security_group.rds.id]
17 parameter_group_name = aws_db_parameter_group.jinwei-me.name
18 publicly_accessible = true
19 skip_final_snapshot = true
20}
21
22resource "random_password" "rds_password" {
23 length = 16
24 special = false
25}
26
27resource "aws_ssm_parameter" "rds_host" {
28 name = "/${var.name}/mysql/host"
29 type = "String"
30 value = aws_db_instance.jinwei-me.address
31}
32
33resource "aws_ssm_parameter" "rds_port" {
34 name = "/${var.name}/mysql/port"
35 type = "String"
36 value = aws_db_instance.jinwei-me.port
37}
38
39resource "aws_ssm_parameter" "rds_user" {
40 name = "/${local.name}/mysql/username"
41 type = "String"
42 value = aws_db_instance.jinwei-me.username
43}
44
45resource "aws_ssm_parameter" "rds_password" {
46 name = "/${local.name}/mysql/password"
47 type = "SecureString"
48 value = random_password.rds_password.result
49}
Powered by cgit v1.2.3 (git 2.41.0)