googleComputeRegionInstanceGroupManager
The Google Compute Engine Regional Instance Group Manager API creates and manages pools of homogeneous Compute Engine virtual machine instances from a common instance template.
To get more information about regionInstanceGroupManagers, see:
- API documentation
- How-to Guides
- Regional Instance Groups Guide
\~> Note: Use google_compute_instance_group_manager to create a zonal 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.computeRegionInstanceGroupManager.ComputeRegionInstanceGroupManager(
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",
distribution_policy_zones: ["us-central1-a", "us-central1-f"],
name: "appserver-igm",
named_port: [
{
name: "custom",
port: 8888,
},
],
region: "us-central1",
target_pools: ["${google_compute_target_pool.appserver.id}"],
target_size: 2,
version: [
{
instance_template: "${google_compute_instance_template.appserver.id}",
},
],
}
);
Example Usage with multiple versions
/*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.computeRegionInstanceGroupManager.ComputeRegionInstanceGroupManager(
this,
"appserver",
{
base_instance_name: "app",
name: "appserver-igm",
region: "us-central1",
target_size: 5,
version: [
{
instance_template: "${google_compute_instance_template.appserver.id}",
},
{
instance_template:
"${google_compute_instance_template.appserver-canary.id}",
target_size: [
{
fixed: 1,
},
],
},
],
}
);
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. -
region
- (Optional) The region where the managed instance group resides. If not provided, the provider region is used.
-
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 to0
. -
listManagedInstancesResults
- (Optional) Pagination behavior of thelistManagedInstances
API method for this managed instance group. Valid values are:pageless
,paginated
. Ifpageless
(default), Pagination is disabled for the group'slistManagedInstances
API method.maxResults
andpageToken
query parameters are ignored and all instances are returned in a single response. Ifpaginated
, pagination is enabled,maxResults
andpageToken
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 withwaitForInstances
it specifies the status to wait for. Whenstable
is specified this resource will wait until the instances are stable before returning. Whenupdated
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 arestable
andupdated
-
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. -
updatePolicy
- (Optional) The update policy for this managed instance group. Structure is documented below. For more information, see the official documentation and API -
distributionPolicyZones
- (Optional) The distribution policy for this managed instance group. You can specify one or more values. For more information, see the official documentation. -
distributionPolicyTargetShape
- (Optional) The shape to which the group converges either proactively or on resize events (depending on the value set in update_policy.0.instance_redistribution_type). For more information see the official documentation. -
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. Proactive cross zone instance redistribution must be disabled before you can update stateful disks on existing instance group managers. This can be controlled via theupdatePolicy
. -
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.
The updatePolicy
block supports:
update_policy {
type = "PROACTIVE"
instance_redistribution_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 eitherrefresh
to update without stopping instances,restart
to restart existing instances orreplace
to delete and create new instances from the target template. If you specify arefresh
, 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 eitherproactive
so that the instance group manager proactively executes actions in order to bring instances to their target versions oropportunistic
so that no action is proactively executed but the update will be performed as part of other actions (for example, resizes or recreateInstances calls). -
instanceRedistributionType
- (Optional) - The instance redistribution policy for regional managed instance groups. Valid values are:"proactive"
,"none"
. Ifproactive
(default), the group attempts to maintain an even distribution of VM instances across zones in the region. Ifnone
, proactive redistribution is disabled. -
maxSurgeFixed
- (Optional), The maximum number of instances that can be created above the specified targetSize during the update process. Conflicts withmaxSurgePercent
. It has to be either 0 or at least equal to the number of zones. If fixed values are used, at least one ofmaxUnavailableFixed
ormaxSurgeFixed
must be greater than 0. -
maxSurgePercent
- (Optional), The maximum number of instances(calculated as percentage) that can be created above the specified targetSize during the update process. Conflicts withmaxSurgeFixed
. Percent value is only allowed for regional managed instance groups with size at least 10. -
maxUnavailableFixed
- (Optional), The maximum number of instances that can be unavailable during the update process. Conflicts withmaxUnavailablePercent
. It has to be either 0 or at least equal to the number of zones. If fixed values are used, at least one ofmaxUnavailableFixed
ormaxSurgeFixed
must be greater than 0. -
maxUnavailablePercent
- (Optional), The maximum number of instances(calculated as percentage) that can be unavailable during the update process. Conflicts withmaxUnavailableFixed
. Percent value is only allowed for regional managed instance groups with size at least 10. -
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:
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.
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 withpercent
. -
percent
- (Optional), The number of instances (calculated as percentage) which are managed for this version. Conflicts withfixed
. Note that when usingpercent
, rounding will be in favor of explicitly settargetSize
values; a managed instance group with 2 instances and 2version
s, one of which has atargetSizePercent
of60
will create 2 instances of thatversion
.
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 arenever
andonPermanentInstanceDeletion
.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 isnever
.
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 arenever
andonPermanentInstanceDeletion
.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 arenever
andonPermanentInstanceDeletion
.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{{diskName}}
-
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.
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 statuseffective
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 the name
, e.g.