From d13766b76d18aaacf14d2e18ffce2bd510318e93 Mon Sep 17 00:00:00 2001 From: upodroid Date: Wed, 23 Dec 2020 22:26:10 +0000 Subject: [PATCH 1/3] add dpts to RIGM Co-authored-by: upodroid --- ...e_compute_region_instance_group_manager.go | 26 ++++++++++++++----- ...pute_region_instance_group_manager_test.go | 9 ++++--- ...egion_instance_group_manager.html.markdown | 13 +++++++--- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/third_party/terraform/resources/resource_compute_region_instance_group_manager.go b/third_party/terraform/resources/resource_compute_region_instance_group_manager.go index 1402227d0313..a99a078ee83f 100644 --- a/third_party/terraform/resources/resource_compute_region_instance_group_manager.go +++ b/third_party/terraform/resources/resource_compute_region_instance_group_manager.go @@ -212,6 +212,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, @@ -343,7 +351,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"}, @@ -464,6 +472,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) } @@ -714,13 +725,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, @@ -728,7 +741,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/third_party/terraform/tests/resource_compute_region_instance_group_manager_test.go b/third_party/terraform/tests/resource_compute_region_instance_group_manager_test.go index 9cb7f5f67aec..184c53cfe498 100644 --- a/third_party/terraform/tests/resource_compute_region_instance_group_manager_test.go +++ b/third_party/terraform/tests/resource_compute_region_instance_group_manager_test.go @@ -1058,10 +1058,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/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown b/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown index bbda21f0fa9d..fe08a9633df4 100644 --- a/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/third_party/terraform/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 + * [Access Policy 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). + * `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`. - - - From ffa6193af7e657af4647676bfdb3c7175818299f Mon Sep 17 00:00:00 2001 From: upodroid Date: Wed, 23 Dec 2020 22:30:31 +0000 Subject: [PATCH 2/3] typo fix --- .../docs/r/compute_region_instance_group_manager.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown b/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown index fe08a9633df4..36ffd5f75f19 100644 --- a/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown @@ -17,7 +17,7 @@ To get more information about regionInstanceGroupManagers, see: * [API documentation](https://cloud.google.com/compute/docs/reference/latest/regionInstanceGroupManagers) * How-to Guides - * [Access Policy Guide](https://cloud.google.com/compute/docs/instance-groups/distributing-instances-with-regional-instance-groups) + * [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. From dddd7286cc197c95ddb61205bfcffb54c53cddc3 Mon Sep 17 00:00:00 2001 From: upodroid Date: Wed, 20 Jan 2021 22:03:04 +0000 Subject: [PATCH 3/3] add doc note --- .../docs/r/compute_region_instance_group_manager.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown b/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown index 36ffd5f75f19..6d7550ea9f3c 100644 --- a/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown +++ b/third_party/terraform/website/docs/r/compute_region_instance_group_manager.html.markdown @@ -143,7 +143,7 @@ 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). +* `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`.