|
1 | 1 | package cockpit_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "fmt" |
5 | 6 | "testing" |
| 7 | + "time" |
6 | 8 |
|
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" |
7 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
8 | 11 | "github.com/hashicorp/terraform-plugin-testing/terraform" |
9 | 12 | cockpitSDK "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1" |
@@ -231,30 +234,35 @@ func isSourcePresent(tt *acctest.TestTools, n string) resource.TestCheckFunc { |
231 | 234 |
|
232 | 235 | func isSourceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { |
233 | 236 | return func(state *terraform.State) error { |
234 | | - for _, rs := range state.RootModule().Resources { |
235 | | - if rs.Type != "scaleway_cockpit_source" { |
236 | | - continue |
237 | | - } |
| 237 | + ctx := context.Background() |
238 | 238 |
|
239 | | - api, region, ID, err := cockpit.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID) |
240 | | - if err != nil { |
241 | | - return err |
242 | | - } |
| 239 | + return retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError { |
| 240 | + for _, rs := range state.RootModule().Resources { |
| 241 | + if rs.Type != "scaleway_cockpit_source" { |
| 242 | + continue |
| 243 | + } |
243 | 244 |
|
244 | | - _, err = api.GetDataSource(&cockpitSDK.RegionalAPIGetDataSourceRequest{ |
245 | | - Region: region, |
246 | | - DataSourceID: ID, |
247 | | - }) |
| 245 | + api, region, id, err := cockpit.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID) |
| 246 | + if err != nil { |
| 247 | + return retry.NonRetryableError(err) |
| 248 | + } |
248 | 249 |
|
249 | | - if err == nil { |
250 | | - return fmt.Errorf("cockpit source (%s) still exists", rs.Primary.ID) |
251 | | - } |
| 250 | + _, err = api.GetDataSource(&cockpitSDK.RegionalAPIGetDataSourceRequest{ |
| 251 | + Region: region, |
| 252 | + DataSourceID: id, |
| 253 | + }) |
252 | 254 |
|
253 | | - if !httperrors.Is404(err) { |
254 | | - return err |
| 255 | + switch { |
| 256 | + case err == nil: |
| 257 | + return retry.RetryableError(fmt.Errorf("cockpit source (%s) still exists", rs.Primary.ID)) |
| 258 | + case httperrors.Is404(err): |
| 259 | + continue |
| 260 | + default: |
| 261 | + return retry.NonRetryableError(err) |
| 262 | + } |
255 | 263 | } |
256 | | - } |
257 | 264 |
|
258 | | - return nil |
| 265 | + return nil |
| 266 | + }) |
259 | 267 | } |
260 | 268 | } |
0 commit comments