-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for S3 Object Lock legal holds, retention modes and retention periods #9942
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
766e77f
d/aws_s3_bucket_object: Add 'object_lock_legal_hold_status' attribute.
ewbankkit 0abfb3e
r/aws_s3_bucket_object: Add 'object_lock_legal_hold_status' attribute.
ewbankkit 147aa76
r/aws_s3_bucket_object: Add 'force_destroy' attribute.
ewbankkit 5060379
r/aws_s3_bucket: Handle locked object for 'force_destroy'.
ewbankkit f49f029
d/aws_s3_bucket_object: Add 'object_lock_mode' and 'object_lock_retai…
ewbankkit 21a9fa7
Fix documentation typo.
ewbankkit 7754826
r/aws_s3_bucket_object: Add S3 Object Lock example usage.
ewbankkit ced3fa0
Only attempt to force destroy S3 bucket objects if the bucket has Obj…
ewbankkit c1d3967
r/aws_s3_bucket_object: Update S3 Object Lock example usage with Obje…
ewbankkit 69d9efa
Fix minor review comments.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,8 +567,8 @@ func resourceAwsS3Bucket() *schema.Resource { | |
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
s3.ObjectLockModeGovernance, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used the correct enumeration here (though the values are identical). |
||
s3.ObjectLockModeCompliance, | ||
s3.ObjectLockRetentionModeGovernance, | ||
s3.ObjectLockRetentionModeCompliance, | ||
}, false), | ||
}, | ||
|
||
|
@@ -1259,49 +1259,17 @@ func resourceAwsS3BucketDelete(d *schema.ResourceData, meta interface{}) error { | |
// bucket may have things delete them | ||
log.Printf("[DEBUG] S3 Bucket attempting to forceDestroy %+v", err) | ||
|
||
bucket := d.Get("bucket").(string) | ||
resp, err := s3conn.ListObjectVersions( | ||
&s3.ListObjectVersionsInput{ | ||
Bucket: aws.String(bucket), | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error S3 Bucket list Object Versions err: %s", err) | ||
} | ||
|
||
objectsToDelete := make([]*s3.ObjectIdentifier, 0) | ||
|
||
if len(resp.DeleteMarkers) != 0 { | ||
|
||
for _, v := range resp.DeleteMarkers { | ||
objectsToDelete = append(objectsToDelete, &s3.ObjectIdentifier{ | ||
Key: v.Key, | ||
VersionId: v.VersionId, | ||
}) | ||
} | ||
// Delete everything including locked objects. | ||
// Don't ignore any object errors or we could recurse infinitely. | ||
var objectLockEnabled bool | ||
objectLockConfiguration := expandS3ObjectLockConfiguration(d.Get("object_lock_configuration").([]interface{})) | ||
if objectLockConfiguration != nil { | ||
objectLockEnabled = aws.StringValue(objectLockConfiguration.ObjectLockEnabled) == s3.ObjectLockEnabledEnabled | ||
} | ||
|
||
if len(resp.Versions) != 0 { | ||
for _, v := range resp.Versions { | ||
objectsToDelete = append(objectsToDelete, &s3.ObjectIdentifier{ | ||
Key: v.Key, | ||
VersionId: v.VersionId, | ||
}) | ||
} | ||
} | ||
|
||
params := &s3.DeleteObjectsInput{ | ||
Bucket: aws.String(bucket), | ||
Delete: &s3.Delete{ | ||
Objects: objectsToDelete, | ||
}, | ||
} | ||
|
||
_, err = s3conn.DeleteObjects(params) | ||
err = deleteAllS3ObjectVersions(s3conn, d.Id(), "", objectLockEnabled, false) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error S3 Bucket force_destroy error deleting: %s", err) | ||
return fmt.Errorf("error S3 Bucket force_destroy: %s", err) | ||
} | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
|
||
// this line recurses until all objects are deleted or an error is returned | ||
|
@@ -2472,7 +2440,7 @@ type S3Website struct { | |
// S3 Object Lock functions. | ||
// | ||
|
||
func readS3ObjectLockConfiguration(conn *s3.S3, bucket string) (interface{}, error) { | ||
func readS3ObjectLockConfiguration(conn *s3.S3, bucket string) ([]interface{}, error) { | ||
resp, err := retryOnAwsCode(s3.ErrCodeNoSuchBucket, func() (interface{}, error) { | ||
return conn.GetObjectLockConfiguration(&s3.GetObjectLockConfigurationInput{ | ||
Bucket: aws.String(bucket), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future it really is hard to gain context around what these variables represent give the function signature. We should try to use more descriptive names here. We should also look at ways for structuring the resource and data source configurations a bit to make tests like this easier. Then again the resource test should cover the
testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object", &rObj),
case.No action items here. Just mentioning for future reference.