Skip to content

Commit

Permalink
make distribution_policy_target_shape updatable (hashicorp#8774) (has…
Browse files Browse the repository at this point in the history
…hicorp#15641)

Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Edward Sun <sunedward@google.com>
  • Loading branch information
modular-magician and Edward Sun committed Aug 25, 2023
1 parent 6c6815e commit 75f55ce
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/8774.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: removed ForceNew on `distribution_policy_target_shape` of `google_compute_region_instance_group_manager`
```
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ 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).`,
},
Expand Down Expand Up @@ -695,6 +694,11 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met
change = true
}

if d.HasChange("distribution_policy_target_shape") {
updatedManager.DistributionPolicy = expandDistributionPolicy(d)
change = true
}

if d.HasChange("update_policy") {
updatedManager.UpdatePolicy = expandRegionUpdatePolicy(d.Get("update_policy").([]interface{}))
change = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ func TestAccRegionInstanceGroupManager_distributionPolicy(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"status"},
},
{
Config: testAccRegionInstanceGroupManager_distributionPolicyUpdate(template, igm, zones),
},
{
ResourceName: "google_compute_region_instance_group_manager.igm-basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"status"},
},
},
})
}
Expand Down Expand Up @@ -1052,6 +1061,62 @@ resource "google_compute_region_instance_group_manager" "igm-basic" {
target_size = 2
distribution_policy_zones = ["%s"]
distribution_policy_target_shape = "ANY"
update_policy {
instance_redistribution_type = "NONE"
type = "OPPORTUNISTIC"
minimal_action = "REPLACE"
max_surge_fixed = 0
max_unavailable_fixed = 6
}
}
`, template, igm, strings.Join(zones, "\",\""))
}

func testAccRegionInstanceGroupManager_distributionPolicyUpdate(template, igm string, zones []string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance_template" "igm-basic" {
name = "%s"
machine_type = "e2-medium"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
boot = true
}
network_interface {
network = "default"
}
}
resource "google_compute_region_instance_group_manager" "igm-basic" {
description = "Terraform test instance group manager"
name = "%s"
version {
instance_template = google_compute_instance_template.igm-basic.self_link
name = "primary"
}
base_instance_name = "tf-test-igm-basic"
region = "us-central1"
target_size = 2
distribution_policy_zones = ["%s"]
distribution_policy_target_shape = "BALANCED"
update_policy {
instance_redistribution_type = "NONE"
type = "OPPORTUNISTIC"
minimal_action = "REPLACE"
max_surge_fixed = 0
max_unavailable_fixed = 6
}
}
`, template, igm, strings.Join(zones, "\",\""))
}
Expand Down

0 comments on commit 75f55ce

Please sign in to comment.