Skip to content

Commit

Permalink
feat(sweeper): add billing group support (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel authored Dec 5, 2023
1 parent 82620e2 commit 187e615
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions internal/sdkprovider/service/project/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func init() {
"aiven_redis",
},
})

resource.AddTestSweepers("aiven_billing_group", &resource.Sweeper{
Name: "aiven_billing_group",
F: sweepBillingGroups(ctx, client),
Dependencies: []string{
"aiven_project",
},
})
}

func sweepProjects(ctx context.Context, client *aiven.Client) func(region string) error {
Expand Down Expand Up @@ -75,3 +83,33 @@ func sweepProjects(ctx context.Context, client *aiven.Client) func(region string
return nil
}
}

func sweepBillingGroups(ctx context.Context, client *aiven.Client) func(region string) error {
return func(region string) error {
billingGroups, err := client.BillingGroup.ListAll(ctx)
if err != nil {
return fmt.Errorf("error retrieving a list of billing groups : %s", err)
}

for _, billingGroup := range billingGroups {
if strings.Contains(billingGroup.BillingGroupName, "test-acc-") {
if err := client.BillingGroup.Delete(ctx, billingGroup.Id); err != nil {
e := err.(aiven.Error)

// billing group not found
if e.Status == 404 {
continue
}

return fmt.Errorf(
"error destroying billing group %s during sweep: %s",
billingGroup.BillingGroupName,
err,
)
}
}
}

return nil
}
}

0 comments on commit 187e615

Please sign in to comment.