diff --git a/.changelog/4348.txt b/.changelog/4348.txt new file mode 100644 index 00000000000..cf3f7ba19e9 --- /dev/null +++ b/.changelog/4348.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: added `distribution_policy_target_shape` field to `google_compute_region_instance_group_manager` resource +``` diff --git a/google/resource_compute_region_instance_group_manager.go b/google/resource_compute_region_instance_group_manager.go index f9405810cb2..f8daab1452b 100644 --- a/google/resource_compute_region_instance_group_manager.go +++ b/google/resource_compute_region_instance_group_manager.go @@ -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, @@ -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"}, @@ -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) } @@ -716,13 +727,15 @@ 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, @@ -730,7 +743,8 @@ func expandDistributionPolicy(configured *schema.Set) *computeBeta.DistributionP distributionPolicyZoneConfigs = append(distributionPolicyZoneConfigs, &distributionPolicyZoneConfig) } - return &computeBeta.DistributionPolicy{Zones: distributionPolicyZoneConfigs} + + return &computeBeta.DistributionPolicy{Zones: distributionPolicyZoneConfigs, TargetShape: dpts} } func flattenDistributionPolicy(distributionPolicy *computeBeta.DistributionPolicy) []string { diff --git a/google/resource_compute_region_instance_group_manager_test.go b/google/resource_compute_region_instance_group_manager_test.go index b7222eb7519..9f132a09e00 100644 --- a/google/resource_compute_region_instance_group_manager_test.go +++ b/google/resource_compute_region_instance_group_manager_test.go @@ -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, "\",\"")) } diff --git a/website/docs/r/compute_region_instance_group_manager.html.markdown b/website/docs/r/compute_region_instance_group_manager.html.markdown index ef4bf7e1c42..d0b12ea2c3e 100644 --- a/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/website/docs/r/compute_region_instance_group_manager.html.markdown @@ -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) @@ -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`. - - -