From 5ad6de605fca05bd3aa2d5e8baf771d5e71f9a1f Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:27:50 +0800 Subject: [PATCH] deprecate cron_schedule use event_schedule instead. Changing for consistency and clarity. A "cron-type" schedule is only one of two types of event schedules. --- terraform/032-db-backup/README.md | 8 +++++--- terraform/032-db-backup/main.tf | 6 +++++- terraform/032-db-backup/outputs.tf | 6 +++++- terraform/032-db-backup/vars.tf | 11 +++++++++-- test/032-db-backup.tf | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/terraform/032-db-backup/README.md b/terraform/032-db-backup/README.md index 67964ca..f5111c4 100644 --- a/terraform/032-db-backup/README.md +++ b/terraform/032-db-backup/README.md @@ -25,14 +25,16 @@ This module is used to run mysqldump and backup files to S3 - `app_name` - Application name - `backup_user_name` - Name of IAM user for S3 access. Default: `db-backup-${var.idp_name}-${var.app_env}` - `cpu` - CPU resources to allot to each task instance - - `cron_schedule` - Schedule for CRON execution. Default: `cron(0 2 * * ? *)` + - `cron_schedule` - Schedule for CRON execution. DEPRECATED: use event_schedule` + - `event_schedule` - Schedule for backup task execution. Default: `cron(0 2 * * ? *)` - `db_names` - List of database names to backup. Default: `["emailservice", "idbroker", "pwmanager", "ssp"]` - `memory` - Memory (RAM) resources to allot to each task instance - `service_mode` - Either `backup` or `restore`. Default: `backup` ## Outputs - - `cron_schedule` - Schedule for CRON execution + - `cron_schedule` - Schedule for CRON execution. DEPRECATED + - `event_schedule` - Schedule for CRON execution - `s3_bucket_name` - S3 Bucket name - `s3_bucket_arn` - S3 Bucket ARN @@ -45,7 +47,7 @@ module "dbbackup" { app_name = var.app_name cloudwatch_log_group_name = var.cloudwatch_log_group_name cpu = var.cpu - cron_schedule = var.cron_schedule + event_schedule = var.event_schedule db_names = var.db_names docker_image = data.terraform_remote_state.ecr.ecr_repo_dbbackup ecs_cluster_id = data.terraform_remote_state.core.ecs_cluster_id diff --git a/terraform/032-db-backup/main.tf b/terraform/032-db-backup/main.tf index 8c2bff9..59d63f3 100644 --- a/terraform/032-db-backup/main.tf +++ b/terraform/032-db-backup/main.tf @@ -156,6 +156,10 @@ resource "aws_ecs_task_definition" "cron_td" { network_mode = "bridge" } +locals { + event_schedule = var.cron_schedule != "" ? var.cron_schedule : var.event_schedule +} + /* * CloudWatch configuration to start scheduled backup. */ @@ -163,7 +167,7 @@ resource "aws_cloudwatch_event_rule" "event_rule" { name = "${var.idp_name}-${var.app_name}-${var.app_env}" description = "Start scheduled backup" - schedule_expression = var.cron_schedule + schedule_expression = local.event_schedule tags = { app_name = var.app_name diff --git a/terraform/032-db-backup/outputs.tf b/terraform/032-db-backup/outputs.tf index 9561872..d52688b 100644 --- a/terraform/032-db-backup/outputs.tf +++ b/terraform/032-db-backup/outputs.tf @@ -1,5 +1,9 @@ output "cron_schedule" { - value = var.cron_schedule + value = local.event_schedule +} + +output "event_schedule" { + value = local.event_schedule } output "s3_bucket_name" { diff --git a/terraform/032-db-backup/vars.tf b/terraform/032-db-backup/vars.tf index 5f62eb5..949731a 100644 --- a/terraform/032-db-backup/vars.tf +++ b/terraform/032-db-backup/vars.tf @@ -28,8 +28,9 @@ variable "cpu" { } variable "cron_schedule" { - type = string - default = "cron(0 2 * * ? *)" + description = "Schedule for CRON execution. DEPRECATED: use event_schedule" + type = string + default = "" } variable "db_names" { @@ -55,6 +56,12 @@ variable "ecsServiceRole_arn" { type = string } +variable "event_schedule" { + description = "Schedule for backup task execution. Default: `cron(0 2 * * ? *)" + type = string + default = "cron(0 2 * * ? *)" +} + variable "idp_name" { type = string } diff --git a/test/032-db-backup.tf b/test/032-db-backup.tf index 81da95f..f3f6704 100644 --- a/test/032-db-backup.tf +++ b/test/032-db-backup.tf @@ -6,7 +6,7 @@ module "backup" { backup_user_name = "" cloudwatch_log_group_name = "" cpu = "" - cron_schedule = "" + event_schedule = "" db_names = [""] docker_image = "" ecsServiceRole_arn = ""