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 the autoscaler performs automatic scaling based on the measured load. For more information, see the official documentation and API

Example Usage

resource "google_compute_instance_template" "foobar" {
  name           = "foobar"
  machine_type   = "n1-standard-1"
  can_ip_forward = false

  tags = ["foo", "bar"]

  disk {
    source_image = "debian-cloud/debian-8"

  network_interface {
    network = "default"

  metadata {
    foo = "bar"

  service_account {
    scopes = ["userinfo-email", "compute-ro", "storage-ro"]

resource "google_compute_target_pool" "foobar" {
  name = "foobar"

resource "google_compute_instance_group_manager" "foobar" {
  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"

resource "google_compute_autoscaler" "foobar" {
  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

Argument Reference

The following arguments are supported:

The autoscaling_policy block contains:

The cpu_utilization block contains:

The metric block contains (more documentation here):

The load_balancing_utilization block contains:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

See the source of this document at Terraform.io