Skip to content

Commit 2b474e3

Browse files
authored
Merge pull request #321 from sil-org/get-rds-arn
Release 14.2.0 - database ARN and S3 backup bucket flexibility
2 parents 0dce2bc + 3f671bb commit 2b474e3

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

modules/032-db-backup/main.tf

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
locals {
2-
aws_region = data.aws_region.current.name
2+
aws_account = data.aws_caller_identity.this.account_id
3+
aws_region = data.aws_region.current.name
4+
rds_arn = (
5+
coalesce(
6+
var.rds_arn,
7+
"arn:aws:rds:${local.aws_region}:${local.aws_account}:db:idp-${var.idp_name}-${var.app_env}"
8+
)
9+
)
10+
s3_backup_bucket = coalesce(var.s3_backup_bucket, "${var.idp_name}-${var.app_name}-${var.app_env}")
311
}
412

513

614
/*
715
* AWS data
816
*/
917

18+
data "aws_caller_identity" "this" {}
19+
1020
data "aws_region" "current" {}
1121

1222
/*
1323
* Create S3 bucket for storing backups
1424
*/
1525
resource "aws_s3_bucket" "backup" {
16-
bucket = "${var.idp_name}-${var.app_name}-${var.app_env}"
26+
bucket = local.s3_backup_bucket
1727
force_destroy = true
1828

1929
tags = {
@@ -149,7 +159,7 @@ module "aws_backup" {
149159

150160
app_name = var.idp_name
151161
app_env = var.app_env
152-
source_arns = [data.aws_db_instance.this.db_instance_arn]
162+
source_arns = [local.rds_arn]
153163
backup_schedule = var.aws_backup_schedule
154164
notification_events = var.aws_backup_notification_events
155165
sns_topic_name = "${var.idp_name}-backup-vault-events"
@@ -158,9 +168,6 @@ module "aws_backup" {
158168
delete_after = var.delete_recovery_point_after_days
159169
}
160170

161-
data "aws_db_instance" "this" {
162-
db_instance_identifier = "idp-${var.idp_name}-${var.app_env}"
163-
}
164171

165172
/*
166173
* Synchronize S3 bucket to Backblaze B2

modules/032-db-backup/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ variable "mysql_user" {
8383
type = string
8484
}
8585

86+
variable "rds_arn" {
87+
description = <<-EOT
88+
The database RDS instance ARN. If not specified, the ARN will be calculated assuming the instance identifier is
89+
"idp-{idp_name}-{app_env}".
90+
EOT
91+
type = string
92+
default = ""
93+
}
94+
95+
variable "s3_backup_bucket" {
96+
description = <<-EOT
97+
The name of the S3 bucket to use for backup storage. If not specified, a bucket will be created with the name
98+
{var.idp_name}-{var.app_name}-{var.app_env}.
99+
EOT
100+
type = string
101+
default = ""
102+
}
103+
86104
variable "service_mode" {
87105
description = "Service mode, either `backup` or `restore`"
88106
type = string

0 commit comments

Comments
 (0)