2015-05-17 02:14:38 +02:00
|
|
|
---
|
|
|
|
layout: "google"
|
2015-07-28 02:47:10 +02:00
|
|
|
page_title: "Google: google_compute_autoscaler"
|
2015-10-23 16:10:41 +02:00
|
|
|
sidebar_current: "docs-google-compute-autoscaler"
|
2015-05-17 02:14:38 +02:00
|
|
|
description: |-
|
2015-07-28 02:47:10 +02:00
|
|
|
Manages an Autoscaler within GCE.
|
2015-05-17 02:14:38 +02:00
|
|
|
---
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
# google\_compute\_autoscaler
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
A Compute Engine Autoscaler automatically adds or removes virtual machines from
|
|
|
|
a managed instance group based on increases or decreases in load. This allows
|
|
|
|
your applications to gracefully handle increases in traffic and reduces cost
|
|
|
|
when the need for resources is lower. You just define the autoscaling policy and
|
2016-04-10 23:34:15 +02:00
|
|
|
the autoscaler performs automatic scaling based on the measured load. For more
|
2015-05-17 02:14:38 +02:00
|
|
|
information, see [the official
|
|
|
|
documentation](https://cloud.google.com/compute/docs/autoscaler/) and
|
|
|
|
[API](https://cloud.google.com/compute/docs/autoscaler/v1beta2/autoscalers)
|
|
|
|
|
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
2017-04-17 12:17:54 +02:00
|
|
|
```hcl
|
2015-05-17 02:14:38 +02:00
|
|
|
resource "google_compute_instance_template" "foobar" {
|
2016-04-10 23:34:15 +02:00
|
|
|
name = "foobar"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
2015-05-17 02:14:38 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
tags = ["foo", "bar"]
|
2015-05-17 02:14:38 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
disk {
|
2016-08-19 02:23:15 +02:00
|
|
|
source_image = "debian-cloud/debian-8"
|
2016-04-10 23:34:15 +02:00
|
|
|
}
|
2015-05-17 02:14:38 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-05-17 02:14:38 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2015-05-17 02:14:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_target_pool" "foobar" {
|
2016-04-10 23:34:15 +02:00
|
|
|
name = "foobar"
|
2015-05-17 02:14:38 +02:00
|
|
|
}
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
resource "google_compute_instance_group_manager" "foobar" {
|
2016-04-10 23:34:15 +02:00
|
|
|
name = "foobar"
|
|
|
|
zone = "us-central1-f"
|
|
|
|
|
|
|
|
instance_template = "${google_compute_instance_template.foobar.self_link}"
|
|
|
|
target_pools = ["${google_compute_target_pool.foobar.self_link}"]
|
|
|
|
base_instance_name = "foobar"
|
2015-05-17 02:14:38 +02:00
|
|
|
}
|
|
|
|
|
2015-07-28 02:47:10 +02:00
|
|
|
resource "google_compute_autoscaler" "foobar" {
|
2016-04-10 23:34:15 +02:00
|
|
|
name = "foobar"
|
|
|
|
zone = "us-central1-f"
|
|
|
|
target = "${google_compute_instance_group_manager.foobar.self_link}"
|
|
|
|
|
|
|
|
autoscaling_policy = {
|
|
|
|
max_replicas = 5
|
|
|
|
min_replicas = 1
|
|
|
|
cooldown_period = 60
|
|
|
|
|
|
|
|
cpu_utilization {
|
|
|
|
target = 0.5
|
2015-05-17 02:14:38 +02:00
|
|
|
}
|
2016-04-10 23:34:15 +02:00
|
|
|
}
|
2015-05-17 02:14:38 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-09-11 20:56:20 +02:00
|
|
|
## Argument Reference
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
The following arguments are supported:
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `name` - (Required) The name of the autoscaler.
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
* `target` - (Required) The full URL to the instance group manager whose size we
|
|
|
|
control.
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `zone` - (Required) The zone of the target.
|
|
|
|
|
2015-05-17 02:14:38 +02:00
|
|
|
* `autoscaling_policy.` - (Required) The parameters of the autoscaling
|
2016-04-10 23:34:15 +02:00
|
|
|
algorithm. Structure is documented below.
|
2015-05-17 02:14:38 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
- - -
|
|
|
|
|
|
|
|
* `description` - (Optional) An optional textual description of the instance
|
|
|
|
group manager.
|
|
|
|
|
|
|
|
* `project` - (Optional) The project in which the resource belongs. If it
|
|
|
|
is not provided, the provider project is used.
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
The `autoscaling_policy` block contains:
|
|
|
|
|
|
|
|
* `max_replicas` - (Required) The group will never be larger than this.
|
|
|
|
|
|
|
|
* `min_replicas` - (Required) The group will never be smaller than this.
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `cooldown_period` - (Optional) Period to wait between changes. This should be
|
2015-05-17 02:14:38 +02:00
|
|
|
at least double the time your instances take to start up.
|
|
|
|
|
|
|
|
* `cpu_utilization` - (Optional) A policy that scales when the cluster's average
|
2016-04-10 23:34:15 +02:00
|
|
|
CPU is above or below a given threshold. Structure is documented below.
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
* `metric` - (Optional) A policy that scales according to Google Cloud
|
|
|
|
Monitoring metrics Structure is documented below.
|
|
|
|
|
|
|
|
* `load_balancing_utilization` - (Optional) A policy that scales when the load
|
2016-04-10 23:34:15 +02:00
|
|
|
reaches a proportion of a limit defined in the HTTP load balancer. Structure
|
2015-05-17 02:14:38 +02:00
|
|
|
is documented below.
|
|
|
|
|
|
|
|
The `cpu_utilization` block contains:
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `target` - The floating point threshold where CPU utilization should be. E.g.
|
2015-05-17 02:14:38 +02:00
|
|
|
for 50% one would specify 0.5.
|
|
|
|
|
|
|
|
The `metric` block contains (more documentation
|
|
|
|
[here](https://cloud.google.com/monitoring/api/metrics)):
|
|
|
|
|
|
|
|
* `name` - The name of the Google Cloud Monitoring metric to follow, e.g.
|
2016-03-31 12:37:17 +02:00
|
|
|
`compute.googleapis.com/instance/network/received_bytes_count`
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
* `type` - Either "cumulative", "delta", or "gauge".
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `target` - The desired metric value per instance. Must be a positive value.
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
The `load_balancing_utilization` block contains:
|
|
|
|
|
|
|
|
* `target` - The floating point threshold where load balancing utilization
|
2016-04-10 23:34:15 +02:00
|
|
|
should be. E.g. if the load balancer's `maxRatePerInstance` is 10 requests
|
2015-05-17 02:14:38 +02:00
|
|
|
per second (RPS) then setting this to 0.5 would cause the group to be scaled
|
|
|
|
such that each instance receives 5 RPS.
|
|
|
|
|
|
|
|
|
|
|
|
## Attributes Reference
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
In addition to the arguments listed above, the following computed attributes are
|
|
|
|
exported:
|
2015-05-17 02:14:38 +02:00
|
|
|
|
|
|
|
* `self_link` - The URL of the created resource.
|