|
1 | 1 | package account_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 | accountSDK "github.com/scaleway/scaleway-sdk-go/api/account/v3" |
@@ -101,29 +104,31 @@ func isProjectPresent(tt *acctest.TestTools, name string) resource.TestCheckFunc |
101 | 104 | } |
102 | 105 |
|
103 | 106 | func isProjectDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { |
104 | | - return func(s *terraform.State) error { |
105 | | - for _, rs := range s.RootModule().Resources { |
106 | | - if rs.Type != "scaleway_account_project" { |
107 | | - continue |
108 | | - } |
| 107 | + return func(state *terraform.State) error { |
| 108 | + ctx := context.Background() |
| 109 | + api := account.NewProjectAPI(tt.Meta) |
109 | 110 |
|
110 | | - accountAPI := account.NewProjectAPI(tt.Meta) |
| 111 | + return retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError { |
| 112 | + for _, rs := range state.RootModule().Resources { |
| 113 | + if rs.Type != "scaleway_account_project" { |
| 114 | + continue |
| 115 | + } |
111 | 116 |
|
112 | | - _, err := accountAPI.GetProject(&accountSDK.ProjectAPIGetProjectRequest{ |
113 | | - ProjectID: rs.Primary.ID, |
114 | | - }) |
| 117 | + _, err := api.GetProject(&accountSDK.ProjectAPIGetProjectRequest{ |
| 118 | + ProjectID: rs.Primary.ID, |
| 119 | + }) |
115 | 120 |
|
116 | | - // If no error resource still exist |
117 | | - if err == nil { |
118 | | - return fmt.Errorf("resource %s(%s) still exist", rs.Type, rs.Primary.ID) |
| 121 | + switch { |
| 122 | + case err == nil: |
| 123 | + return retry.RetryableError(fmt.Errorf("resource %s(%s) still exists", rs.Type, rs.Primary.ID)) |
| 124 | + case httperrors.Is404(err): |
| 125 | + continue |
| 126 | + default: |
| 127 | + return retry.NonRetryableError(err) |
| 128 | + } |
119 | 129 | } |
120 | 130 |
|
121 | | - // Unexpected api error we return it |
122 | | - if !httperrors.Is404(err) { |
123 | | - return err |
124 | | - } |
125 | | - } |
126 | | - |
127 | | - return nil |
| 131 | + return nil |
| 132 | + }) |
128 | 133 | } |
129 | 134 | } |
0 commit comments