Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for google_compute_autoscaler autoscalingPolicy.cpuUtilization.predictiveMethod #2987

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4523.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added autoscaling_policy.cpu_utilization.predictive_method field to `google_compute_autoscaler` and `google_compute_region_autoscaler`
```
31 changes: 31 additions & 0 deletions google-beta/resource_compute_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ scales up until it reaches the maximum number of instances you
specified or until the average utilization reaches the target
utilization.`,
},
"predictive_method": {
Type: schema.TypeString,
Optional: true,
Description: `Indicates whether predictive autoscaling based on CPU metric is enabled. Valid values are:

- NONE (default). No predictive method is used. The autoscaler scales the group to meet current demand based on real-time metrics.

- OPTIMIZE_AVAILABILITY. Predictive autoscaling improves availability by monitoring daily and weekly load patterns and scaling out ahead of anticipated demand.`,
Default: "NONE",
},
},
},
},
Expand Down Expand Up @@ -973,12 +983,22 @@ func flattenComputeAutoscalerAutoscalingPolicyCpuUtilization(v interface{}, d *s
transformed := make(map[string]interface{})
transformed["target"] =
flattenComputeAutoscalerAutoscalingPolicyCpuUtilizationTarget(original["utilizationTarget"], d, config)
transformed["predictive_method"] =
flattenComputeAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(original["predictiveMethod"], d, config)
return []interface{}{transformed}
}
func flattenComputeAutoscalerAutoscalingPolicyCpuUtilizationTarget(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil || isEmptyValue(reflect.ValueOf(v)) {
return "NONE"
}

return v
}

func flattenComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1372,13 +1392,24 @@ func expandComputeAutoscalerAutoscalingPolicyCpuUtilization(v interface{}, d Ter
transformed["utilizationTarget"] = transformedTarget
}

transformedPredictiveMethod, err := expandComputeAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(original["predictive_method"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPredictiveMethod); val.IsValid() && !isEmptyValue(val) {
transformed["predictiveMethod"] = transformedPredictiveMethod
}

return transformed, nil
}

func expandComputeAutoscalerAutoscalingPolicyCpuUtilizationTarget(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
1 change: 1 addition & 0 deletions google-beta/resource_compute_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ resource "google_compute_autoscaler" "foobar" {
cooldown_period = 60
cpu_utilization {
target = 0.5
predictive_method = "OPTIMIZE_AVAILABILITY"
}
scale_down_control {
max_scaled_down_replicas {
Expand Down
31 changes: 31 additions & 0 deletions google-beta/resource_compute_region_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ scales up until it reaches the maximum number of instances you
specified or until the average utilization reaches the target
utilization.`,
},
"predictive_method": {
Type: schema.TypeString,
Optional: true,
Description: `Indicates whether predictive autoscaling based on CPU metric is enabled. Valid values are:

- NONE (default). No predictive method is used. The autoscaler scales the group to meet current demand based on real-time metrics.

- OPTIMIZE_AVAILABILITY. Predictive autoscaling improves availability by monitoring daily and weekly load patterns and scaling out ahead of anticipated demand.`,
Default: "NONE",
},
},
},
},
Expand Down Expand Up @@ -972,12 +982,22 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilization(v interface{}
transformed := make(map[string]interface{})
transformed["target"] =
flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationTarget(original["utilizationTarget"], d, config)
transformed["predictive_method"] =
flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(original["predictiveMethod"], d, config)
return []interface{}{transformed}
}
func flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationTarget(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil || isEmptyValue(reflect.ValueOf(v)) {
return "NONE"
}

return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1368,13 +1388,24 @@ func expandComputeRegionAutoscalerAutoscalingPolicyCpuUtilization(v interface{},
transformed["utilizationTarget"] = transformedTarget
}

transformedPredictiveMethod, err := expandComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(original["predictive_method"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPredictiveMethod); val.IsValid() && !isEmptyValue(val) {
transformed["predictiveMethod"] = transformedPredictiveMethod
}

return transformed, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationTarget(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyCpuUtilizationPredictiveMethod(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
1 change: 1 addition & 0 deletions google-beta/resource_compute_region_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ resource "google_compute_region_autoscaler" "foobar" {
cooldown_period = 60
cpu_utilization {
target = 0.5
predictive_method = "OPTIMIZE_AVAILABILITY"
}
scale_down_control {
max_scaled_down_replicas {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/compute_autoscaler.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ The `cpu_utilization` block supports:
specified or until the average utilization reaches the target
utilization.

* `predictive_method` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Indicates whether predictive autoscaling based on CPU metric is enabled. Valid values are:
- NONE (default). No predictive method is used. The autoscaler scales the group to meet current demand based on real-time metrics.
- OPTIMIZE_AVAILABILITY. Predictive autoscaling improves availability by monitoring daily and weekly load patterns and scaling out ahead of anticipated demand.

The `metric` block supports:

* `name` -
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/compute_region_autoscaler.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ The `cpu_utilization` block supports:
specified or until the average utilization reaches the target
utilization.

* `predictive_method` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
Indicates whether predictive autoscaling based on CPU metric is enabled. Valid values are:
- NONE (default). No predictive method is used. The autoscaler scales the group to meet current demand based on real-time metrics.
- OPTIMIZE_AVAILABILITY. Predictive autoscaling improves availability by monitoring daily and weekly load patterns and scaling out ahead of anticipated demand.

The `metric` block supports:

* `name` -
Expand Down