-
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 ownership controls options for s3 bucket (#311)
add object ownership controls options for s3 bucket Reviewed-by: https://github.com/apps/ansible-zuul
- Loading branch information
Showing
4 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/311-s3_bucket-allow-object-ownership-configuration.yaml
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 new option ``object_ownership`` to configure object ownership (https://github.com/ansible-collections/amazon.aws/pull/311) |
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
119 changes: 119 additions & 0 deletions
119
tests/integration/targets/s3_bucket/roles/s3_bucket/tasks/ownership_controls.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,119 @@ | ||
--- | ||
- module_defaults: | ||
group/aws: | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
security_token: "{{ security_token | default(omit) }}" | ||
region: "{{ aws_region }}" | ||
block: | ||
|
||
# ============================================================ | ||
- set_fact: | ||
local_bucket_name: "{{ bucket_name | hash('md5')}}ownership" | ||
|
||
- name: 'Create a simple bucket bad value for ownership controls' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
object_ownership: default | ||
ignore_errors: true | ||
register: output | ||
|
||
- assert: | ||
that: | ||
- output.failed | ||
|
||
- name: 'Create bucket with object_ownership set to object_writer' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
ignore_errors: true | ||
register: output | ||
|
||
- assert: | ||
that: | ||
- output.changed | ||
- not output.object_ownership|bool | ||
|
||
- name: delete s3 bucket | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: absent | ||
|
||
- name: 'create s3 bucket with object ownership controls' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
object_ownership: ObjectWriter | ||
register: output | ||
|
||
- assert: | ||
that: | ||
- output.changed | ||
- output.object_ownership | ||
- output.object_ownership == 'ObjectWriter' | ||
|
||
- name: 'update s3 bucket ownership controls' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
object_ownership: BucketOwnerPreferred | ||
register: output | ||
|
||
- assert: | ||
that: | ||
- output.changed | ||
- output.object_ownership | ||
- output.object_ownership == 'BucketOwnerPreferred' | ||
|
||
- name: 'test idempotency update s3 bucket ownership controls' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
object_ownership: BucketOwnerPreferred | ||
register: output | ||
|
||
- assert: | ||
that: | ||
- output.changed is false | ||
- output.object_ownership | ||
- output.object_ownership == 'BucketOwnerPreferred' | ||
|
||
- name: 'delete s3 bucket ownership controls' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
delete_object_ownership: true | ||
register: output | ||
|
||
- assert: | ||
that: | ||
- output.changed | ||
- not output.object_ownership|bool | ||
|
||
- name: 'delete s3 bucket ownership controls once again (idempotency)' | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
delete_object_ownership: true | ||
register: idempotency | ||
|
||
- assert: | ||
that: | ||
- not idempotency.changed | ||
- not idempotency.object_ownership|bool | ||
|
||
# ============================================================ | ||
always: | ||
- name: delete s3 bucket ownership controls | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: present | ||
delete_object_ownership: true | ||
ignore_errors: yes | ||
|
||
- name: Ensure all buckets are deleted | ||
s3_bucket: | ||
name: '{{ local_bucket_name }}' | ||
state: absent | ||
ignore_errors: yes |