|
1 | 1 | package iot_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 | iotSDK "github.com/scaleway/scaleway-sdk-go/api/iot/v1" |
@@ -109,33 +112,36 @@ func TestAccHub_Dedicated(t *testing.T) { |
109 | 112 |
|
110 | 113 | func isHubDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { |
111 | 114 | return func(state *terraform.State) error { |
112 | | - for _, rs := range state.RootModule().Resources { |
113 | | - if rs.Type != "scaleway_iot_hub" { |
114 | | - continue |
115 | | - } |
| 115 | + ctx := context.Background() |
116 | 116 |
|
117 | | - iotAPI, region, hubID, err := iot.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID) |
118 | | - if err != nil { |
119 | | - return err |
120 | | - } |
| 117 | + return retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError { |
| 118 | + for _, rs := range state.RootModule().Resources { |
| 119 | + if rs.Type != "scaleway_iot_hub" { |
| 120 | + continue |
| 121 | + } |
121 | 122 |
|
122 | | - _, err = iotAPI.GetHub(&iotSDK.GetHubRequest{ |
123 | | - Region: region, |
124 | | - HubID: hubID, |
125 | | - }) |
| 123 | + iotAPI, region, hubID, err := iot.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID) |
| 124 | + if err != nil { |
| 125 | + return retry.NonRetryableError(err) |
| 126 | + } |
126 | 127 |
|
127 | | - // If no error resource still exist |
128 | | - if err == nil { |
129 | | - return fmt.Errorf("hub (%s) still exists", rs.Primary.ID) |
130 | | - } |
| 128 | + _, err = iotAPI.GetHub(&iotSDK.GetHubRequest{ |
| 129 | + Region: region, |
| 130 | + HubID: hubID, |
| 131 | + }) |
131 | 132 |
|
132 | | - // Unexpected api error we return it |
133 | | - if !httperrors.Is404(err) { |
134 | | - return err |
| 133 | + switch { |
| 134 | + case err == nil: |
| 135 | + return retry.RetryableError(fmt.Errorf("hub (%s) still exists", rs.Primary.ID)) |
| 136 | + case httperrors.Is404(err): |
| 137 | + continue |
| 138 | + default: |
| 139 | + return retry.NonRetryableError(err) |
| 140 | + } |
135 | 141 | } |
136 | | - } |
137 | 142 |
|
138 | | - return nil |
| 143 | + return nil |
| 144 | + }) |
139 | 145 | } |
140 | 146 | } |
141 | 147 |
|
|
0 commit comments