Skip to content

googleComputeInstanceGroupManager

The Google Compute Engine Instance Group Manager API creates and manages pools of homogeneous Compute Engine virtual machine instances from a common instance template. For more information, see the official documentation and API

\~> Note: Use google_compute_region_instance_group_manager to create a regional (multi-zone) instance group manager.

Example Usage with top level instance template (google provider)

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeHealthCheckAutohealing =
  new google.computeHealthCheck.ComputeHealthCheck(this, "autohealing", {
    check_interval_sec: 5,
    healthy_threshold: 2,
    http_health_check: [
      {
        port: "8080",
        request_path: "/healthz",
      },
    ],
    name: "autohealing-health-check",
    timeout_sec: 5,
    unhealthy_threshold: 10,
  });
new google.computeInstanceGroupManager.ComputeInstanceGroupManager(
  this,
  "appserver",
  {
    all_instances_config: [
      {
        labels: [
          {
            label_key: "label_value",
          },
        ],
        metadata: [
          {
            metadata_key: "metadata_value",
          },
        ],
      },
    ],
    auto_healing_policies: [
      {
        health_check: googleComputeHealthCheckAutohealing.id,
        initial_delay_sec: 300,
      },
    ],
    base_instance_name: "app",
    name: "appserver-igm",
    named_port: [
      {
        name: "customhttp",
        port: 8888,
      },
    ],
    target_pools: ["${google_compute_target_pool.appserver.id}"],
    target_size: 2,
    version: [
      {
        instance_template: "${google_compute_instance_template.appserver.id}",
      },
    ],
    zone: "us-central1-a",
  }
);

Example Usage with multiple versions (googleBeta provider)

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeInstanceGroupManager.ComputeInstanceGroupManager(
  this,
  "appserver",
  {
    base_instance_name: "app",
    name: "appserver-igm",
    provider: "${google-beta}",
    target_size: 5,
    version: [
      {
        instance_template: "${google_compute_instance_template.appserver.id}",
        name: "appserver",
      },
      {
        instance_template:
          "${google_compute_instance_template.appserver-canary.id}",
        name: "appserver-canary",
        target_size: [
          {
            fixed: 1,
          },
        ],
      },
    ],
    zone: "us-central1-a",
  }
);

Argument Reference

The following arguments are supported:

  • baseInstanceName - (Required) The base instance name to use for instances in this group. The value must be a valid RFC1035 name. Supported characters are lowercase letters, numbers, and hyphens (-). Instances are named by appending a hyphen and a random four-character string to the base instance name.

  • version - (Required) Application versions managed by this instance group. Each version deals with a specific instance template, allowing canary release scenarios. Structure is documented below.

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

  • zone - (Required) The zone that instances in this group should be created in.


  • description - (Optional) An optional textual description of the instance group manager.

  • namedPort - (Optional) The named port configuration. See the section below for details on configuration.

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

  • targetSize - (Optional) The target number of running instances for this managed instance group. This value should always be explicitly set unless this resource is attached to an autoscaler, in which case it should never be set. Defaults to 0.

  • listManagedInstancesResults - (Optional) Pagination behavior of the listManagedInstances API method for this managed instance group. Valid values are: pageless, paginated. If pageless (default), Pagination is disabled for the group's listManagedInstances API method. maxResults and pageToken query parameters are ignored and all instances are returned in a single response. If paginated, pagination is enabled, maxResults and pageToken query parameters are respected.

  • targetPools - (Optional) The full URL of all target pools to which new instances in the group are added. Updating the target pools attribute does not affect existing instances.

  • waitForInstances - (Optional) Whether to wait for all instances to be created/updated before returning. Note that if this is set to true and the operation does not succeed, Terraform will continue trying until it times out.

  • waitForInstancesStatus - (Optional) When used with waitForInstances it specifies the status to wait for. When stable is specified this resource will wait until the instances are stable before returning. When updated is set, it will wait for the version target to be reached and any per instance configs to be effective as well as all instances to be stable before returning. The possible values are stable and updated


  • autoHealingPolicies - (Optional) The autohealing policies for this managed instance group. You can specify only one value. Structure is documented below. For more information, see the official documentation.

  • allInstancesConfig - (Optional, Beta) Properties to set on all instances in the group. After setting allInstancesConfig on the group, you must update the group's instances to apply the configuration.

  • statefulDisk - (Optional) Disks created on the instances that will be preserved on instance delete, update, etc. Structure is documented below. For more information see the official documentation.

  • statefulInternalIp - (Optional, Beta) Internal network IPs assigned to the instances that will be preserved on instance delete, update, etc. This map is keyed with the network interface name. Structure is documented below.

  • statefulExternalIp - (Optional, Beta) External network IPs assigned to the instances that will be preserved on instance delete, update, etc. This map is keyed with the network interface name. Structure is documented below.

  • updatePolicy - (Optional) The update policy for this managed instance group. Structure is documented below. For more information, see the official documentation and API


