Skip to content

Commit

Permalink
Merge pull request #8992 from terraform-providers/rfd-retry-ssm
Browse files Browse the repository at this point in the history
Timeout error retries for SSM resources
  • Loading branch information
ryndaniels authored Jun 19, 2019
2 parents 024499f + ae5d8c7 commit d92923f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
39 changes: 23 additions & 16 deletions aws/resource_aws_ssm_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -348,31 +353,33 @@ func resourceAwsSsmDocumentDelete(d *schema.ResourceData, meta interface{}) erro
return err
}

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(&ssm.DescribeDocumentInput{
Name: aws.String(d.Get("name").(string)),
})
_, err := ssmconn.DescribeDocument(input)

if err != nil {
awsErr, ok := err.(awserr.Error)
if !ok {
return resource.NonRetryableError(err)
}

if awsErr.Code() == "InvalidDocument" {
return nil
}
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)
}

return nil
}

Expand Down
11 changes: 7 additions & 4 deletions aws/resource_aws_ssm_resource_data_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func resourceAwsSsmResourceDataSync() *schema.Resource {

func resourceAwsSsmResourceDataSyncCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ssmconn
input := &ssm.CreateResourceDataSyncInput{
S3Destination: expandSsmResourceDataSyncS3Destination(d),
SyncName: aws.String(d.Get("name").(string)),
}

err := resource.Retry(1*time.Minute, func() *resource.RetryError {
input := &ssm.CreateResourceDataSyncInput{
S3Destination: expandSsmResourceDataSyncS3Destination(d),
SyncName: aws.String(d.Get("name").(string)),
}
_, err := conn.CreateResourceDataSync(input)
if err != nil {
if isAWSErr(err, ssm.ErrCodeResourceDataSyncInvalidConfigurationException, "S3 write failed for bucket") {
Expand All @@ -82,6 +82,9 @@ func resourceAwsSsmResourceDataSyncCreate(d *schema.ResourceData, meta interface
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.CreateResourceDataSync(input)
}

if err != nil {
return err
Expand Down

0 comments on commit d92923f

Please sign in to comment.