provider/aws: Add retry to the `aws_ssm_document` delete func

As noticed in the acceptance tests, we were expecting the document to be
deleted but it was still found

```
=== RUN   TestAccAWSSSMDocument_permission
--- FAIL: TestAccAWSSSMDocument_permission (5.60s)
    testing.go:329: Error destroying resource! WARNING: Dangling
    resources
            may exist. The full state and error is shown below.

                            Error: Check failed: Expected AWS SSM
                            Document to be gone, but was still found

                                            State: <no state>
```
This commit is contained in:
stack72 2016-10-03 16:14:15 +01:00
parent b79aea491b
commit 09e9e3a662
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
1 changed files with 32 additions and 1 deletions

View File

@ -1,12 +1,16 @@
package aws
import (
"fmt"
"log"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)
@ -215,11 +219,38 @@ func resourceAwsSsmDocumentDelete(d *schema.ResourceData, meta interface{}) erro
}
_, err := ssmconn.DeleteDocument(params)
if err != nil {
return err
}
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)),
})
if err != nil {
awsErr, ok := err.(awserr.Error)
if !ok {
return resource.NonRetryableError(err)
}
if awsErr.Code() == "InvalidDocument" {
return nil
}
return resource.NonRetryableError(err)
}
return resource.RetryableError(
fmt.Errorf("%q: Timeout while waiting for the document to be deleted", d.Id()))
})
if err != nil {
return err
}
d.SetId("")
return nil
}