Merge pull request #4168 from combor/malformed_xml_fix
S3 bucket force_destroy error: MalformedXML
This commit is contained in:
commit
9f5f30650f
|
@ -406,30 +406,46 @@ func resourceAwsS3BucketDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
log.Printf("[DEBUG] S3 Bucket attempting to forceDestroy %+v", err)
|
log.Printf("[DEBUG] S3 Bucket attempting to forceDestroy %+v", err)
|
||||||
|
|
||||||
bucket := d.Get("bucket").(string)
|
bucket := d.Get("bucket").(string)
|
||||||
resp, err := s3conn.ListObjects(
|
resp, err := s3conn.ListObjectVersions(
|
||||||
&s3.ListObjectsInput{
|
&s3.ListObjectVersionsInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error S3 Bucket list Objects err: %s", err)
|
return fmt.Errorf("Error S3 Bucket list Object Versions err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
objectsToDelete := make([]*s3.ObjectIdentifier, len(resp.Contents))
|
objectsToDelete := make([]*s3.ObjectIdentifier, 0)
|
||||||
for i, v := range resp.Contents {
|
|
||||||
objectsToDelete[i] = &s3.ObjectIdentifier{
|
if len(resp.DeleteMarkers) != 0 {
|
||||||
Key: v.Key,
|
|
||||||
|
for _, v := range resp.DeleteMarkers {
|
||||||
|
objectsToDelete = append(objectsToDelete, &s3.ObjectIdentifier{
|
||||||
|
Key: v.Key,
|
||||||
|
VersionId: v.VersionId,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = s3conn.DeleteObjects(
|
|
||||||
&s3.DeleteObjectsInput{
|
if len(resp.Versions) != 0 {
|
||||||
Bucket: aws.String(bucket),
|
for _, v := range resp.Versions {
|
||||||
Delete: &s3.Delete{
|
objectsToDelete = append(objectsToDelete, &s3.ObjectIdentifier{
|
||||||
Objects: objectsToDelete,
|
Key: v.Key,
|
||||||
},
|
VersionId: v.VersionId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params := &s3.DeleteObjectsInput{
|
||||||
|
Bucket: aws.String(bucket),
|
||||||
|
Delete: &s3.Delete{
|
||||||
|
Objects: objectsToDelete,
|
||||||
},
|
},
|
||||||
)
|
}
|
||||||
|
|
||||||
|
_, err = s3conn.DeleteObjects(params)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error S3 Bucket force_destroy error deleting: %s", err)
|
return fmt.Errorf("Error S3 Bucket force_destroy error deleting: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue