Skip to content

Commit

Permalink
feat!: Allow setting predictive method for CPU utilization scaling (t…
Browse files Browse the repository at this point in the history
…erraform-google-modules#255)

* Allow setting predictive method for CPU utilization scaling

* Update variable type for autoscaling_cpu

* Update fixture for failing tests
  • Loading branch information
vasyharan committed Oct 19, 2022
1 parent 5792db1 commit 28c77b5
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 15 deletions.
3 changes: 2 additions & 1 deletion autogen/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ resource "google_compute_region_autoscaler" "autoscaler" {
dynamic "cpu_utilization" {
for_each = var.autoscaling_cpu
content {
target = lookup(cpu_utilization.value, "target", null)
target = lookup(cpu_utilization.value, "target", null)
predictive_method = lookup(cpu_utilization.value, "predictive_method", null)
}
}
dynamic "metric" {
Expand Down
5 changes: 4 additions & 1 deletion autogen/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ variable "autoscaling_mode" {

variable "autoscaling_cpu" {
description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization"
type = list(map(number))
type = list(object({
target = number
predictive_method = string
}))
default = []
}

Expand Down
2 changes: 1 addition & 1 deletion examples/mig/autoscaler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group with an autoscaler.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| autoscaling\_cpu | Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization | `list(map(number))` | n/a | yes |
| autoscaling\_cpu | Autoscaling, cpu utilization policy block as single element array. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#cpu_utilization | <pre>list(object({<br> target = number<br> predictive_method = string<br> }))</pre> | n/a | yes |
| autoscaling\_enabled | Creates an autoscaler for the managed instance group | `any` | n/a | yes |
| min\_replicas | The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. | `any` | n/a | yes |
| project\_id | The GCP project to use for integration tests | `string` | n/a | yes |
Expand Down
7 changes: 5 additions & 2 deletions examples/mig/autoscaler/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ variable "min_replicas" {


variable "autoscaling_cpu" {
description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization"
type = list(map(number))
description = "Autoscaling, cpu utilization policy block as single element array. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_autoscaler#cpu_utilization"
type = list(object({
target = number
predictive_method = string
}))
}

3 changes: 2 additions & 1 deletion examples/mig/healthcheck/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ module "mig" {

autoscaling_cpu = [
{
target = 0.4
target = 0.4
predictive_method = null # use default of NONE
},
]

Expand Down
2 changes: 1 addition & 1 deletion modules/mig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The current version is 2.X. The following guides are available to assist with up
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| autoscaler\_name | Autoscaler name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no |
| autoscaling\_cpu | Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization | `list(map(number))` | `[]` | no |
| autoscaling\_cpu | Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization | <pre>list(object({<br> target = number<br> predictive_method = string<br> }))</pre> | `[]` | no |
| autoscaling\_enabled | Creates an autoscaler for the managed instance group | `string` | `"false"` | no |
| autoscaling\_lb | Autoscaling, load balancing utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#load_balancing_utilization | `list(map(number))` | `[]` | no |
| 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 |
Expand Down
3 changes: 2 additions & 1 deletion modules/mig/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ resource "google_compute_region_autoscaler" "autoscaler" {
dynamic "cpu_utilization" {
for_each = var.autoscaling_cpu
content {
target = lookup(cpu_utilization.value, "target", null)
target = lookup(cpu_utilization.value, "target", null)
predictive_method = lookup(cpu_utilization.value, "predictive_method", null)
}
}
dynamic "metric" {
Expand Down
7 changes: 5 additions & 2 deletions modules/mig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ variable "autoscaling_mode" {

variable "autoscaling_cpu" {
description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization"
type = list(map(number))
default = []
type = list(object({
target = number
predictive_method = string
}))
default = []
}

variable "autoscaling_metric" {
Expand Down
2 changes: 1 addition & 1 deletion modules/mig_with_percent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The current version is 2.X. The following guides are available to assist with up
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| autoscaler\_name | Autoscaler name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no |
| autoscaling\_cpu | Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization | `list(map(number))` | `[]` | no |
| autoscaling\_cpu | Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization | <pre>list(object({<br> target = number<br> predictive_method = string<br> }))</pre> | `[]` | no |
| autoscaling\_enabled | Creates an autoscaler for the managed instance group | `string` | `"false"` | no |
| autoscaling\_lb | Autoscaling, load balancing utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#load_balancing_utilization | `list(map(number))` | `[]` | no |
| 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 |
Expand Down
3 changes: 2 additions & 1 deletion modules/mig_with_percent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ resource "google_compute_region_autoscaler" "autoscaler" {
dynamic "cpu_utilization" {
for_each = var.autoscaling_cpu
content {
target = lookup(cpu_utilization.value, "target", null)
target = lookup(cpu_utilization.value, "target", null)
predictive_method = lookup(cpu_utilization.value, "predictive_method", null)
}
}
dynamic "metric" {
Expand Down
7 changes: 5 additions & 2 deletions modules/mig_with_percent/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ variable "autoscaling_mode" {

variable "autoscaling_cpu" {
description = "Autoscaling, cpu utilization policy block as single element array. https://www.terraform.io/docs/providers/google/r/compute_autoscaler.html#cpu_utilization"
type = list(map(number))
default = []
type = list(object({
target = number
predictive_method = string
}))
default = []
}

variable "autoscaling_metric" {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/mig/autoscaler/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module "mig_autoscaler" {

autoscaling_cpu = [
{
target = 0.6
target = 0.6,
predictive_method = null,
},
]
}
Expand Down

0 comments on commit 28c77b5

Please sign in to comment.