Skip to content

Commit

Permalink
deprecate cron_schedule
Browse files Browse the repository at this point in the history
use event_schedule instead. Changing for consistency and clarity. A "cron-type" schedule is only one of two types of event schedules.
  • Loading branch information
briskt committed Aug 7, 2024
1 parent b543fe9 commit 5ad6de6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
8 changes: 5 additions & 3 deletions terraform/032-db-backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion terraform/032-db-backup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,18 @@ 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.
*/
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
Expand Down
6 changes: 5 additions & 1 deletion terraform/032-db-backup/outputs.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
11 changes: 9 additions & 2 deletions terraform/032-db-backup/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/032-db-backup.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module "backup" {
backup_user_name = ""
cloudwatch_log_group_name = ""
cpu = ""
cron_schedule = ""
event_schedule = ""
db_names = [""]
docker_image = ""
ecsServiceRole_arn = ""
Expand Down

0 comments on commit 5ad6de6

Please sign in to comment.