Google Compute Engine Region Autoscaler

This page shows how to write Terraform for Compute Engine Region Autoscaler and write them securely.

google_compute_region_autoscaler (Terraform)

The Region Autoscaler in Compute Engine can be configured in Terraform with the resource name google_compute_region_autoscaler. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub
resource "google_compute_region_autoscaler" "app-as" {
  name   = "backend-autoscaler"
  region = var.region
  target =
  autoscaling_policy {
    max_replicas    = 2
resource "google_compute_region_autoscaler" "autoscaler" {
  name   = var.autoscaler_name
  region = var.region
  target =

  autoscaling_policy {
resource "google_compute_region_autoscaler" "autoscaler" {

  # Count for list of group managers
  count = length(var.instance_group_mgrs)

  name   = var.instance_group_mgrs[count.index].name

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).


Creation timestamp in RFC3339 text format.

An optional description of this resource.

  • id optional computed - string
  • name required - string

Name of the resource. The name must be 1-63 characters long and match the regular expression 'a-z?' which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

URL of the region where the instance group resides.

URL of the managed instance group that this autoscaler will scale.

  • autoscaling_policy list block

    The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. This prevents the autoscaler from collecting information when the instance is initializing, during which the collected usage would not be reliable. The default time autoscaler waits is 60 seconds. Virtual machine initialization times might vary because of numerous factors. We recommend that you test how long an instance may take to initialize. To do this, create an instance and time the startup process.

    The maximum number of instances that the autoscaler can scale up to. This is required when creating or updating an autoscaler. The maximum number of replicas should not be lower than minimal number of replicas.

    The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. If not provided, autoscaler will choose a default value depending on maximum number of instances allowed.

    Defines operating mode for this policy. Default value: "ON" Possible values: ["OFF", "ONLY_UP", "ON"]

    • cpu_utilization list block

      The target CPU utilization that the autoscaler should maintain. Must be a float value in the range (0, 1]. If not specified, the default is 0.6. If the CPU level is below the target utilization, the autoscaler scales down the number of instances until it reaches the minimum number of instances you specified or until the average CPU of your instances reaches the target utilization. If the average CPU is above the target utilization, the autoscaler scales up until it reaches the maximum number of instances you specified or until the average utilization reaches the target utilization.

    • load_balancing_utilization list block

      Fraction of backend capacity utilization (set in HTTP(s) load balancing configuration) that autoscaler should maintain. Must be a positive float value. If not defined, the default is 0.8.

    • metric list block

      The identifier (type) of the Stackdriver Monitoring metric. The metric cannot have negative values. The metric must have a value type of INT64 or DOUBLE.

      The target value of the metric that autoscaler should maintain. This must be a positive value. A utilization metric scales number of virtual machines handling requests to increase or decrease proportionally to the metric. For example, a good metric to use as a utilizationTarget is The autoscaler will work to keep this value constant for each of the instances.

      Defines how target utilization value is expressed for a Stackdriver Monitoring metric. Possible values: ["GAUGE", "DELTA_PER_SECOND", "DELTA_PER_MINUTE"]

    • scale_in_control list block

      How long back autoscaling should look when computing recommendations to include directives regarding slower scale down, as described above.

      • max_scaled_in_replicas list block

        Specifies a fixed number of VM instances. This must be a positive integer.

        Specifies a percentage of instances between 0 to 100%, inclusive. For example, specify 80 for 80%.

  • timeouts single block

Explanation in Terraform Registry

Represents an Autoscaler resource. Autoscalers allow you to automatically scale virtual machine instances in managed instance groups according to an autoscaling policy that you define. To get more information about RegionAutoscaler, see:

Tips: Best Practices for The Other Google Compute Engine Resources

In addition to the google_compute_disk, Google Compute Engine has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.



Ensure the encryption key for your GCE disk is stored securely

It is better to store the encryption key for your GCE disk securely. Secret Manager could be used instead.



Ensure your VPC firewall blocks unwanted outbound traffic

It is better to block unwanted outbound traffic not to expose resources in the VPC to unwanted attacks.



Ensure appropriate service account is assigned to your GCE instance

It is better to create a custom service account for the instance and assign it.



Ensure OS login for your GCE instances is enabled at project level

It is better to enable OS login for your GCE instances. Enabling OS login ensures that SSH keys used to connect to instances are mapped with IAM users, allowing centralized and automated SSH key management.



Ensure to use modern TLS protocols

It's better to adopt TLS v1.2+ instead of outdated TLS protocols.



Ensure VPC flow logging is enabled

It is better to enable VPC flow logging. VPC flow logging allows us to audit traffic in your network.

Review your Google Compute Engine settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Frequently asked questions

What is Google Compute Engine Region Autoscaler?

Google Compute Engine Region Autoscaler is a resource for Compute Engine of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Compute Engine Region Autoscaler?

For Terraform, the pankajakhade/assignments, franklinRibe/Terraform7605-4531-projeto-final and KawiNeal/http-loadbalancer source code examples are useful. See the Terraform Example section for further details.


Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.