Skip to content

Commit

Permalink
fix a permadiff (GoogleCloudPlatform#5322)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmedia authored Oct 14, 2021
1 parent 51bb6c0 commit f411d0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `An optional textual description of the instance group manager.`,
},

Expand Down Expand Up @@ -673,6 +672,12 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte
}
var change bool

if d.HasChange("description") {
updatedManager.Description = d.Get("description").(string)
updatedManager.ForceSendFields = append(updatedManager.ForceSendFields, "Description")
change = true
}

if d.HasChange("target_pools") {
updatedManager.TargetPools = convertStringSet(d.Get("target_pools").(*schema.Set))
updatedManager.ForceSendFields = append(updatedManager.ForceSendFields, "TargetPools")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
target2 := fmt.Sprintf("tf-test-igm-%s", randString(t, 10))
template2 := fmt.Sprintf("tf-test-igm-%s", randString(t, 10))
igm := fmt.Sprintf("tf-test-igm-%s", randString(t, 10))
description := "Manager 1"
description2 := "Manager 2"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceGroupManagerDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccInstanceGroupManager_update(template1, target1, igm),
Config: testAccInstanceGroupManager_update(template1, target1, description, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
Expand All @@ -147,7 +149,7 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
ImportStateVerifyIgnore: []string{"status"},
},
{
Config: testAccInstanceGroupManager_update2(template1, target1, target2, template2, igm),
Config: testAccInstanceGroupManager_update2(template1, target1, target2, template2, description, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
Expand All @@ -156,7 +158,7 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
ImportStateVerifyIgnore: []string{"status"},
},
{
Config: testAccInstanceGroupManager_update3(template1, target1, target2, template2, igm),
Config: testAccInstanceGroupManager_update3(template1, target1, target2, template2, description2, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
Expand Down Expand Up @@ -555,7 +557,7 @@ resource "google_compute_instance_group_manager" "igm-basic" {
`, template, igm)
}

func testAccInstanceGroupManager_update(template, target, igm string) string {
func testAccInstanceGroupManager_update(template, target, description, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
Expand Down Expand Up @@ -590,7 +592,7 @@ resource "google_compute_target_pool" "igm-update" {
}
resource "google_compute_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
description = "%s"
name = "%s"
version {
Expand All @@ -607,11 +609,11 @@ resource "google_compute_instance_group_manager" "igm-update" {
port = 8080
}
}
`, template, target, igm)
`, template, target, description, igm)
}

// Change IGM's instance template and target size
func testAccInstanceGroupManager_update2(template1, target1, target2, template2, igm string) string {
func testAccInstanceGroupManager_update2(template1, target1, target2, template2, description, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
Expand Down Expand Up @@ -673,7 +675,7 @@ resource "google_compute_instance_template" "igm-update2" {
}
resource "google_compute_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
description = "%s"
name = "%s"
version {
Expand All @@ -697,11 +699,11 @@ resource "google_compute_instance_group_manager" "igm-update" {
port = 8443
}
}
`, template1, target1, target2, template2, igm)
`, template1, target1, target2, template2, description, igm)
}

// Remove target pools
func testAccInstanceGroupManager_update3(template1, target1, target2, template2, igm string) string {
func testAccInstanceGroupManager_update3(template1, target1, target2, template2, description2, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
Expand Down Expand Up @@ -763,7 +765,7 @@ resource "google_compute_instance_template" "igm-update2" {
}
resource "google_compute_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
description = "%s"
name = "%s"
version {
Expand All @@ -783,7 +785,7 @@ resource "google_compute_instance_group_manager" "igm-update" {
port = 8443
}
}
`, template1, target1, target2, template2, igm)
`, template1, target1, target2, template2, description2, igm)
}

func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string {
Expand Down

0 comments on commit f411d0c

Please sign in to comment.