Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for capacity aware modes to `google_compute_region_instance_group_manager #8277

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4348.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `distribution_policy_target_shape` field to `google_compute_region_instance_group_manager` resource
```
26 changes: 20 additions & 6 deletions google/resource_compute_region_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ func resourceComputeRegionInstanceGroupManager() *schema.Resource {
},
},

"distribution_policy_target_shape": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: `The shape to which the group converges either proactively or on resize events (depending on the value set in updatePolicy.instanceRedistributionType).`,
},

"update_policy": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -345,7 +353,7 @@ func resourceComputeRegionInstanceGroupManagerCreate(d *schema.ResourceData, met
AutoHealingPolicies: expandAutoHealingPolicies(d.Get("auto_healing_policies").([]interface{})),
Versions: expandVersions(d.Get("version").([]interface{})),
UpdatePolicy: expandRegionUpdatePolicy(d.Get("update_policy").([]interface{})),
DistributionPolicy: expandDistributionPolicy(d.Get("distribution_policy_zones").(*schema.Set)),
DistributionPolicy: expandDistributionPolicy(d),
StatefulPolicy: expandStatefulPolicy(d.Get("stateful_disk").(*schema.Set).List()),
// Force send TargetSize to allow size of 0.
ForceSendFields: []string{"TargetSize"},
Expand Down Expand Up @@ -466,6 +474,9 @@ func resourceComputeRegionInstanceGroupManagerRead(d *schema.ResourceData, meta
if err := d.Set("distribution_policy_zones", flattenDistributionPolicy(manager.DistributionPolicy)); err != nil {
return err
}
if err := d.Set("distribution_policy_target_shape", manager.DistributionPolicy.TargetShape); err != nil {
return err
}
if err := d.Set("self_link", ConvertSelfLinkToV1(manager.SelfLink)); err != nil {
return fmt.Errorf("Error setting self_link: %s", err)
}
Expand Down Expand Up @@ -716,21 +727,24 @@ func flattenRegionUpdatePolicy(updatePolicy *computeBeta.InstanceGroupManagerUpd
return results
}

func expandDistributionPolicy(configured *schema.Set) *computeBeta.DistributionPolicy {
if configured.Len() == 0 {
func expandDistributionPolicy(d *schema.ResourceData) *computeBeta.DistributionPolicy {
dpz := d.Get("distribution_policy_zones").(*schema.Set)
dpts := d.Get("distribution_policy_target_shape").(string)
if dpz.Len() == 0 && dpts == "" {
return nil
}

distributionPolicyZoneConfigs := make([]*computeBeta.DistributionPolicyZoneConfiguration, 0, configured.Len())
for _, raw := range configured.List() {
distributionPolicyZoneConfigs := make([]*computeBeta.DistributionPolicyZoneConfiguration, 0, dpz.Len())
for _, raw := range dpz.List() {
data := raw.(string)
distributionPolicyZoneConfig := computeBeta.DistributionPolicyZoneConfiguration{
Zone: "zones/" + data,
}

distributionPolicyZoneConfigs = append(distributionPolicyZoneConfigs, &distributionPolicyZoneConfig)
}
return &computeBeta.DistributionPolicy{Zones: distributionPolicyZoneConfigs}

return &computeBeta.DistributionPolicy{Zones: distributionPolicyZoneConfigs, TargetShape: dpts}
}

func flattenDistributionPolicy(distributionPolicy *computeBeta.DistributionPolicy) []string {
Expand Down
9 changes: 5 additions & 4 deletions google/resource_compute_region_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,11 @@ resource "google_compute_region_instance_group_manager" "igm-basic" {
name = "primary"
}

base_instance_name = "igm-basic"
region = "us-central1"
target_size = 2
distribution_policy_zones = ["%s"]
base_instance_name = "igm-basic"
region = "us-central1"
target_size = 2
distribution_policy_zones = ["%s"]
distribution_policy_target_shape = "ANY"
}
`, template, igm, strings.Join(zones, "\",\""))
}
Expand Down
13 changes: 10 additions & 3 deletions website/docs/r/compute_region_instance_group_manager.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ description: |-

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. For more information, see [the official documentation](https://cloud.google.com/compute/docs/instance-groups/distributing-instances-with-regional-instance-groups)
and [API](https://cloud.google.com/compute/docs/reference/latest/regionInstanceGroupManagers)
template.

~> **Note:** Use [google_compute_instance_group_manager](/docs/providers/google/r/compute_instance_group_manager.html) to create a single-zone instance group manager.
To get more information about regionInstanceGroupManagers, see:

* [API documentation](https://cloud.google.com/compute/docs/reference/latest/regionInstanceGroupManagers)
* How-to Guides
* [Regional Instance Groups Guide](https://cloud.google.com/compute/docs/instance-groups/distributing-instances-with-regional-instance-groups)

~> **Note:** Use [google_compute_instance_group_manager](/docs/providers/google/r/compute_instance_group_manager.html) to create a zonal instance group manager.

## Example Usage with top level instance template (`google` provider)

Expand Down Expand Up @@ -138,6 +143,8 @@ group. You can specify only one value. Structure is documented below. For more i
* `distribution_policy_zones` - (Optional) The distribution policy for this managed instance
group. You can specify one or more values. For more information, see the [official documentation](https://cloud.google.com/compute/docs/instance-groups/distributing-instances-with-regional-instance-groups#selectingzones).

* `distribution_policy_target_shape` - (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](https://cloud.google.com/compute/docs/instance-groups/regional-mig-distribution-shape).

* `stateful_disk` - (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](https://cloud.google.com/compute/docs/instance-groups/configuring-stateful-disks-in-migs). Proactive cross zone instance redistribution must be disabled before you can update stateful disks on existing instance group managers. This can be controlled via the `update_policy`.

- - -
Expand Down