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

aws_route53_record: add create,update,delete timeout options for the resource #11895

Merged
merged 1 commit into from
Feb 10, 2020
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
75 changes: 23 additions & 52 deletions aws/resource_aws_route53_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ func resourceAwsRoute53RecordUpdate(d *schema.ResourceData, meta interface{}) er
},
}

req := &route53.ChangeResourceRecordSetsInput{
input := &route53.ChangeResourceRecordSetsInput{
HostedZoneId: aws.String(cleanZoneID(*zoneRecord.HostedZone.Id)),
ChangeBatch: changeBatch,
}

log.Printf("[DEBUG] Updating resource records for zone: %s, name: %s\n\n%s",
zone, *rec.Name, req)
zone, *rec.Name, input)

respRaw, err := changeRoute53RecordSet(conn, req)
respRaw, err := changeRoute53RecordSet(conn, input)
if err != nil {
return fmt.Errorf("[ERR]: Error building changeset: %s", err)
}
Expand Down Expand Up @@ -459,30 +459,24 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
}

func changeRoute53RecordSet(conn *route53.Route53, input *route53.ChangeResourceRecordSetsInput) (interface{}, error) {
wait := resource.StateChangeConf{
Pending: []string{"rejected"},
Target: []string{"accepted"},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := conn.ChangeResourceRecordSets(input)
if err != nil {
if r53err, ok := err.(awserr.Error); ok {
if r53err.Code() == "PriorRequestNotComplete" {
// There is some pending operation, so just retry
// in a bit.
return nil, "rejected", nil
}
}

return nil, "failure", err
}

return resp, "accepted", nil
},
var out *route53.ChangeResourceRecordSetsOutput
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
out, err = conn.ChangeResourceRecordSets(input)
if isAWSErr(err, "NoSuchHostedZone", "") {
log.Print("[DEBUG] Hosted Zone not found, retrying...")
return resource.RetryableError(err)
}
if err != nil {
return resource.NonRetryableError(err)
}
return nil
})
if isResourceTimeoutError(err) {
out, err = conn.ChangeResourceRecordSets(input)
}

return wait.WaitForState()
return out, err
}

func waitForRoute53RecordSetToSync(conn *route53.Route53, requestId string) error {
Expand Down Expand Up @@ -754,35 +748,12 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
}

func deleteRoute53RecordSet(conn *route53.Route53, input *route53.ChangeResourceRecordSetsInput) (interface{}, error) {
wait := resource.StateChangeConf{
Pending: []string{"rejected"},
Target: []string{"accepted"},
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := conn.ChangeResourceRecordSets(input)
if err != nil {
if r53err, ok := err.(awserr.Error); ok {
if r53err.Code() == "PriorRequestNotComplete" {
// There is some pending operation, so just retry
// in a bit.
return 42, "rejected", nil
}

if r53err.Code() == "InvalidChangeBatch" {
// This means that the record is already gone.
return resp, "accepted", nil
}
}

return 42, "failure", err
}

return resp, "accepted", nil
},
out, err := conn.ChangeResourceRecordSets(input)
if isAWSErr(err, "InvalidChangeBatch", "") {
return out, nil
}

return wait.WaitForState()
return out, err
}

func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) (*route53.ResourceRecordSet, error) {
Expand Down