Skip to content

Commit

Permalink
feat(mig): Add option to configure autoscaling schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
BapRx committed May 19, 2022
1 parent 0c02f57 commit 9f5a4c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/mig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The current version is 2.X. The following guides are available to assist with up
| autoscaling\_metric | Autoscaling, metric policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#metric | <pre>list(object({<br> name = string<br> target = number<br> type = string<br> }))</pre> | `[]` | no |
| autoscaling\_mode | Operating mode of the autoscaling policy. If omitted, the default value is ON. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#mode | `string` | `null` | no |
| autoscaling\_scale\_in\_control | Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control | <pre>object({<br> fixed_replicas = number<br> percent_replicas = number<br> time_window_sec = number<br> })</pre> | <pre>{<br> "fixed_replicas": null,<br> "percent_replicas": null,<br> "time_window_sec": null<br>}</pre> | no |
| scaling\_schedules | Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules | <pre>list(object({<br> disabled = bool<br> duration_sec = number<br> min_required_replicas = number<br> name = string<br> schedule = string<br> time_zone = string<br> }))</pre> | `[]` | no |
| cooldown\_period | The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. | `number` | `60` | no |
| distribution\_policy\_zones | The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region. | `list(string)` | `[]` | no |
| health\_check | Health check to determine whether instances are responsive and able to do work | <pre>object({<br> type = string<br> initial_delay_sec = number<br> check_interval_sec = number<br> healthy_threshold = number<br> timeout_sec = number<br> unhealthy_threshold = number<br> response = string<br> proxy_header = string<br> port = number<br> request = string<br> request_path = string<br> host = string<br> })</pre> | <pre>{<br> "check_interval_sec": 30,<br> "healthy_threshold": 1,<br> "host": "",<br> "initial_delay_sec": 30,<br> "port": 80,<br> "proxy_header": "NONE",<br> "request": "",<br> "request_path": "/",<br> "response": "",<br> "timeout_sec": 10,<br> "type": "",<br> "unhealthy_threshold": 5<br>}</pre> | no |
Expand Down
11 changes: 11 additions & 0 deletions modules/mig/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions modules/mig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 9f5a4c0

Please sign in to comment.