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

allow updating (R)IGM target pools to empty #6492

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/3581.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed issue where removing all target pools from `google_compute_instance_group_manager` or `google_compute_region_instance_group_manager` had no effect
```
1 change: 1 addition & 0 deletions google/resource_compute_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ func resourceComputeInstanceGroupManagerUpdate(d *schema.ResourceData, meta inte

if d.HasChange("target_pools") {
updatedManager.TargetPools = convertStringSet(d.Get("target_pools").(*schema.Set))
updatedManager.ForceSendFields = append(updatedManager.ForceSendFields, "TargetPools")
change = true
}

Expand Down
94 changes: 94 additions & 0 deletions google/resource_compute_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccInstanceGroupManager_update3(template1, target1, target2, template2, igm),
},
{
ResourceName: "google_compute_instance_group_manager.igm-update",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -537,6 +545,92 @@ resource "google_compute_instance_group_manager" "igm-update" {
`, template1, target1, target2, template2, igm)
}

// Remove target pools
func testAccInstanceGroupManager_update3(template1, target1, target2, template2, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
}

resource "google_compute_instance_template" "igm-update" {
name = "%s"
machine_type = "n1-standard-1"
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"
}

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}

resource "google_compute_target_pool" "igm-update" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
}

resource "google_compute_target_pool" "igm-update2" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
}

resource "google_compute_instance_template" "igm-update2" {
name = "%s"
machine_type = "n1-standard-1"
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"
}

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}

resource "google_compute_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
name = "%s"

version {
name = "prod"
instance_template = google_compute_instance_template.igm-update2.self_link
}

base_instance_name = "igm-update"
zone = "us-central1-c"
target_size = 3
named_port {
name = "customhttp"
port = 8080
}
named_port {
name = "customhttps"
port = 8443
}
}
`, template1, target1, target2, template2, igm)
}

func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_region_instance_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ func resourceComputeRegionInstanceGroupManagerUpdate(d *schema.ResourceData, met

if d.HasChange("target_pools") {
updatedManager.TargetPools = convertStringSet(d.Get("target_pools").(*schema.Set))
updatedManager.ForceSendFields = append(updatedManager.ForceSendFields, "TargetPools")
change = true
}

Expand Down
94 changes: 94 additions & 0 deletions google/resource_compute_region_instance_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccRegionInstanceGroupManager_update3(template1, target1, target2, template2, igm),
},
{
ResourceName: "google_compute_region_instance_group_manager.igm-update",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -549,6 +557,92 @@ resource "google_compute_region_instance_group_manager" "igm-update" {
`, template1, target1, target2, template2, igm)
}

// Remove target pools
func testAccRegionInstanceGroupManager_update3(template1, target1, target2, template2, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
}

resource "google_compute_instance_template" "igm-update" {
name = "%s"
machine_type = "n1-standard-1"
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"
}

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}

resource "google_compute_target_pool" "igm-update" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
}

resource "google_compute_target_pool" "igm-update2" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
session_affinity = "CLIENT_IP_PROTO"
}

resource "google_compute_instance_template" "igm-update2" {
name = "%s"
machine_type = "n1-standard-1"
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"
}

service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}

resource "google_compute_region_instance_group_manager" "igm-update" {
description = "Terraform test instance group manager"
name = "%s"

version {
instance_template = google_compute_instance_template.igm-update2.self_link
name = "primary"
}

base_instance_name = "igm-update"
region = "us-central1"
target_size = 3
named_port {
name = "customhttp"
port = 8080
}
named_port {
name = "customhttps"
port = 8443
}
}
`, template1, target1, target2, template2, igm)
}

func testAccRegionInstanceGroupManager_updateLifecycle(tag, igm string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down