-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Object Lock default retention configuration for S3 buckets (#2062) (
#2177) SUMMARY https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-configure.html#object-lock-configure-set-retention-period-object Design detail: AWS API doesn't support unsetting the default retention, though it is possible in the Web console. ISSUE TYPE Feature Pull Request COMPONENT NAME s3_bucket Reviewed-by: Helen Bailey [email protected] Reviewed-by: Alina Buzachis Reviewed-by: Mike Graves [email protected] (cherry picked from commit c2e7aaf) SUMMARY ISSUE TYPE Bugfix Pull Request Docs Pull Request Feature Pull Request New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Mike Graves <[email protected]> Reviewed-by: GomathiselviS
- Loading branch information
1 parent
8a930e4
commit ae1f15f
Showing
4 changed files
with
279 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- s3_bucket - Add ``object_lock_default_retention`` to set Object Lock default retention configuration for S3 buckets (https://github.com/ansible-collections/amazon.aws/pull/2062). |
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ public_access | |
acl | ||
object_lock | ||
accelerate | ||
default_retention | ||
|
||
[all:vars] | ||
ansible_connection=local | ||
|
136 changes: 136 additions & 0 deletions
136
tests/integration/targets/s3_bucket/roles/s3_bucket/tasks/default_retention.yml
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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
--- | ||
- module_defaults: | ||
group/aws: | ||
access_key: "{{ aws_access_key }}" | ||
secret_key: "{{ aws_secret_key }}" | ||
session_token: "{{ security_token | default(omit) }}" | ||
region: "{{ aws_region }}" | ||
block: | ||
- ansible.builtin.set_fact: | ||
local_bucket_name: "{{ bucket_name | hash('md5')}}-default-retention" | ||
|
||
# ============================================================ | ||
|
||
- name: Create a simple bucket with object lock | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}" | ||
state: present | ||
object_lock_enabled: true | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- output.changed | ||
- output.object_lock_enabled | ||
|
||
- name: Add object lock default retention | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}" | ||
state: present | ||
object_lock_enabled: true | ||
object_lock_default_retention: | ||
mode: GOVERNANCE | ||
days: 1 | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- output.changed | ||
- output.object_lock_enabled | ||
- output.object_lock_default_retention | ||
|
||
- name: Delete test s3 bucket | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}" | ||
state: absent | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- output.changed | ||
|
||
# ============================================================ | ||
|
||
- name: Create a bucket with object lock and default retention enabled | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}-2" | ||
state: present | ||
object_lock_enabled: true | ||
object_lock_default_retention: | ||
mode: GOVERNANCE | ||
days: 1 | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- output.changed | ||
- output.object_lock_enabled | ||
- output.object_lock_default_retention | ||
|
||
- name: Touch bucket with object lock enabled (idempotency) | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}-2" | ||
state: present | ||
object_lock_enabled: true | ||
object_lock_default_retention: | ||
mode: GOVERNANCE | ||
days: 1 | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- not output.changed | ||
- output.object_lock_enabled | ||
- output.object_lock_default_retention | ||
|
||
- name: Change bucket with object lock default retention enabled | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}-2" | ||
state: present | ||
object_lock_enabled: true | ||
object_lock_default_retention: | ||
mode: GOVERNANCE | ||
days: 2 | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- output.changed | ||
- output.object_lock_enabled | ||
- output.object_lock_default_retention | ||
|
||
- name: Disable object lock default retention | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}-2" | ||
state: present | ||
object_lock_enabled: true | ||
register: output | ||
ignore_errors: true | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- not output.changed | ||
|
||
- name: Delete test s3 bucket | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}-2" | ||
state: absent | ||
register: output | ||
|
||
- ansible.builtin.assert: | ||
that: | ||
- output.changed | ||
|
||
# ============================================================ | ||
always: | ||
- name: Ensure all buckets are deleted | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}" | ||
state: absent | ||
ignore_errors: true | ||
|
||
- name: Ensure all buckets are deleted | ||
amazon.aws.s3_bucket: | ||
name: "{{ local_bucket_name }}-2" | ||
state: absent | ||
ignore_errors: true |