@@ -21,7 +21,7 @@ locals {
2121 )
2222}
2323
24- resource "aws_ecs_task_definition" "cron_job " {
24+ resource "aws_ecs_task_definition" "mailchimp_cron_job " {
2525 count = var. enable_mailchimp_sync ? 1 : 0
2626
2727 family = " ${ var . env_name } _forms-admin_mailchimp_sync"
@@ -46,27 +46,27 @@ resource "aws_ecs_task_definition" "cron_job" {
4646# #
4747# EventBridge
4848# #
49- resource "aws_cloudwatch_event_rule" "sync_cron_job " {
49+ resource "aws_cloudwatch_event_rule" "sync_mailchimp_cron_job " {
5050 count = var. enable_mailchimp_sync ? 1 : 0
5151
52- name = " ${ var . env_name } -forms-admin-sync-cron"
52+ name = " ${ var . env_name } -forms-admin-mailchimp- sync-cron"
5353 description = " Trigger the forms-admin MailChimp synchronisation on a schedule"
5454 schedule_expression = " cron(30 10 * * ? *)" # 10:30AM daily. In office hours so that we can respond to failures
5555}
5656
57- resource "aws_cloudwatch_event_target" "ecs_sync_job " {
57+ resource "aws_cloudwatch_event_target" "ecs_mailchimp_sync_job " {
5858 count = var. enable_mailchimp_sync ? 1 : 0
5959
6060 arn = var. ecs_cluster_arn
61- rule = aws_cloudwatch_event_rule. sync_cron_job [0 ]. name
62- role_arn = aws_iam_role. ecs_cron_scheduler [0 ]. arn
61+ rule = aws_cloudwatch_event_rule. sync_mailchimp_cron_job [0 ]. name
62+ role_arn = aws_iam_role. ecs_mailchimp_cron_scheduler [0 ]. arn
6363
6464 ecs_target {
6565 # Construct ARN without revision number to always use the latest revision
6666 # Format: arn:aws:ecs:region:account:task-definition/family
6767 # This ensures the EventBridge rule always uses the latest revision
6868 # which is updated by the forms-admin deployment pipeline
69- task_definition_arn = " arn:aws:ecs:eu-west-2:${ data . aws_caller_identity . current . account_id } :task-definition/${ aws_ecs_task_definition . cron_job [0 ]. family } "
69+ task_definition_arn = " arn:aws:ecs:eu-west-2:${ data . aws_caller_identity . current . account_id } :task-definition/${ aws_ecs_task_definition . mailchimp_cron_job [0 ]. family } "
7070 launch_type = " FARGATE"
7171 platform_version = " 1.4.0"
7272
@@ -83,8 +83,8 @@ resource "aws_cloudwatch_event_target" "ecs_sync_job" {
8383}
8484
8585# # Monitor for failure
86- resource "aws_cloudwatch_event_rule" "sync_cron_job_failed " {
87- name = " ${ var . env_name } -forms-admin-sync-failed"
86+ resource "aws_cloudwatch_event_rule" "sync_mailchimp_cron_job_failed " {
87+ name = " ${ var . env_name } -forms-admin-mailchimp- sync-failed"
8888 description = " Trigger when the MailChimp sync job has exited with a non-zero exit code"
8989
9090 event_pattern = jsonencode ({
@@ -106,8 +106,8 @@ resource "aws_cloudwatch_event_rule" "sync_cron_job_failed" {
106106 })
107107}
108108
109- resource "aws_cloudwatch_event_target" "sync_cron_job_alert_message " {
110- rule = aws_cloudwatch_event_rule. sync_cron_job_failed . name
109+ resource "aws_cloudwatch_event_target" "sync_mailchimp_cron_job_alert_message " {
110+ rule = aws_cloudwatch_event_rule. sync_mailchimp_cron_job_failed . name
111111
112112 # defined in 'environment' module. Sends alarms/errors via ZenDesk
113113 arn = var. zendesk_sns_topic_arn
@@ -134,10 +134,10 @@ resource "aws_cloudwatch_event_target" "sync_cron_job_alert_message" {
134134# #
135135# IAM
136136# #
137- resource "aws_iam_role" "ecs_cron_scheduler " {
137+ resource "aws_iam_role" "ecs_mailchimp_cron_scheduler " {
138138 count = var. enable_mailchimp_sync ? 1 : 0
139139
140- name = " ${ var . env_name } -forms-admin-ecs-cron-scheduler"
140+ name = " ${ var . env_name } -forms-admin-mailchimp- ecs-cron-scheduler"
141141
142142 assume_role_policy = jsonencode ({
143143 Version = " 2012-10-17"
@@ -153,9 +153,19 @@ resource "aws_iam_role" "ecs_cron_scheduler" {
153153 })
154154}
155155
156- resource "aws_iam_role_policy_attachment" "ecs_events_policy " {
156+ resource "aws_iam_role_policy_attachment" "ecs_mailchimp_events_policy " {
157157 count = var. enable_mailchimp_sync ? 1 : 0
158158
159159 policy_arn = " arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceEventsRole"
160- role = aws_iam_role. ecs_cron_scheduler [0 ]. name
160+ role = aws_iam_role. ecs_mailchimp_cron_scheduler [0 ]. name
161+ }
162+
163+ moved {
164+ from = aws_cloudwatch_event_rule. sync_cron_job_failed
165+ to = aws_cloudwatch_event_rule. sync_mailchimp_cron_job_failed
166+ }
167+
168+ moved {
169+ from = aws_cloudwatch_event_target. sync_cron_job_alert_message
170+ to = aws_cloudwatch_event_target. sync_mailchimp_cron_job_alert_message
161171}
0 commit comments