diff --git a/terraform/032-db-backup/main.tf b/terraform/032-db-backup/main.tf index 126a6a8..58de5c5 100644 --- a/terraform/032-db-backup/main.tf +++ b/terraform/032-db-backup/main.tf @@ -3,6 +3,16 @@ locals { aws_region = data.aws_region.current.name } + +/* + * AWS data + */ + +data "aws_caller_identity" "this" {} + +data "aws_region" "current" {} + + /* * Create S3 bucket for storing backups */ @@ -191,9 +201,19 @@ resource "aws_cloudwatch_event_target" "backup_event_target" { } /* - * AWS data + * AWS backup */ +module "aws_backup" { + count = var.enable_aws_backup ? 1 : 0 -data "aws_caller_identity" "this" {} + source = "github.com/silinternational/terraform-modules//aws/backup/rds?ref=8.8.0" + app_name = var.app_name + app_env = var.app_env + source_arns = [data.aws_db_instance.this.db_instance_arn] + backup_cron_schedule = var.aws_backup_cron_schedule + notification_events = var.aws_backup_notification_events +} -data "aws_region" "current" {} +data "aws_db_instance" "this" { + db_instance_identifier = "idp-${var.idp_name}-${var.app_env}" +} diff --git a/terraform/032-db-backup/vars.tf b/terraform/032-db-backup/vars.tf index 949731a..841f487 100644 --- a/terraform/032-db-backup/vars.tf +++ b/terraform/032-db-backup/vars.tf @@ -91,3 +91,21 @@ variable "service_mode" { variable "vpc_id" { type = string } + +variable "enable_aws_backup" { + description = "enable backup using AWS Backup service" + type = bool + default = false +} + +variable "aws_backup_cron_schedule" { + description = "cron-type schedule for AWS Backup" + type = string + default = "0 14 * * ? *" # Every day at 14:00 UTC, 12-hour offset from backup script +} + +variable "aws_backup_notification_events" { + description = "The names of the backup events that should trigger an email notification" + type = list(string) + default = ["BACKUP_JOB_FAILED"] +}