-
Notifications
You must be signed in to change notification settings - Fork 626
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
Allow retries on DNS records if the record already exists #773
Allow retries on DNS records if the record already exists #773
Conversation
I couldn't come up with a unit test for this one as it relies on creating records, waiting, deleting a record and then asserting that state. I've manually completed it but can't find a sensible way of automating that. |
@@ -270,6 +271,10 @@ func resourceCloudflareRecord() *schema.Resource { | |||
Computed: true, | |||
}, | |||
}, | |||
Timeouts: &schema.ResourceTimeout{ | |||
Create: schema.DefaultTimeout(30 * time.Second), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realistically, 10-15s is probably stil more than enough 🤷♂️
Despite best efforts, occasionally Terraform's API calls will be faster than the remote API's consistency. The scenario is easiest to find when you are constantly updating similar records back and forth or changing between A/CNAME and there is a `Delete` operation involved. This results in a scenario where an end user will get failures from `terraform apply` runs that indicate the record alredy exists but moments later, is available for use. To handle this scenario a bit nicer for the user, we can attempt to automatically retry the operation for a short period of time. I've opted for 30s as that is high enough that the remote API state will be in sync but also low enough that you won't be waiting too long to find out there is an issue there if the state is as intended and you're introducing an unintended duplicate. Fixes cloudflare#750
86b84ff
to
7f04599
Compare
return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { | ||
r, err := client.CreateDNSRecord(newRecord.ZoneID, newRecord) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "already exist") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty naive matching but it covers the A/CNAME cases nicely.
Replace hard coded per_page parameter on DNS API with default
Despite best efforts, occasionally Terraform's API calls will be faster
than the remote API's consistency. The scenario is easiest to find when
you are constantly updating similar records back and forth or changing
between A/CNAME and there is a
Delete
operation involved.This results in a scenario where an end user will get failures from
terraform apply
runs that indicate the record alredy exists butmoments later, is available for use.
To handle this scenario a bit nicer for the user, we can attempt to
automatically retry the operation for a short period of time. I've opted
for 30s as that is high enough that the remote API state will be in sync
but also low enough that you won't be waiting too long to find out there
is an issue there if the state is as intended and you're introducing an
unintended duplicate.
Fixes #750