Skip to content

Commit

Permalink
more tightly scope s3 bucket object error
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Aug 5, 2015
1 parent 285b406 commit bfaea76
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions builtin/providers/aws/resource_aws_s3_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
)

Expand Down Expand Up @@ -89,10 +90,13 @@ func resourceAwsS3BucketObjectRead(d *schema.ResourceData, meta interface{}) err
})

if err != nil {
// if there is an error reading the object we assume it's not there.
d.SetId("")
log.Printf("Error Reading Object (%s): %s", key, err)
return nil
// If S3 returns a 404 Request Failure, mark the object as destroyed
if awsErr, ok := err.(awserr.RequestFailure); ok && awsErr.StatusCode() == 404 {
d.SetId("")
log.Printf("[WARN] Error Reading Object (%s), object not found (HTTP status 404)", key)
return nil
}
return err
}

log.Printf("[DEBUG] Reading S3 Bucket Object meta: %s", resp)
Expand Down

0 comments on commit bfaea76

Please sign in to comment.