Skip to content

Commit

Permalink
Add test sweeper
Browse files Browse the repository at this point in the history
  • Loading branch information
asaha2 committed Dec 5, 2024
1 parent c2db11d commit c757f07
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions digitalocean/dropletautoscale/sweep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dropletautoscale

import (
"context"
"log"
"strings"

"github.com/digitalocean/godo"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/config"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/sweep"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func init() {
resource.AddTestSweepers("digitalocean_droplet_autoscale", &resource.Sweeper{
Name: "digitalocean_droplet_autoscale",
F: sweepDropletAutoscale,
})
}

func sweepDropletAutoscale(region string) error {
meta, err := sweep.SharedConfigForRegion(region)
if err != nil {
return err
}
client := meta.(*config.CombinedConfig).GodoClient()
pools, _, err := client.DropletAutoscale.List(context.Background(), &godo.ListOptions{PerPage: 200})
if err != nil {
return err
}
for _, pool := range pools {
if strings.HasPrefix(pool.Name, sweep.TestNamePrefix) {
log.Printf("Destroying droplet autoscale pool %s", pool.Name)
if _, err = client.DropletAutoscale.DeleteDangerous(context.Background(), pool.ID); err != nil {
return err
}
}
}
return nil
}

0 comments on commit c757f07

Please sign in to comment.