-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Timeout error retries for SSM resources #8992
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,21 +164,26 @@ func resourceAwsSsmDocumentCreate(d *schema.ResourceData, meta interface{}) erro | |
} | ||
|
||
log.Printf("[DEBUG] Waiting for SSM Document %q to be created", d.Get("name").(string)) | ||
var resp *ssm.CreateDocumentOutput | ||
err := resource.Retry(5*time.Minute, func() *resource.RetryError { | ||
resp, err := ssmconn.CreateDocument(docInput) | ||
var err error | ||
resp, err = ssmconn.CreateDocument(docInput) | ||
|
||
if err != nil { | ||
return resource.NonRetryableError(err) | ||
} | ||
|
||
d.SetId(*resp.DocumentDescription.Name) | ||
return nil | ||
}) | ||
|
||
if isResourceTimeoutError(err) { | ||
resp, err = ssmconn.CreateDocument(docInput) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("Error creating SSM document: %s", err) | ||
} | ||
|
||
d.SetId(*resp.DocumentDescription.Name) | ||
|
||
if v, ok := d.GetOk("permissions"); ok && v != nil { | ||
if err := setDocumentPermissions(d, meta); err != nil { | ||
return err | ||
|
@@ -369,6 +374,11 @@ func resourceAwsSsmDocumentDelete(d *schema.ResourceData, meta interface{}) erro | |
|
||
return resource.RetryableError(fmt.Errorf("SSM Document (%s) still exists", d.Id())) | ||
}) | ||
if isResourceTimeoutError(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woo! Okay this one is strange currently, let's fix it! The So maybe this logic can look something like: input := &ssm.DescribeDocumentInput{
Name: aws.String(d.Get("name").(string)),
}
log.Printf("[DEBUG] Waiting for SSM Document %q to be deleted", d.Get("name").(string))
err = resource.Retry(10*time.Minute, func() *resource.RetryError {
_, err := ssmconn.DescribeDocument(input)
if isAWSErr(err, ssm.ErrCodeInvalidDocument, "") {
return nil
}
if err != nil {
return resource.NonRetryableError(err)
}
return resource.RetryableError(fmt.Errorf("SSM Document (%s) still exists", d.Id()))
})
if isResourceTimeoutError(err) {
_, err = ssmconn.DescribeDocument(input)
}
if isAWSErr(err, ssm.ErrCodeInvalidDocument, "") {
return nil
}
if err != nil {
return fmt.Errorf("error waiting for SSM Document (%s) deletion: %s", d.Id(), err)
} Please reach out if you have any questions 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bflad gotcha! Pushed an update to this, but I am left with one question. After the retry, we return nil if it was an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aye, that's the rabbit hole with this type of deletion logic. You are correct that it should probably return an error indicating if the document was still found, but up to you if you'd like to implement that now this logic is considered best effort. 😅 |
||
_, err = ssmconn.DescribeDocument(&ssm.DescribeDocumentInput{ | ||
Name: aws.String(d.Get("name").(string)), | ||
}) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("error waiting for SSM Document (%s) deletion: %s", d.Id(), err) | ||
} | ||
|
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.
😍