From 5d862d58b62cbafa98e1ae0e8228969c010628ea Mon Sep 17 00:00:00 2001 From: George Taylor Date: Wed, 18 Oct 2023 10:49:34 +0100 Subject: [PATCH] Allow customisable cron expression for bastion scale up/down schedules (#276) * Variable for scale cron expressions * terraform-docs: automated action * change to using one var with keys * terraform-docs: automated action * Update variables.tf * terraform-docs: automated action --------- Co-authored-by: github-actions[bot] --- README.md | 1 + main.tf | 4 ++-- variables.tf | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbc1482..a396965 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ In order to prevent older versions from being retained forever, in addition to t |------|-------------|------|---------|:--------:| | [allow\_ssh\_commands](#input\_allow\_ssh\_commands) | Allow SSH commands to be specified | `bool` | n/a | yes | | [app\_name](#input\_app\_name) | Name of application | `string` | n/a | yes | +| [autoscaling\_cron](#input\_autoscaling\_cron) | Cron expressions for scale up and scale down | `map(string)` |
{
"down": "0 20 * * *",
"up": "0 5 * * *"
}
| no | | [bucket\_force\_destroy](#input\_bucket\_force\_destroy) | The bucket and all objects should be destroyed when using true | `bool` | n/a | yes | | [bucket\_name](#input\_bucket\_name) | Bucket used for bucket log storage and user public keys | `string` | n/a | yes | | [bucket\_versioning](#input\_bucket\_versioning) | Enable bucket versioning or not | `bool` | n/a | yes | diff --git a/main.tf b/main.tf index 49cd649..ade0d18 100644 --- a/main.tf +++ b/main.tf @@ -491,7 +491,7 @@ resource "aws_autoscaling_schedule" "bastion_linux_scale_down" { min_size = 0 max_size = 0 desired_capacity = 0 - recurrence = "0 20 * * *" # 20.00 UTC time or 21.00 London time + recurrence = var.autoscaling_cron["up"] autoscaling_group_name = aws_autoscaling_group.bastion_linux_daily.name } @@ -500,6 +500,6 @@ resource "aws_autoscaling_schedule" "bastion_linux_scale_up" { min_size = 1 max_size = 1 desired_capacity = 1 - recurrence = "0 5 * * *" # 5.00 UTC time or 6.00 London time + recurrence = var.autoscaling_cron["down"] autoscaling_group_name = aws_autoscaling_group.bastion_linux_daily.name } diff --git a/variables.tf b/variables.tf index 70d46c9..01d098b 100644 --- a/variables.tf +++ b/variables.tf @@ -112,3 +112,11 @@ variable "tags_prefix" { description = "prefix for name tags" type = string } +variable "autoscaling_cron" { + description = "Cron expressions for scale up and scale down" + type = map(string) + default = { + "up" = "0 5 * * *" # 5.00 UTC or 6.00 BST + "down" = "0 20 * * *" # 20.00 UTC or 21.00 BST + } +}