From 0269e71eeaff5dbfdaaf2e83c74c8a3273122a4e Mon Sep 17 00:00:00 2001 From: Baptiste <32563450+BapRx@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:39:36 +0200 Subject: [PATCH] feat(mig): Add option to configure autoscaling schedules (#247) * feat(mig): Add option to configure autoscaling schedules * feat(docs): Regenerate docs * chore(mig): Add missing autogen; Run `make build` --- autogen/main.tf.tmpl | 11 +++++++++++ autogen/variables.tf.tmpl | 13 +++++++++++++ modules/mig/README.md | 1 + modules/mig/main.tf | 11 +++++++++++ modules/mig/variables.tf | 13 +++++++++++++ modules/mig_with_percent/README.md | 1 + modules/mig_with_percent/main.tf | 11 +++++++++++ modules/mig_with_percent/variables.tf | 13 +++++++++++++ 8 files changed, 74 insertions(+) diff --git a/autogen/main.tf.tmpl b/autogen/main.tf.tmpl index 83f466b0..b1ddb2c0 100644 --- a/autogen/main.tf.tmpl +++ b/autogen/main.tf.tmpl @@ -163,6 +163,17 @@ resource "google_compute_region_autoscaler" "autoscaler" { target = lookup(load_balancing_utilization.value, "target", null) } } + dynamic "scaling_schedules" { + for_each = var.scaling_schedules + content { + disabled = lookup(scaling_schedules.value, "disabled", null) + duration_sec = lookup(scaling_schedules.value, "duration_sec", null) + min_required_replicas = lookup(scaling_schedules.value, "min_required_replicas", null) + name = lookup(scaling_schedules.value, "name", null) + schedule = lookup(scaling_schedules.value, "schedule", null) + time_zone = lookup(scaling_schedules.value, "time_zone", null) + } + } } {% if mig_with_percent %} diff --git a/autogen/variables.tf.tmpl b/autogen/variables.tf.tmpl index f99788c8..e03cc009 100644 --- a/autogen/variables.tf.tmpl +++ b/autogen/variables.tf.tmpl @@ -204,6 +204,19 @@ variable "autoscaling_lb" { default = [] } +variable "scaling_schedules" { + description = "Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules" + type = list(object({ + disabled = bool + duration_sec = number + min_required_replicas = number + name = string + schedule = string + time_zone = string + })) + default = [] +} + variable "autoscaling_scale_in_control" { description = "Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control" type = object({ diff --git a/modules/mig/README.md b/modules/mig/README.md index 4dead6de..5c0f6c2f 100644 --- a/modules/mig/README.md +++ b/modules/mig/README.md @@ -39,6 +39,7 @@ The current version is 2.X. The following guides are available to assist with up | network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | | project\_id | The GCP project ID | `string` | `null` | no | | region | The GCP region where the managed instance group resides. | `any` | n/a | yes | +| scaling\_schedules | Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules |
list(object({| `[]` | no | | stateful\_disks | Disks created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs |
disabled = bool
duration_sec = number
min_required_replicas = number
name = string
schedule = string
time_zone = string
}))
list(object({| `[]` | no | | subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | | subnetwork\_project | The project that subnetwork belongs to | `string` | `""` | no | diff --git a/modules/mig/main.tf b/modules/mig/main.tf index 0ad424ca..e7c9d3c1 100644 --- a/modules/mig/main.tf +++ b/modules/mig/main.tf @@ -147,6 +147,17 @@ resource "google_compute_region_autoscaler" "autoscaler" { target = lookup(load_balancing_utilization.value, "target", null) } } + dynamic "scaling_schedules" { + for_each = var.scaling_schedules + content { + disabled = lookup(scaling_schedules.value, "disabled", null) + duration_sec = lookup(scaling_schedules.value, "duration_sec", null) + min_required_replicas = lookup(scaling_schedules.value, "min_required_replicas", null) + name = lookup(scaling_schedules.value, "name", null) + schedule = lookup(scaling_schedules.value, "schedule", null) + time_zone = lookup(scaling_schedules.value, "time_zone", null) + } + } } } diff --git a/modules/mig/variables.tf b/modules/mig/variables.tf index 917fd256..591ed769 100644 --- a/modules/mig/variables.tf +++ b/modules/mig/variables.tf @@ -189,6 +189,19 @@ variable "autoscaling_lb" { default = [] } +variable "scaling_schedules" { + description = "Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules" + type = list(object({ + disabled = bool + duration_sec = number + min_required_replicas = number + name = string + schedule = string + time_zone = string + })) + default = [] +} + variable "autoscaling_scale_in_control" { description = "Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control" type = object({ diff --git a/modules/mig_with_percent/README.md b/modules/mig_with_percent/README.md index 4a2fa557..9eb794be 100644 --- a/modules/mig_with_percent/README.md +++ b/modules/mig_with_percent/README.md @@ -40,6 +40,7 @@ The current version is 2.X. The following guides are available to assist with up | next\_version\_percent | Percentage of instances defined in the second version | `any` | n/a | yes | | project\_id | The GCP project ID | `string` | `null` | no | | region | The GCP region where the managed instance group resides. | `any` | n/a | yes | +| scaling\_schedules | Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules |
device_name = string
delete_rule = string
}))
list(object({| `[]` | no | | stateful\_disks | Disks created on the instances that will be preserved on instance delete. https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs |
disabled = bool
duration_sec = number
min_required_replicas = number
name = string
schedule = string
time_zone = string
}))
list(object({| `[]` | no | | subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | | subnetwork\_project | The project that subnetwork belongs to | `string` | `""` | no | diff --git a/modules/mig_with_percent/main.tf b/modules/mig_with_percent/main.tf index d2305a0b..bd04a446 100644 --- a/modules/mig_with_percent/main.tf +++ b/modules/mig_with_percent/main.tf @@ -156,6 +156,17 @@ resource "google_compute_region_autoscaler" "autoscaler" { target = lookup(load_balancing_utilization.value, "target", null) } } + dynamic "scaling_schedules" { + for_each = var.scaling_schedules + content { + disabled = lookup(scaling_schedules.value, "disabled", null) + duration_sec = lookup(scaling_schedules.value, "duration_sec", null) + min_required_replicas = lookup(scaling_schedules.value, "min_required_replicas", null) + name = lookup(scaling_schedules.value, "name", null) + schedule = lookup(scaling_schedules.value, "schedule", null) + time_zone = lookup(scaling_schedules.value, "time_zone", null) + } + } } depends_on = [google_compute_region_instance_group_manager.mig_with_percent] diff --git a/modules/mig_with_percent/variables.tf b/modules/mig_with_percent/variables.tf index 7cdb15d9..33ef6cd3 100644 --- a/modules/mig_with_percent/variables.tf +++ b/modules/mig_with_percent/variables.tf @@ -197,6 +197,19 @@ variable "autoscaling_lb" { default = [] } +variable "scaling_schedules" { + description = "Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules" + type = list(object({ + disabled = bool + duration_sec = number + min_required_replicas = number + name = string + schedule = string + time_zone = string + })) + default = [] +} + variable "autoscaling_scale_in_control" { description = "Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control" type = object({
device_name = string
delete_rule = string
}))