The updatePolicy block supports:

update_policy {
  type                           = "PROACTIVE"
  minimal_action                 = "REPLACE"
  most_disruptive_allowed_action = "REPLACE"
  max_surge_percent              = 20
  max_unavailable_fixed          = 2
  min_ready_sec                  = 50
  replacement_method             = "RECREATE"
}
  • minimalAction - (Required) - Minimal action to be taken on an instance. You can specify either refresh to update without stopping instances, restart to restart existing instances or replace to delete and create new instances from the target template. If you specify a refresh, the Updater will attempt to perform that action only. However, if the Updater determines that the minimal action you specify is not enough to perform the update, it might perform a more disruptive action.

  • mostDisruptiveAllowedAction - (Optional) - Most disruptive action that is allowed to be taken on an instance. You can specify either NONE to forbid any actions, REFRESH to allow actions that do not need instance restart, RESTART to allow actions that can be applied without instance replacing or REPLACE to allow all possible actions. If the Updater determines that the minimal update action needed is more disruptive than most disruptive allowed action you specify it will not perform the update at all.

  • type - (Required) - The type of update process. You can specify either proactive so that the instance group manager proactively executes actions in order to bring instances to their target versions or opportunistic so that no action is proactively executed but the update will be performed as part of other actions (for example, resizes or recreateInstances calls).

  • maxSurgeFixed - (Optional), The maximum number of instances that can be created above the specified targetSize during the update process. Conflicts with maxSurgePercent. If neither is set, defaults to 1

  • maxSurgePercent - (Optional), The maximum number of instances(calculated as percentage) that can be created above the specified targetSize during the update process. Conflicts with maxSurgeFixed.

  • maxUnavailableFixed - (Optional), The maximum number of instances that can be unavailable during the update process. Conflicts with maxUnavailablePercent. If neither is set, defaults to 1

  • maxUnavailablePercent - (Optional), The maximum number of instances(calculated as percentage) that can be unavailable during the update process. Conflicts with maxUnavailableFixed.

  • minReadySec - (Optional, Beta), Minimum number of seconds to wait for after a newly created instance becomes available. This value must be from range [0, 3600]

  • replacementMethod - (Optional), The instance replacement method for managed instance groups. Valid values are: "RECREATE", "SUBSTITUTE". If SUBSTITUTE (default), the group replaces VM instances with new instances that have randomly generated names. If RECREATE, instance names are preserved. You must also set max_unavailable_fixed or max_unavailable_percent to be greater than 0.


The instanceLifecyclePolicy block supports:

instance_lifecycle_policy {
  force_update_on_repair = "YES"
}
  • forceUpdateOnRepair - (Optional, Beta), Specifies whether to apply the group's latest configuration when repairing a VM. Valid options are: yes, no. If yes and you updated the group's instance template or per-instance configurations after the VM was created, then these changes are applied when VM is repaired. If no (default), then updates are applied in accordance with the group's update policy type.

The allInstancesConfig block supports:

all_instances_config {
  metadata = {
    metadata_key = "metadata_value"
  }
  labels = {
    label_key = "label_Value"
  }
}
  • metadata - (Optional, Beta), The metadata key-value pairs that you want to patch onto the instance. For more information, see Project and instance metadata.

  • labels - (Optional, Beta), The label key-value pairs that you want to patch onto the instance.


