diff --git a/modules/032-db-backup/main.tf b/modules/032-db-backup/main.tf index 5d23a2a..405bebb 100644 --- a/modules/032-db-backup/main.tf +++ b/modules/032-db-backup/main.tf @@ -1,5 +1,13 @@ locals { - aws_region = data.aws_region.current.name + aws_account = data.aws_caller_identity.this.account_id + aws_region = data.aws_region.current.name + rds_arn = ( + coalesce( + var.rds_arn, + "arn:aws:rds:${local.aws_region}:${local.aws_account}:db:idp-${var.idp_name}-${var.app_env}" + ) + ) + s3_backup_bucket = coalesce(var.s3_backup_bucket, "${var.idp_name}-${var.app_name}-${var.app_env}") } @@ -7,13 +15,15 @@ locals { * AWS data */ +data "aws_caller_identity" "this" {} + data "aws_region" "current" {} /* * Create S3 bucket for storing backups */ resource "aws_s3_bucket" "backup" { - bucket = "${var.idp_name}-${var.app_name}-${var.app_env}" + bucket = local.s3_backup_bucket force_destroy = true tags = { @@ -149,7 +159,7 @@ module "aws_backup" { app_name = var.idp_name app_env = var.app_env - source_arns = [data.aws_db_instance.this.db_instance_arn] + source_arns = [local.rds_arn] backup_schedule = var.aws_backup_schedule notification_events = var.aws_backup_notification_events sns_topic_name = "${var.idp_name}-backup-vault-events" @@ -158,9 +168,6 @@ module "aws_backup" { delete_after = var.delete_recovery_point_after_days } -data "aws_db_instance" "this" { - db_instance_identifier = "idp-${var.idp_name}-${var.app_env}" -} /* * Synchronize S3 bucket to Backblaze B2 diff --git a/modules/032-db-backup/variables.tf b/modules/032-db-backup/variables.tf index c14394f..c5c78f1 100644 --- a/modules/032-db-backup/variables.tf +++ b/modules/032-db-backup/variables.tf @@ -83,6 +83,24 @@ variable "mysql_user" { type = string } +variable "rds_arn" { + description = <<-EOT + The database RDS instance ARN. If not specified, the ARN will be calculated assuming the instance identifier is + "idp-{idp_name}-{app_env}". + EOT + type = string + default = "" +} + +variable "s3_backup_bucket" { + description = <<-EOT + The name of the S3 bucket to use for backup storage. If not specified, a bucket will be created with the name + {var.idp_name}-{var.app_name}-{var.app_env}. + EOT + type = string + default = "" +} + variable "service_mode" { description = "Service mode, either `backup` or `restore`" type = string