Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions modules/032-db-backup/main.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
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}")
}


/*
* 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 = {
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions modules/032-db-backup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down