Google Compute Engine Instance Group

This page shows how to write Terraform for Compute Engine Instance Group and write them securely.


Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.


Terraform Example (google_compute_instance_group)

Creates a group of dissimilar Compute Engine virtual machine instances. For more information, see the official documentation and API -> Recreating an instance group that's in use by another resource will give a resourceInUseByAnotherResource error. You can avoid this error with a Terraform lifecycle block as outlined in the example below.


  • description optional - string
    • An optional textual description of the instance group.

  • id optionalcomputed - string
  • instances optionalcomputed - set / string
    • List of instances in the group. They should be given as self_link URLs. When adding instances they must all be in the same network and zone as the instance group.

  • name required - string
    • The name of the instance group. Must be 1-63 characters long and comply with RFC1035. Supported characters include lowercase letters, numbers, and hyphens.

  • network optionalcomputed - string
    • The URL of the network the instance group is in. If this is different from the network where the instances are in, the creation fails. Defaults to the network where the instances are in (if neither network nor instances is specified, this field will be blank).

  • project optionalcomputed - string
    • The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

  • self_link requiredcomputed - string
    • The URI of the created resource.

  • size requiredcomputed - number
    • The number of instances in the group.

  • zone optionalcomputed - string
    • The zone that this instance group should be created in.

Example Usage (from GitHub)

resource "google_compute_instance_group" "malware-scanner" {
  name        = "malware-scanner"
  description = "Malware Scan instance group"
  zone        = var.zone_1
  instances = [
resource "google_compute_instance_group" "fw-umig-01" {
  name        = "firewall-umig-01"
  description = "Terraform unmanaged instance groups"
  zone        = "us-central1-b"
  network     =

Frequently asked questions

What is Google Compute Engine Instance Group?

Google Compute Engine Instance Group 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 Instance Group?

For Terraform, the gashirar/gcs-malware-scanner-terraform and aaronstrong/gcp-professional-architect source code examples are useful. See the Terraform Example section for further details.