|
1 | 1 | package ovh
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "fmt"
|
5 | 6 | "log"
|
6 | 7 | "net/url"
|
| 8 | + "time" |
7 | 9 |
|
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" |
8 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
| 12 | + "github.com/ovh/go-ovh/ovh" |
9 | 13 | "github.com/ovh/terraform-provider-ovh/ovh/helpers"
|
10 | 14 | )
|
11 | 15 |
|
@@ -182,19 +186,31 @@ func resourceCloudProjectFailoverIpAttachCreate(d *schema.ResourceData, meta int
|
182 | 186 | url.PathEscape(id),
|
183 | 187 | )
|
184 | 188 |
|
185 |
| - ip := &FailoverIp{} |
186 |
| - if err := config.OVHClient.Post(endpoint, opts, ip); err != nil { |
187 |
| - return fmt.Errorf("calling Post %s: %q", endpoint, err) |
188 |
| - } |
| 189 | + retry.RetryContext(context.Background(), 5*time.Minute, func() *retry.RetryError { |
| 190 | + ip := &FailoverIp{} |
| 191 | + if err := config.OVHClient.Post(endpoint, opts, ip); err != nil { |
| 192 | + // Retry 400 errors because it can mean that the instance IP |
| 193 | + // is not yet allocated internally. |
| 194 | + ovhError, isOvhApiError := err.(*ovh.APIError) |
| 195 | + if isOvhApiError && ovhError.Code == 400 { |
| 196 | + log.Printf("[INFO] container registry id %s on project %s deleted", id, serviceName) |
| 197 | + return retry.RetryableError(fmt.Errorf("error calling POST %s: %q", endpoint, err)) |
| 198 | + } else { |
| 199 | + return retry.NonRetryableError(fmt.Errorf("failed to attach failover IP: %s", err)) |
| 200 | + } |
| 201 | + } |
189 | 202 |
|
190 |
| - for k, v := range ip.ToMap() { |
191 |
| - if k != "id" { |
192 |
| - err := d.Set(k, v) |
193 |
| - if err != nil { |
194 |
| - return err |
| 203 | + for k, v := range ip.ToMap() { |
| 204 | + if k != "id" { |
| 205 | + err := d.Set(k, v) |
| 206 | + if err != nil { |
| 207 | + return retry.NonRetryableError(err) |
| 208 | + } |
195 | 209 | }
|
196 | 210 | }
|
197 |
| - } |
| 211 | + |
| 212 | + return nil |
| 213 | + }) |
198 | 214 |
|
199 | 215 | for d.Get("status").(string) == "operationPending" {
|
200 | 216 | if err := resourceCloudProjectFailoverIpAttachRead(d, meta); err != nil {
|
|
0 commit comments