Skip to content

Commit

Permalink
Add mode and scaleDownControls for Compute Region AutoScaler (#3701) (#…
Browse files Browse the repository at this point in the history
…6685)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jun 24, 2020
1 parent 5c9f20d commit 7d9bc92
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .changelog/3701.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
compute: Added `mode` to `google_compute_region_autoscaler` `autoscaling_policy`
```
```release-note:enhancement
compute: Added `scale_down_control ` to `google_compute_region_autoscaler` `autoscaling_policy` (beta only)
```
24 changes: 24 additions & 0 deletions google/resource_compute_region_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ Stackdriver Monitoring metric. Possible values: ["GAUGE", "DELTA_PER_SECOND", "D
},
},
},
"mode": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"OFF", "ONLY_UP", "ON", ""}, false),
Description: `Defines operating mode for this policy. Default value: "ON" Possible values: ["OFF", "ONLY_UP", "ON"]`,
Default: "ON",
},
},
},
},
Expand Down Expand Up @@ -484,6 +491,8 @@ func flattenComputeRegionAutoscalerAutoscalingPolicy(v interface{}, d *schema.Re
flattenComputeRegionAutoscalerAutoscalingPolicyMaxReplicas(original["maxNumReplicas"], d, config)
transformed["cooldown_period"] =
flattenComputeRegionAutoscalerAutoscalingPolicyCooldownPeriod(original["coolDownPeriodSec"], d, config)
transformed["mode"] =
flattenComputeRegionAutoscalerAutoscalingPolicyMode(original["mode"], d, config)
transformed["cpu_utilization"] =
flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilization(original["cpuUtilization"], d, config)
transformed["metric"] =
Expand Down Expand Up @@ -543,6 +552,10 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyCooldownPeriod(v interface{}
return v // let terraform core handle it otherwise
}

func flattenComputeRegionAutoscalerAutoscalingPolicyMode(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyCpuUtilization(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -658,6 +671,13 @@ func expandComputeRegionAutoscalerAutoscalingPolicy(v interface{}, d TerraformRe
transformed["coolDownPeriodSec"] = transformedCooldownPeriod
}

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

transformedCpuUtilization, err := expandComputeRegionAutoscalerAutoscalingPolicyCpuUtilization(original["cpu_utilization"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -694,6 +714,10 @@ func expandComputeRegionAutoscalerAutoscalingPolicyCooldownPeriod(v interface{},
return v, nil
}

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

func expandComputeRegionAutoscalerAutoscalingPolicyCpuUtilization(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
57 changes: 9 additions & 48 deletions google/resource_compute_region_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestAccComputeRegionAutoscaler_update(t *testing.T) {
})
}

func testAccComputeRegionAutoscaler_basic(it_name, tp_name, igm_name, autoscaler_name string) string {
func testAccComputeRegionAutoscaler_scaffolding(it_name, tp_name, igm_name string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
Expand Down Expand Up @@ -84,6 +84,11 @@ resource "google_compute_region_instance_group_manager" "foobar" {
region = "us-central1"
}
`, it_name, tp_name, igm_name)
}

func testAccComputeRegionAutoscaler_basic(it_name, tp_name, igm_name, autoscaler_name string) string {
return testAccComputeRegionAutoscaler_scaffolding(it_name, tp_name, igm_name) + fmt.Sprintf(`
resource "google_compute_region_autoscaler" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
Expand All @@ -98,55 +103,11 @@ resource "google_compute_region_autoscaler" "foobar" {
}
}
}
`, it_name, tp_name, igm_name, autoscaler_name)
`, autoscaler_name)
}

func testAccComputeRegionAutoscaler_update(it_name, tp_name, igm_name, autoscaler_name string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
}
resource "google_compute_instance_template" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
boot = true
}
network_interface {
network = "default"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
resource "google_compute_target_pool" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
}
resource "google_compute_region_instance_group_manager" "foobar" {
description = "Terraform test instance group manager"
name = "%s"
version {
instance_template = google_compute_instance_template.foobar.self_link
name = "primary"
}
target_pools = [google_compute_target_pool.foobar.self_link]
base_instance_name = "foobar"
region = "us-central1"
}
return testAccComputeRegionAutoscaler_scaffolding(it_name, tp_name, igm_name) + fmt.Sprintf(`
resource "google_compute_region_autoscaler" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
Expand All @@ -161,5 +122,5 @@ resource "google_compute_region_autoscaler" "foobar" {
}
}
}
`, it_name, tp_name, igm_name, autoscaler_name)
`, autoscaler_name)
}
10 changes: 10 additions & 0 deletions website/docs/r/compute_region_autoscaler.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ The `autoscaling_policy` block supports:
instance may take to initialize. To do this, create an instance
and time the startup process.

* `mode` -
(Optional)
Defines operating mode for this policy.

Default value: `ON`
Possible values are:
* `OFF`
* `ONLY_UP`
* `ON`

* `cpu_utilization` -
(Optional)
Defines the CPU utilization policy that allows the autoscaler to
Expand Down

0 comments on commit 7d9bc92

Please sign in to comment.