Skip to content

Commit

Permalink
feat(mig): Add option to configure autoscaling schedules (terraform-g…
Browse files Browse the repository at this point in the history
…oogle-modules#247)

* feat(mig): Add option to configure autoscaling schedules

* feat(docs): Regenerate docs

* chore(mig): Add missing autogen; Run `make build`
  • Loading branch information
BapRx authored Jun 3, 2022
1 parent 0c02f57 commit 0269e71
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
11 changes: 11 additions & 0 deletions autogen/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
13 changes: 13 additions & 0 deletions autogen/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions modules/mig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <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 |
| 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 |
| 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 |
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
1 change: 1 addition & 0 deletions modules/mig_with_percent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <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 |
| 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 |
| 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 |
Expand Down
11 changes: 11 additions & 0 deletions modules/mig_with_percent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions modules/mig_with_percent/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 0269e71

Please sign in to comment.