Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Retry failover IP attach to cloud project #785

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions ovh/resource_cloud_project_failover_ip_attach.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ovh

import (
"context"
"fmt"
"log"
"net/url"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/go-ovh/ovh"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

Expand Down Expand Up @@ -182,19 +186,31 @@ func resourceCloudProjectFailoverIpAttachCreate(d *schema.ResourceData, meta int
url.PathEscape(id),
)

ip := &FailoverIp{}
if err := config.OVHClient.Post(endpoint, opts, ip); err != nil {
return fmt.Errorf("calling Post %s: %q", endpoint, err)
}
retry.RetryContext(context.Background(), 5*time.Minute, func() *retry.RetryError {
ip := &FailoverIp{}
if err := config.OVHClient.Post(endpoint, opts, ip); err != nil {
// Retry 400 errors because it can mean that the instance IP
// is not allocated yet.
ovhError, isOvhApiError := err.(*ovh.APIError)
if isOvhApiError && ovhError.Code == 400 {
log.Printf("[INFO] container registry id %s on project %s deleted", id, serviceName)
return retry.RetryableError(fmt.Errorf("error calling POST %s: %q", endpoint, err))
} else {
return retry.NonRetryableError(fmt.Errorf("failed to attach failover IP: %s", err))
}
}

for k, v := range ip.ToMap() {
if k != "id" {
err := d.Set(k, v)
if err != nil {
return err
for k, v := range ip.ToMap() {
if k != "id" {
err := d.Set(k, v)
if err != nil {
return retry.NonRetryableError(err)
}
}
}
}

return nil
})

for d.Get("status").(string) == "operationPending" {
if err := resourceCloudProjectFailoverIpAttachRead(d, meta); err != nil {
Expand Down