Skip to content

Commit 0269e71

Browse files
authored
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`
1 parent 0c02f57 commit 0269e71

File tree

8 files changed

+74
-0
lines changed

8 files changed

+74
-0
lines changed

autogen/main.tf.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ resource "google_compute_region_autoscaler" "autoscaler" {
163163
target = lookup(load_balancing_utilization.value, "target", null)
164164
}
165165
}
166+
dynamic "scaling_schedules" {
167+
for_each = var.scaling_schedules
168+
content {
169+
disabled = lookup(scaling_schedules.value, "disabled", null)
170+
duration_sec = lookup(scaling_schedules.value, "duration_sec", null)
171+
min_required_replicas = lookup(scaling_schedules.value, "min_required_replicas", null)
172+
name = lookup(scaling_schedules.value, "name", null)
173+
schedule = lookup(scaling_schedules.value, "schedule", null)
174+
time_zone = lookup(scaling_schedules.value, "time_zone", null)
175+
}
176+
}
166177
}
167178
{% if mig_with_percent %}
168179

autogen/variables.tf.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ variable "autoscaling_lb" {
204204
default = []
205205
}
206206

207+
variable "scaling_schedules" {
208+
description = "Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules"
209+
type = list(object({
210+
disabled = bool
211+
duration_sec = number
212+
min_required_replicas = number
213+
name = string
214+
schedule = string
215+
time_zone = string
216+
}))
217+
default = []
218+
}
219+
207220
variable "autoscaling_scale_in_control" {
208221
description = "Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control"
209222
type = object({

modules/mig/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The current version is 2.X. The following guides are available to assist with up
3939
| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
4040
| project\_id | The GCP project ID | `string` | `null` | no |
4141
| region | The GCP region where the managed instance group resides. | `any` | n/a | yes |
42+
| 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 |
4243
| 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 | <pre>list(object({<br> device_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
4344
| subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
4445
| subnetwork\_project | The project that subnetwork belongs to | `string` | `""` | no |

modules/mig/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ resource "google_compute_region_autoscaler" "autoscaler" {
147147
target = lookup(load_balancing_utilization.value, "target", null)
148148
}
149149
}
150+
dynamic "scaling_schedules" {
151+
for_each = var.scaling_schedules
152+
content {
153+
disabled = lookup(scaling_schedules.value, "disabled", null)
154+
duration_sec = lookup(scaling_schedules.value, "duration_sec", null)
155+
min_required_replicas = lookup(scaling_schedules.value, "min_required_replicas", null)
156+
name = lookup(scaling_schedules.value, "name", null)
157+
schedule = lookup(scaling_schedules.value, "schedule", null)
158+
time_zone = lookup(scaling_schedules.value, "time_zone", null)
159+
}
160+
}
150161
}
151162
}
152163

modules/mig/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ variable "autoscaling_lb" {
189189
default = []
190190
}
191191

192+
variable "scaling_schedules" {
193+
description = "Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules"
194+
type = list(object({
195+
disabled = bool
196+
duration_sec = number
197+
min_required_replicas = number
198+
name = string
199+
schedule = string
200+
time_zone = string
201+
}))
202+
default = []
203+
}
204+
192205
variable "autoscaling_scale_in_control" {
193206
description = "Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control"
194207
type = object({

modules/mig_with_percent/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The current version is 2.X. The following guides are available to assist with up
4040
| next\_version\_percent | Percentage of instances defined in the second version | `any` | n/a | yes |
4141
| project\_id | The GCP project ID | `string` | `null` | no |
4242
| region | The GCP region where the managed instance group resides. | `any` | n/a | yes |
43+
| 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 |
4344
| 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 | <pre>list(object({<br> device_name = string<br> delete_rule = string<br> }))</pre> | `[]` | no |
4445
| subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no |
4546
| subnetwork\_project | The project that subnetwork belongs to | `string` | `""` | no |

modules/mig_with_percent/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ resource "google_compute_region_autoscaler" "autoscaler" {
156156
target = lookup(load_balancing_utilization.value, "target", null)
157157
}
158158
}
159+
dynamic "scaling_schedules" {
160+
for_each = var.scaling_schedules
161+
content {
162+
disabled = lookup(scaling_schedules.value, "disabled", null)
163+
duration_sec = lookup(scaling_schedules.value, "duration_sec", null)
164+
min_required_replicas = lookup(scaling_schedules.value, "min_required_replicas", null)
165+
name = lookup(scaling_schedules.value, "name", null)
166+
schedule = lookup(scaling_schedules.value, "schedule", null)
167+
time_zone = lookup(scaling_schedules.value, "time_zone", null)
168+
}
169+
}
159170
}
160171

161172
depends_on = [google_compute_region_instance_group_manager.mig_with_percent]

modules/mig_with_percent/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ variable "autoscaling_lb" {
197197
default = []
198198
}
199199

200+
variable "scaling_schedules" {
201+
description = "Autoscaling, scaling schedule block. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#scaling_schedules"
202+
type = list(object({
203+
disabled = bool
204+
duration_sec = number
205+
min_required_replicas = number
206+
name = string
207+
schedule = string
208+
time_zone = string
209+
}))
210+
default = []
211+
}
212+
200213
variable "autoscaling_scale_in_control" {
201214
description = "Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#scale_in_control"
202215
type = object({

0 commit comments

Comments
 (0)