Skip to content

googleComputeRegionPerInstanceConfig

A config defined for a single managed instance that belongs to an instance group manager. It preserves the instance name across instance group manager operations and can define stateful disks or metadata that are unique to the instance. This resource works with regional instance group managers.

To get more information about RegionPerInstanceConfig, see:

Example Usage - Stateful Rigm

data "google_compute_image" "my_image" {
  family  = "debian-11"
  project = "debian-cloud"
}

resource "google_compute_instance_template" "igm-basic" {
  name           = "my-template"
  machine_type   = "e2-medium"
  can_ip_forward = false
  tags           = ["foo", "bar"]

  disk {
    source_image = data.google_compute_image.my_image.self_link
    auto_delete  = true
    boot         = true
  }

  network_interface {
    network = "default"
  }

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

resource "google_compute_region_instance_group_manager" "rigm" {
  description = "Terraform test instance group manager"
  name        = "my-rigm"

  version {
    name              = "prod"
    instance_template = google_compute_instance_template.igm-basic.self_link
  }

  update_policy {
    type                         = "OPPORTUNISTIC"
    instance_redistribution_type = "NONE"
    minimal_action               = "RESTART"
  }

  base_instance_name = "rigm"
  region             = "us-central1"
  target_size        = 2
}

resource "google_compute_disk" "default" {
  name  = "test-disk-%{random_suffix}"
  type  = "pd-ssd"
  zone  = "us-central1-a"
  image = "debian-11-bullseye-v20220719"
  physical_block_size_bytes = 4096
}

resource "google_compute_region_per_instance_config" "with_disk" {
  region = google_compute_region_instance_group_manager.igm.region
  region_instance_group_manager = google_compute_region_instance_group_manager.rigm.name
  name = "instance-1"
  preserved_state {
    metadata = {
      foo = "bar"
      // Adding a reference to the instance template used causes the stateful instance to update
      // if the instance template changes. Otherwise there is no explicit dependency and template
      // changes may not occur on the stateful instance
      instance_template = google_compute_instance_template.igm-basic.self_link
    }

    disk {
      device_name = "my-stateful-disk"
      source      = google_compute_disk.default.id
      mode        = "READ_ONLY"
    }
  }
}

Argument Reference

The following arguments are supported:

  • name - (Required) The name for this per-instance config and its corresponding instance.

  • regionInstanceGroupManager - (Required) The region instance group manager this instance config is part of.


  • preservedState - (Optional) The preserved state for this instance. Structure is documented below.

  • region - (Optional) Region where the containing instance group manager is located

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

  • minimalAction - (Optional) The minimal action to perform on the instance during an update. Default is none. Possible values are:

  • REPLACE

  • RESTART

  • REFRESH

  • NONE

  • mostDisruptiveAllowedAction - (Optional) The most disruptive action to perform on the instance during an update. Default is replace. Possible values are:

  • REPLACE

  • RESTART

  • REFRESH

  • NONE

  • removeInstanceStateOnDestroy - (Optional) When true, deleting this config will immediately remove any specified state from the underlying instance. When false, deleting this config will not immediately remove any state from the underlying instance. State will be removed on the next instance recreation or update.

The preservedState block supports:

  • metadata - (Optional) Preserved metadata defined for this instance. This is a list of key->value pairs.

  • disk - (Optional) Stateful disks for the instance. Structure is documented below.

  • internalIp - (Optional, Beta) Preserved internal IPs defined for this instance. This map is keyed with the name of the network interface. Structure is documented below.

  • externalIp - (Optional, Beta) Preserved external IPs defined for this instance. This map is keyed with the name of the network interface. Structure is documented below.

The disk block supports:

  • deviceName - (Required) A unique device name that is reflected into the /dev/ tree of a Linux operating system running within the instance.

  • source - (Required) The URI of an existing persistent disk to attach under the specified device-name in the format projects/projectId/zones/zone/disks/diskName.

  • mode - (Optional) The mode of the disk. Default value is readWrite. Possible values are readOnly and readWrite.

  • deleteRule - (Optional) A value that prescribes what should happen to the stateful disk when the VM instance is deleted. The available options are never and onPermanentInstanceDeletion. never - detach the disk when the VM is deleted, but do not delete the disk. onPermanentInstanceDeletion will delete the stateful disk when the VM is permanently deleted from the instance group. Default value is never. Possible values are never and onPermanentInstanceDeletion.

The internalIp block supports:

  • interfaceName - (Required) The identifier for this object. Format specified above.

  • autoDelete - (Optional) These stateful IPs will never be released during autohealing, update or VM instance recreate operations. This flag is used to configure if the IP reservation should be deleted after it is no longer used by the group, e.g. when the given instance or the whole group is deleted. Default value is never. Possible values are never and onPermanentInstanceDeletion.

  • ipAddress - (Optional) Ip address representation Structure is documented below.

The ipAddress block supports:

  • address - (Optional) The URL of the reservation for this IP address.

The externalIp block supports:

  • interfaceName - (Required) The identifier for this object. Format specified above.

  • autoDelete - (Optional) These stateful IPs will never be released during autohealing, update or VM instance recreate operations. This flag is used to configure if the IP reservation should be deleted after it is no longer used by the group, e.g. when the given instance or the whole group is deleted. Default value is never. Possible values are never and onPermanentInstanceDeletion.

  • ipAddress - (Optional) Ip address representation Structure is documented below.

The ipAddress block supports:

  • address - (Optional) The URL of the reservation for this IP address.

Attributes Reference

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

  • id - an identifier for the resource with format {{project}}/{{region}}/{{regionInstanceGroupManager}}/{{name}}

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

RegionPerInstanceConfig can be imported using any of these accepted formats:

$ terraform import google_compute_region_per_instance_config.default projects/{{project}}/regions/{{region}}/instanceGroupManagers/{{region_instance_group_manager}}/{{name}}
$ terraform import google_compute_region_per_instance_config.default {{project}}/{{region}}/{{region_instance_group_manager}}/{{name}}
$ terraform import google_compute_region_per_instance_config.default {{region}}/{{region_instance_group_manager}}/{{name}}
$ terraform import google_compute_region_per_instance_config.default {{region_instance_group_manager}}/{{name}}

User Project Overrides

This resource supports User Project Overrides.