Skip to content

Commit

Permalink
Merge pull request #1806 from alphagov/turn_review_apps_off_overnight
Browse files Browse the repository at this point in the history
.review_apps: use app autoscaling to turn review apps off at night, weekends
  • Loading branch information
AP-Hunt authored Feb 26, 2025
2 parents a21081c + e2a6946 commit d33506a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .review_apps/app_autoscaling.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
resource "aws_appautoscaling_target" "review_app" {
service_namespace = "ecs"
resource_id = "service/${data.terraform_remote_state.review.outputs.ecs_cluster_id}/${aws_ecs_service.app.name}"
scalable_dimension = "ecs:service:DesiredCount"

max_capacity = 1
min_capacity = 1
}

resource "aws_appautoscaling_scheduled_action" "shutdown_at_night" {
name = "pr-${var.pull_request_number}-shutdown-at-night"

service_namespace = aws_appautoscaling_target.review_app.service_namespace
resource_id = aws_appautoscaling_target.review_app.resource_id
scalable_dimension = aws_appautoscaling_target.review_app.scalable_dimension

schedule = "cron(0 18 * * ? *)" # daily at 1800

scalable_target_action {
min_capacity = 0
max_capacity = 0
}
}

resource "aws_appautoscaling_scheduled_action" "startup_weekday_mornings" {
name = "pr-${var.pull_request_number}-startup-weekday-mornings"

service_namespace = aws_appautoscaling_target.review_app.service_namespace
resource_id = aws_appautoscaling_target.review_app.resource_id
scalable_dimension = aws_appautoscaling_target.review_app.scalable_dimension

schedule = "cron(0 8 ? * MON-FRI *)" # Monday-Friday at 0800

scalable_target_action {
min_capacity = 1
max_capacity = 1
}
}

0 comments on commit d33506a

Please sign in to comment.