Skip to content

Commit dcabe38

Browse files
abhinavdahiyajhixson74
authored andcommitted
gcp: destroy instance groups
1 parent f3679ca commit dcabe38

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

pkg/destroy/bootstrap/bootstrap.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func Destroy(dir string) (err error) {
5454
switch platform {
5555
case gcp.Name:
5656
// First remove the bootstrap from LB target and its instance so that bootstrap module is cleanly destroyed.
57+
fmt.Println("RUNNING TF APPLY GCP_BOOTSTRAP_ENABLED FALSE")
5758
_, err = terraform.Apply(tempDir, platform, append(extraArgs, "-var=gcp_bootstrap_enabled=false")...)
5859
if err != nil {
5960
return errors.Wrap(err, "Terraform apply")

pkg/destroy/gcp/compute.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ func (o *ClusterUninstaller) deleteInstanceGroup(ig nameAndZone) error {
111111
return nil
112112
}
113113

114+
// destroyInstanceGroups searches for instance groups across all zones that have a name that starts with
115+
// the infra ID prefix, and then deletes each instance found.
116+
func (o *ClusterUninstaller) destroyInstanceGroups() error {
117+
groups, err := o.listInstanceGroupsWithFilter(o.clusterIDFilter())
118+
if err != nil {
119+
return err
120+
}
121+
errs := []error{}
122+
found := make([]string, 0, len(groups))
123+
for _, group := range groups {
124+
found = append(found, fmt.Sprintf("%s/%s", group.zone, group.name))
125+
err := o.deleteInstanceGroup(group)
126+
if err != nil {
127+
errs = append(errs, err)
128+
}
129+
}
130+
deletedItems := o.setPendingItems("computeinstancegroup", found)
131+
for _, item := range deletedItems {
132+
o.Logger.Infof("Deleted instance group %s", item)
133+
}
134+
return aggregateError(errs, len(found))
135+
}
136+
114137
func (o *ClusterUninstaller) listComputeInstances() ([]nameAndZone, error) {
115138
o.Logger.Debugf("Listing compute instances")
116139
result := []nameAndZone{}

pkg/destroy/gcp/gcp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func (o *ClusterUninstaller) destroyCluster() (bool, error) {
134134
{name: "Firewalls", destroy: o.destroyFirewalls},
135135
{name: "Addresses", destroy: o.destroyAddresses},
136136
{name: "Target Pools", destroy: o.destroyTargetPools},
137+
{name: "Compute instance groups", destroy: o.destroyInstanceGroups},
137138
{name: "Forwarding rules", destroy: o.destroyForwardingRules},
138139
{name: "Backend services", destroy: o.destroyBackendServices},
139140
{name: "Health checks", destroy: o.destroyHealthChecks},

0 commit comments

Comments
 (0)