hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.73k forks source link

scaling_schedule in regional autoscaller not working when min_required_replicas = 0 is set #8993

Closed MikeMoore63 closed 3 years ago

MikeMoore63 commented 3 years ago

Community Note

12.24

google_compute_region_autoscaler - beta

Terraform Configuration Files

resource "google_compute_region_autoscaler" "scheduled_scale" {
  provider = google-beta.beta_deploy_provider
  name = "repobridge-scaler"
  depends_on = [
  google_compute_region_instance_group_manager.buildbridge-instance-group-manager]
  target = google_compute_region_instance_group_manager.buildbridge-instance-group-manager.id
  region = var.region

  autoscaling_policy {
    max_replicas = 1
    min_replicas = 1
    cooldown_period = 60
    cpu_utilization {
      target = 1
    }

    scaling_schedules {
          name = "weekend"
          description = "scale build bridge down at weekends"
          min_required_replicas = 0
          schedule = "0 3 * * SAT"
          duration_sec = 36 * 60 * 60
          time_zone = "UTC"
    }
    scaling_schedules {
          name ="weekday"
          description = "scale build bridge down at weekdays"
          time_zone = "UTC"
          schedule = "0 3 * * MON,TUE,WED,THU,FRI"
          duration_sec = 18 * 60 * 60
          min_required_replicas = 1
    }
  }
}

Debug Output

Panic Output

Expected Behavior

Expected to create auto scaller with schedule connected to mig

Actual Behavior

Error: Error creating RegionAutoscaler: googleapi: Error 400: Required field 'resource.autoscalingPolicy.scalingSchedules.key' not specified, required

In the api call you can see terraform generted an api call like this

'''

2021-04-25T13:47:50.603+0100 [INFO]  plugin.terraform-provider-google-beta_v3.55.0_x5: 2021/04/25 13:47:50 [DEBUG] Creating new RegionAutoscaler: map[string]interface {}{"autoscalingPolicy":map[string]interface {}{"coolDownPeriodSec":60, "cpuUtilization":map[string]interface {}{"utilizationTarget":1}, "maxNumReplicas":1, "minNumReplicas":1, "mode":"ON", "scalingSchedules":map[string]interface {}{"weekday":map[string]interface {}{"description":"scale build bridge down at weekdays", "durationSec":64800, "minRequiredReplicas":1, "schedule":"0 3 * * MON,TUE,WED,THU,FRI", "timeZone":"UTC"}, "weekend":map[string]interface {}{"description":"scale build bridge down at weekends", "durationSec":129600, "schedule":"0 3 * * SAT", "timeZone":"UTC"}}}, "name":"repobridge-scaler", "region":"projects/xxxxxx/global/regions/europe-west1", "target":"projects/*******/regions/europe-west1/instanceGroupManagers/gce-europe-west1-b-d-repobridge"}: timestamp=2021-04-25T13:47:50.603+0100

2021-04-25T13:47:50.603+0100 [INFO] plugin.terraform-provider-google-beta_v3.55.0_x5: 2021/04/25 13:47:50 [DEBUG] Waiting for state to become: [success]: timestamp=2021-04-25T13:47:50.603+0100 2021-04-25T13:47:50.604+0100 [INFO] plugin.terraform-provider-google-beta_v3.55.0_x5: 2021/04/25 13:47:50 [DEBUG] Retry Transport: starting RoundTrip retry loop: timestamp=2021-04-25T13:47:50.604+0100 2021-04-25T13:47:50.604+0100 [INFO] plugin.terraform-provider-google-beta_v3.55.0_x5: 2021/04/25 13:47:50 [DEBUG] Retry Transport: request attempt 0: timestamp=2021-04-25T13:47:50.604+0100 2021-04-25T13:47:50.604+0100 [INFO] plugin.terraform-provider-google-beta_v3.55.0_x5: 2021/04/25 13:47:50 [DEBUG] Google API Request Details: ---[ REQUEST ]--------------------------------------- POST /compute/beta/projects/xxxxxx/regions/europe-west1/autoscalers?alt=json HTTP/1.1 Host: compute.googleapis.com User-Agent: Terraform/0.12.26 (+https://www.terraform.io) Terraform-Plugin-SDK/2.4.2 terraform-provider-google-beta/dev Content-Length: 666 Content-Type: application/json Accept-Encoding: gzip

{ "autoscalingPolicy": { "coolDownPeriodSec": 60, "cpuUtilization": { "utilizationTarget": 1 }, "maxNumReplicas": 1, "minNumReplicas": 1, "mode": "ON", "scalingSchedules": { "weekday": { "description": "scale build bridge down at weekdays", "durationSec": 64800, "minRequiredReplicas": 1, "schedule": "0 3 MON,TUE,WED,THU,FRI", "timeZone": "UTC" }, "weekend": { "description": "scale build bridge down at weekends", "durationSec": 129600, "schedule": "0 3 SAT", "timeZone": "UTC" } } }, "name": "repobridge-scaler", "region": "projects/xxxxxx/global/regions/europe-west1", "target": "projects/xxxxxx/regions/europe-west1/instanceGroupManagers/gce-europe-west1-b-d-repobridge" }

-----------------------------------------------------: timestamp=2021-04-25T13:47:50.604+0100 2021-04-25T13:47:53.359+0100 [INFO] plugin.terraform-provider-google-beta_v3.55.0_x5: 2021/04/25 13:47:53 [DEBUG] Google API Response Details: ---[ RESPONSE ]-------------------------------------- HTTP/1.1 400 Bad Request Connection: close Transfer-Encoding: chunked Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" Cache-Control: private Content-Type: application/json; charset=UTF-8 Date: Sun, 25 Apr 2021 12:47:53 GMT Server: ESF Vary: Origin Vary: X-Origin Vary: Referer X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0

14b { "error": { "code": 400, "message": "Required field 'resource.autoscalingPolicy.scalingSchedules.key' not specified", "errors": [ { "message": "Required field 'resource.autoscalingPolicy.scalingSchedules.key' not specified", "domain": "global", "reason": "required" } ] } } '''

Steps to Reproduce

Create any scaling auto mig with a scaling_schedule

  1. terraform apply

Important Factoids

References

https://cloud.google.com/compute/docs/reference/rest/beta/regionAutoscalers/get

edwardmedia commented 3 years ago

@MikeMoore63 there is a test (below) that works fine. Can you compare the differences?

https://github.com/hashicorp/terraform-provider-google-beta/blob/6d7bc1f340997d3b233cc59152845ffddcb840f6/google-beta/resource_compute_region_autoscaler_test.go#L256

MikeMoore63 commented 3 years ago

JUst created using gcloud and all worked fine but log looked similar so puzzled as to

@MikeMoore63 there is a test (below) that works fine. Can you compare the differences?

https://github.com/hashicorp/terraform-provider-google-beta/blob/6d7bc1f340997d3b233cc59152845ffddcb840f6/google-beta/resource_compute_region_autoscaler_test.go#L256

Ok so played around with this it only errors when min_required_replicas = 0.

Using gcloud/console I can set to 0.

MikeMoore63 commented 3 years ago

A work around for this is set min_replicas in outer resource to 0 and just scale up which works. This as docs state after duration is passed reverts to default behavior.

ghost commented 3 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error πŸ€– πŸ™‰ , please reach out to my human friends πŸ‘‰ hashibot-feedback@hashicorp.com. Thanks!