Refresh state for deleted s3 bucket correctly

If reading an S3 bucket's state, and that bucket has been deleted, don't
fail with a 404 error. Instead, update the state to reflect that the
bucket does not exist. Fixes #1574.
This commit is contained in:
Phil Frost 2015-04-17 13:30:31 -04:00
parent 8f8e93e657
commit 47e1ec85f1
1 changed files with 7 additions and 1 deletions

View File

@ -85,7 +85,13 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
Bucket: aws.String(d.Id()),
})
if err != nil {
return err
if awsError, ok := err.(aws.APIError); ok && awsError.StatusCode == 404 {
d.SetId("")
} else {
// some of the AWS SDK's errors can be empty strings, so let's add
// some additional context.
return fmt.Errorf("error reading S3 bucket \"%s\": %#v", d.Id())
}
}
tagSet, err := getTagSetS3(s3conn, d.Id())