Skip to content

Commit 2cf312e

Browse files
update backup-restore feature
1 parent 004d9ae commit 2cf312e

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

examples/complete-psql-replica/main.tf

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ locals {
44
family = "postgres15"
55
vpc_cidr = "10.20.0.0/16"
66
environment = "prod"
7+
create_namespace = true
8+
namespace = "postgres"
79
storage_type = "gp3"
810
engine_version = "15.2"
911
instance_class = "db.m5d.large"
@@ -81,7 +83,7 @@ module "vpc" {
8183
}
8284

8385
module "rds-pg" {
84-
source = "squareops/rds-postgresql/aws"
86+
source = "../.."
8587
name = local.name
8688
db_name = "postgres"
8789
family = local.family
@@ -101,7 +103,7 @@ module "rds-pg" {
101103
publicly_accessible = false
102104
skip_final_snapshot = true
103105
backup_window = "03:00-06:00"
104-
maintenance_window = "Mon:00:00-Mon:03:00"
106+
maintenance_window = "Mon:00:00-Mon:03:00
105107
final_snapshot_identifier_prefix = "final"
106108
major_engine_version = local.engine_version
107109
deletion_protection = true
@@ -113,4 +115,23 @@ module "rds-pg" {
113115
slack_channel = "postgresql-notification"
114116
slack_webhook_url = "https://hooks/xxxxxxxx"
115117
custom_user_password = local.custom_user_password
118+
#if you want backup and restore then you have to create your cluster with rds vpc , subnet, key_arn.
119+
#And allow cluster security group in rds security group
120+
# cluster_name = "cluster-name"
121+
# namespace = local.namespace
122+
# create_namespace = local.create_namespace
123+
# postgresdb_backup_enabled = false
124+
# postgresdb_backup_config = {
125+
# postgres_database_name = "" # which database backup you want
126+
# s3_bucket_region = "" #s3 bucket region
127+
# cron_for_full_backup = "*/3 * * * *"
128+
# bucket_uri = "s3://xyz" #s3 bucket uri
129+
# }
130+
# postgresdb_restore_enabled = false
131+
# postgresdb_restore_config = {
132+
# bucket_uri = "s3://xyz" #s3 bucket uri which have dackup dump file
133+
# backup_file_name = "abc.dump" #Give only .sql or .zip file for restore
134+
# s3_bucket_region = "" # bucket region
135+
# DB_NAME = "" # which db to restore backup file
136+
# }
116137
}

examples/complete/main.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,21 @@ module "rds-pg" {
131131
custom_user_password = local.custom_user_password
132132
#if you want backup and restore then you have to create your cluster with rds vpc id , private subnets, kms key.
133133
#And allow cluster security group in rds security group
134-
cluster_name = "cluster-name"
135-
namespace = local.namespace
136-
create_namespace = local.create_namespace
137-
postgresdb_backup_enabled = false
138-
postgresdb_backup_config = {
139-
postgres_database_name = "" # which database backup you want
140-
s3_bucket_region = "" #s3 bucket region
141-
cron_for_full_backup = "*/3 * * * *"
142-
bucket_uri = "s3://xyz" #s3 bucket uri
143-
}
144-
postgresdb_restore_enabled = false
145-
postgresdb_restore_config = {
146-
bucket_uri = "s3://xyz" #s3 bucket uri which have dackup dump file
147-
backup_file_name = "abc.dump" #Give only .sql or .zip file for restore
148-
s3_bucket_region = "" # bucket region
149-
DB_NAME = "" # which db to restore backup file
150-
}
134+
# cluster_name = "cluster-name"
135+
# namespace = local.namespace
136+
# create_namespace = local.create_namespace
137+
# postgresdb_backup_enabled = false
138+
# postgresdb_backup_config = {
139+
# postgres_database_name = "" # which database backup you want
140+
# s3_bucket_region = "" #s3 bucket region
141+
# cron_for_full_backup = "*/3 * * * *"
142+
# bucket_uri = "s3://xyz" #s3 bucket uri
143+
# }
144+
# postgresdb_restore_enabled = false
145+
# postgresdb_restore_config = {
146+
# bucket_uri = "s3://xyz" #s3 bucket uri which have dackup dump file
147+
# backup_file_name = "abc.dump" #Give only .sql or .zip file for restore
148+
# s3_bucket_region = "" # bucket region
149+
# DB_NAME = "" # which db to restore backup file
150+
# }
151151
}

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,19 @@ module "backup_restore" {
327327
postgresdb_backup_enabled = var.postgresdb_backup_enabled
328328
postgresdb_backup_config = {
329329
db_username = var.master_username
330-
db_password = var.custom_user_password != "" ? var.custom_user_password : nonsensitive(random_password.master[0].result)
330+
db_password = nonsensitive(random_password.master[0].result)
331331
postgres_database_name = var.postgresdb_backup_config.postgres_database_name
332332
s3_bucket_region = var.postgresdb_backup_config.s3_bucket_region
333333
cron_for_full_backup = var.postgresdb_backup_config.cron_for_full_backup
334334
bucket_uri = var.postgresdb_backup_config.bucket_uri
335-
db_endpoint = replace(module.db.db_instance_endpoint, ":5432", "")
335+
db_endpoint = replace(var.replica_enable ? module.db_replica[0].db_instance_endpoint : module.db.db_instance_endpoint, ":5432", "")
336336
}
337337

338338
postgresdb_restore_enabled = var.postgresdb_restore_enabled
339339
postgresdb_restore_config = {
340-
db_endpoint = replace(module.db.db_instance_endpoint, ":5432", "")
340+
db_endpoint = replace(var.replica_enable ? module.db_replica[0].db_instance_endpoint : module.db.db_instance_endpoint, ":5432", "")
341341
db_username = var.master_username
342-
db_password = var.custom_user_password != "" ? var.custom_user_password : nonsensitive(random_password.master[0].result)
342+
db_password = nonsensitive(random_password.master[0].result)
343343
bucket_uri = var.postgresdb_restore_config.bucket_uri
344344
s3_bucket_region = var.postgresdb_restore_config.s3_bucket_region
345345
DB_NAME = var.postgresdb_restore_config.DB_NAME,

0 commit comments

Comments
 (0)