Skip to content

Commit

Permalink
added force_destroy argument to s3 bucket provider
Browse files Browse the repository at this point in the history
commit a92fe29
Author: Michael Austin <[email protected]>
Date:   Wed May 20 16:35:38 2015 -0400

    updated to new style of awserr

commit 428271c
Merge: b3bae0e 883e284
Author: Michael Austin <[email protected]>
Date:   Wed May 20 16:29:00 2015 -0400

    Merge branch 'master' into 2544-terraform-s3-forceDelete

commit b3bae0e
Author: Michael Austin <[email protected]>
Date:   Wed May 20 12:06:36 2015 -0400

    removed extra line

commit 85eb40f
Author: Michael Austin <[email protected]>
Date:   Tue May 19 14:27:19 2015 -0400

    stray [

commit d8a405f
Author: Michael Austin <[email protected]>
Date:   Tue May 19 14:24:01 2015 -0400

    addressed feedback concerning parsing of aws error in a more standard way

commit 5b9a5ee
Author: Michael Austin <[email protected]>
Date:   Tue May 19 10:55:22 2015 -0400

    clarify comment to highlight recursion

commit 9104378
Author: Michael Austin <[email protected]>
Date:   Tue May 19 10:51:13 2015 -0400

    addressed feedback about reusing err variable and unneeded parens

commit 95e9c3a
Merge: 2637edf db095e2
Author: Michael Austin <[email protected]>
Date:   Mon May 18 19:15:36 2015 -0400

    Merge branch 'master' into 2544-terraform-s3-forceDelete

commit 2637edf
Author: Michael Austin <[email protected]>
Date:   Fri May 15 15:12:41 2015 -0400

    optimize delete to delete up to 1000 at once instead of one at a time

commit 1441eb2
Author: Michael Austin <[email protected]>
Date:   Fri May 15 12:34:53 2015 -0400

    Revert "hook new resource provider into configuration"

    This reverts commit e14a1ad.

commit b532fa2
Author: Michael Austin <[email protected]>
Date:   Fri May 15 12:34:49 2015 -0400

    this file should not be in this branch

commit 645c0b6
Author: Michael Austin <[email protected]>
Date:   Thu May 14 21:15:29 2015 -0400

    buckets tagged force_destroy will delete all files and then delete buckets

commit ac50cae
Author: Michael Austin <[email protected]>
Date:   Thu May 14 12:41:40 2015 -0400

    added code to delete policy from s3 bucket

commit cd45e45
Author: Michael Austin <[email protected]>
Date:   Thu May 14 12:27:13 2015 -0400

    added code to read bucket policy from bucket, however, it's not working as expected currently

commit 0d3d51a
Merge: 31ffdea 8a3b75d
Author: Michael Austin <[email protected]>
Date:   Thu May 14 08:38:06 2015 -0400

    Merge remote-tracking branch 'hashi_origin/master' into 2544-terraform-s3-policy

commit 31ffdea
Author: Michael Austin <[email protected]>
Date:   Wed May 13 16:01:52 2015 -0400

    add name for use with resouce id

commit b41c737
Author: Michael Austin <[email protected]>
Date:   Wed May 13 14:48:24 2015 -0400

    Revert "working policy assignment"
    This reverts commit 0975a70.

commit b926b11
Author: Michael Austin <[email protected]>
Date:   Wed May 13 14:35:02 2015 -0400

    moved policy to it's own provider

commit 233a5f4
Merge: e14a1ad c003e96
Author: Michael Austin <[email protected]>
Date:   Wed May 13 12:39:14 2015 -0400

    merged origin/master

commit e14a1ad
Author: Michael Austin <[email protected]>
Date:   Wed May 13 12:26:51 2015 -0400

    hook new resource provider into configuration

commit 455b409
Author: Michael Austin <[email protected]>
Date:   Wed May 13 12:26:15 2015 -0400

    dummy resource provider

commit 0975a70
Author: Michael Austin <[email protected]>
Date:   Wed May 13 09:42:31 2015 -0400

    working policy assignment

commit 3ab901d
Author: Michael Austin <[email protected]>
Date:   Tue May 12 10:39:56 2015 -0400

    added policy string to schema
  • Loading branch information
m-s-austin committed May 20, 2015
1 parent 883e284 commit dc698e3
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func resourceAwsS3Bucket() *schema.Resource {
},

"tags": tagsSchema(),

"force_destroy": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -259,7 +265,46 @@ func resourceAwsS3BucketDelete(d *schema.ResourceData, meta interface{}) error {
Bucket: aws.String(d.Id()),
})
if err != nil {
return err
ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code() == "BucketNotEmpty" {
if d.Get("force_destroy").(bool) {
// bucket may have things delete them
log.Printf("[DEBUG] S3 Bucket attempting to forceDestroy %+v", err)

bucket := d.Get("bucket").(string)
resp, err := s3conn.ListObjects(
&s3.ListObjectsInput{
Bucket: aws.String(bucket),
},
)

if err != nil {
return fmt.Errorf("Error S3 Bucket list Objects err: %s", err)
}

objectsToDelete := make([]*s3.ObjectIdentifier, len(resp.Contents))
for i, v := range resp.Contents {
objectsToDelete[i] = &s3.ObjectIdentifier{
Key: v.Key,
}
}
_, err = s3conn.DeleteObjects(
&s3.DeleteObjectsInput{
Bucket: aws.String(bucket),
Delete: &s3.Delete{
Objects: objectsToDelete,
},
},
)
if err != nil {
return fmt.Errorf("Error S3 Bucket force_destroy error deleting: %s", err)
}

// this line recurses until all objects are deleted or an error is returned
return resourceAwsS3BucketDelete(d, meta)
}
}
return fmt.Errorf("Error deleting S3 Bucket: %s", err)
}
return nil
}
Expand Down

0 comments on commit dc698e3

Please sign in to comment.