Skip to content

Commit ec6bab3

Browse files
check if instance manager not found on delete, don't return an error (#7903) (#5614)
Signed-off-by: Modular Magician <[email protected]>
1 parent a2e39fd commit ec6bab3

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.changelog/7903.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed crash on `terraform destroy -refresh=false` for instance group managers with `wait_for_instances = "true"` if the instance group manager was not found
3+
```

google-beta/resource_compute_instance_group_manager.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package google
33
import (
44
"fmt"
55
"log"
6+
"regexp"
67
"strings"
78
"time"
89

@@ -953,6 +954,14 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte
953954
if d.Get("wait_for_instances").(bool) {
954955
err := computeIGMWaitForInstanceStatus(d, meta)
955956
if err != nil {
957+
notFound, reErr := regexp.MatchString(`not found`, err.Error())
958+
if reErr != nil {
959+
return reErr
960+
}
961+
if notFound {
962+
// manager was not found, we can exit gracefully
963+
return nil
964+
}
956965
return err
957966
}
958967
}

google-beta/resource_compute_region_instance_group_manager.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package google
33
import (
44
"fmt"
55
"log"
6+
"regexp"
67
"strings"
78
"time"
89

@@ -622,6 +623,12 @@ func waitForInstancesRefreshFunc(f getInstanceManagerFunc, waitForUpdates bool,
622623
log.Printf("[WARNING] Error in fetching manager while waiting for instances to come up: %s\n", err)
623624
return nil, "error", err
624625
}
626+
if m == nil {
627+
// getManager/getRegional manager call handleNotFoundError, which will return a nil error and nil object in the case
628+
// that the original error was a 404. if m == nil here, we will assume that it was not found return an "instance manager not found"
629+
// error so that we can parse it later on and handle it there
630+
return nil, "error", fmt.Errorf("instance manager not found")
631+
}
625632
if m.Status.IsStable {
626633
if waitForUpdates {
627634
// waitForUpdates waits for versions to be reached and per instance configs to be updated (if present)
@@ -886,6 +893,14 @@ func resourceComputeRegionInstanceGroupManagerDelete(d *schema.ResourceData, met
886893
if d.Get("wait_for_instances").(bool) {
887894
err := computeRIGMWaitForInstanceStatus(d, meta)
888895
if err != nil {
896+
notFound, reErr := regexp.MatchString(`not found`, err.Error())
897+
if reErr != nil {
898+
return reErr
899+
}
900+
if notFound {
901+
// manager was not found, we can exit gracefully
902+
return nil
903+
}
889904
return err
890905
}
891906
}

0 commit comments

Comments
 (0)