The namedPort block supports: (Include a namedPort block for each named-port required).

  • name - (Required) The name of the port.

  • port - (Required) The port number.


The autoHealingPolicies block supports:

  • healthCheck - (Required) The health check resource that signals autohealing.

  • initialDelaySec - (Required) The number of seconds that the managed instance group waits before it applies autohealing policies to new instances or recently recreated instances. Between 0 and 3600.

The version block supports:

version {
  name              = "appserver-canary"
  instance_template = google_compute_instance_template.appserver-canary.id

  target_size {
    fixed = 1
  }
}
version {
  name              = "appserver-canary"
  instance_template = google_compute_instance_template.appserver-canary.id

  target_size {
    percent = 20
  }
}
  • name - (Required) - Version name.

  • instanceTemplate - (Required) - The full URL to an instance template from which all new instances of this version will be created.

  • targetSize - (Optional) - The number of instances calculated as a fixed number or a percentage depending on the settings. Structure is documented below.

-> Exactly one version you specify must not have a targetSize specified. During a rolling update, the instance group manager will fulfill the targetSize constraints of every other version, and any remaining instances will be provisioned with the version where targetSize is unset.

The targetSize block supports:

  • fixed - (Optional), The number of instances which are managed for this version. Conflicts with percent.

  • percent - (Optional), The number of instances (calculated as percentage) which are managed for this version. Conflicts with fixed. Note that when using percent, rounding will be in favor of explicitly set targetSize values; a managed instance group with 2 instances and 2 versions, one of which has a targetSizePercent of 60 will create 2 instances of that version.

The statefulDisk block supports: (Include a statefulDisk block for each stateful disk required).

  • deviceName - (Required), The device name of the disk to be attached.

  • 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. The default is never.

The statefulInternalIp block supports:

  • interfaceName - (Required), The network interface name of the internal Ip. Possible value: nic0

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

The statefulExternalIp block supports:

  • interfaceName - (Required), The network interface name of the external Ip. Possible value: nic0

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

Attributes Reference

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

  • id - an identifier for the resource with format projects/{{project}}/zones/{{zone}}/instanceGroupManagers/{{name}}

  • fingerprint - The fingerprint of the instance group manager.

  • instanceGroup - The full URL of the instance group created by the manager.

  • selfLink - The URL of the created resource.

  • status - The status of this managed instance group.

The status block holds:

  • isStable - A bit indicating whether the managed instance group is in a stable state. A stable state means that: none of the instances in the managed instance group is currently undergoing any type of change (for example, creation, restart, or deletion); no future changes are scheduled for instances in the managed instance group; and the managed instance group itself is not being modified.

  • versionTarget - A status of consistency of Instances' versions with their target version specified by version field on Instance Group Manager.

The versionTarget block holds:

  • versionTarget - A bit indicating whether version target has been reached in this managed instance group, i.e. all instances are in their target version. Instances' target version are specified by version field on Instance Group Manager.

  • stateful - Stateful status of the given Instance Group Manager.

The stateful block holds:

  • hasStatefulConfig - A bit indicating whether the managed instance group has stateful configuration, that is, if you have configured any items in a stateful policy or in per-instance configs. The group might report that it has no stateful config even when there is still some preserved state on a managed instance, for example, if you have deleted all PICs but not yet applied those deletions.

  • perInstanceConfigs - Status of per-instance configs on the instance.

The perInstanceConfigs block holds:

  • allEffective - A bit indicating if all of the group's per-instance configs (listed in the output of a listPerInstanceConfigs API call) have status effective or there are no per-instance-configs.

Timeouts

This resource provides the following Timeouts configuration options: configuration options:

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

Import

Instance group managers can be imported using any of these accepted formats:

$ terraform import google_compute_instance_group_manager.appserver projects/{{project}}/zones/{{zone}}/instanceGroupManagers/{{name}}
$ terraform import google_compute_instance_group_manager.appserver {{project}}/{{zone}}/{{name}}
$ terraform import google_compute_instance_group_manager.appserver {{project}}/{{name}}
$ terraform import google_compute_instance_group_manager.appserver {{name}}