-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLDC-3810: Automatically redeploy prod and staging when collection year rolls over #154
Merged
+112
−0
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bcf5b12
CLDC-3810: Set up ability to automatically redeploy app when collecti…
RachaelBooth 05b1333
Restore timing to non-test value
RachaelBooth b2f78e3
Enable for production
RachaelBooth 76227ef
Use customer managed key
RachaelBooth 9cac0c7
Actually set key arn
RachaelBooth a272c61
New test time
RachaelBooth e5e7c87
Try without the CMK
RachaelBooth e139449
Also redeploy sidekiq service
RachaelBooth 76f0613
New test time
RachaelBooth dceed69
Back to real schedule
RachaelBooth 48a67ea
Format
RachaelBooth ed60d04
Fix checkov skips
RachaelBooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
resource "aws_scheduler_schedule" "app_collection_rollover_redeploy" { | ||
#checkov:skip=CKV_AWS_297: CMK not required here and seems to cause issues | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
name = "${var.prefix}-app-collection-rollover-redeploy" | ||
|
||
schedule_expression = "cron(0 0 1 4 ? *)" | ||
schedule_expression_timezone = "UTC" | ||
|
||
flexible_time_window { | ||
mode = "OFF" | ||
} | ||
|
||
target { | ||
arn = "arn:aws:scheduler:::aws-sdk:ecs:updateService" | ||
role_arn = aws_iam_role.scheduler[0].arn | ||
|
||
input = jsonencode({ | ||
Cluster = aws_ecs_cluster.this.name, | ||
Service = aws_ecs_service.app.name, | ||
ForceNewDeployment = true | ||
}) | ||
} | ||
} | ||
|
||
resource "aws_scheduler_schedule" "sidekiq_collection_rollover_redeploy" { | ||
#checkov:skip=CKV_AWS_297: CMK not required here and seems to cause issues | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
name = "${var.prefix}-sidekiq-collection-rollover-redeploy" | ||
|
||
schedule_expression = "cron(0 0 1 4 ? *)" | ||
schedule_expression_timezone = "UTC" | ||
|
||
flexible_time_window { | ||
mode = "OFF" | ||
} | ||
|
||
target { | ||
arn = "arn:aws:scheduler:::aws-sdk:ecs:updateService" | ||
role_arn = aws_iam_role.scheduler[0].arn | ||
|
||
input = jsonencode({ | ||
Cluster = aws_ecs_cluster.this.name, | ||
Service = aws_ecs_service.sidekiq.name, | ||
ForceNewDeployment = true | ||
}) | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "scheduler" { | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
name = "${var.prefix}-rds-scheduler" | ||
assume_role_policy = data.aws_iam_policy_document.scheduler_assume_role[0].json | ||
} | ||
|
||
data "aws_iam_policy_document" "scheduler_assume_role" { | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
statement { | ||
actions = ["sts:AssumeRole"] | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["scheduler.amazonaws.com"] | ||
} | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "allow_ecs_actions" { | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
statement { | ||
actions = [ | ||
"ecs:Describe*", | ||
"ecs:UpdateService" | ||
] | ||
resources = [ | ||
aws_ecs_service.app.id, | ||
aws_ecs_service.sidekiq.id | ||
] | ||
effect = "Allow" | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "allow_ecs_actions" { | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
name = "${var.prefix}-allow-ecs-actions" | ||
policy = data.aws_iam_policy_document.allow_ecs_actions[0].json | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "scheduler_allow_ecs_actions" { | ||
count = var.collection_rollover_redeploy_enabled ? 1 : 0 | ||
|
||
role = aws_iam_role.scheduler[0].name | ||
policy_arn = aws_iam_policy.allow_ecs_actions[0].arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes things on AWS are an hour off, like logs, or the time at which things are uploaded to S3. I'm not sure if it would impact this at all, but would it make sense to redeploy at 1am ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be set to execute in UTC (so by April it will be 1am local time), which means it will be fine - AWS times on logs / file uploads I think are always in UTC, the important one for this will be what day the app thinks it is which is probably based on UTC (but if not will still be ok this way round).