Add iamConfiguration support to gcp_storage_bucket

You can now set the iam configuration for a given bucket, you can set:
1. publicAccessPrevention and
2. uniformBucketLevelAccess

no support for bucketPolicyOnly because according to the storage docs:

Note: iamConfiguration also includes the bucketPolicyOnly field, which
uses a legacy name but has the same functionality as the
uniformBucketLevelAccess field. We recommend only using
uniformBucketLevelAccess, as specifying both fields may result in
unreliable behavior.

Also added integration tests for this feature

Signed-off-by: Jorge Gallegos <jgallego@redhat.com>
This commit is contained in:
Jorge Gallegos 2025-06-26 12:00:00 -06:00
commit f9f0b33542
No known key found for this signature in database
3 changed files with 180 additions and 2 deletions

View file

@ -0,0 +1,86 @@
---
- name: Run test cases
block:
# --------------------------------------------------------------------------
- name: Create default bucket
google.cloud.gcp_storage_bucket:
name: "{{ resource_name }}-default"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: present
register: result
- name: Assert changed is true and default values are returned
ansible.builtin.assert:
that:
- result.changed == true
- result.iamConfiguration.publicAccessPrevention == 'inherited'
- result.iamConfiguration.uniformBucketLevelAccess.enabled == false
# --------------------------------------------------------------------------
- name: Create bucket with enforced PAP
google.cloud.gcp_storage_bucket:
name: "{{ resource_name }}-pap"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: present
iam_configuration:
public_access_prevention: enforced
register: result
- name: Assert changed is true and IAM PAP is 'enforced'
ansible.builtin.assert:
that:
- result.changed == true
- result.iamConfiguration.publicAccessPrevention == 'enforced'
# --------------------------------------------------------------------------
- name: Create bucket with UBLA enabled
google.cloud.gcp_storage_bucket:
name: "{{ resource_name }}-ublae"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: present
iam_configuration:
uniform_bucket_level_access:
enabled: true
register: result
- name: Assert changed is true and IAM UBLA is enabled
ansible.builtin.assert:
that:
- result.changed == true
- result.iamConfiguration.uniformBucketLevelAccess.enabled == true
# --------------------------------------------------------------------------
- name: Create bucket with UBLA disabled
google.cloud.gcp_storage_bucket:
name: "{{ resource_name }}-ublad"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: present
iam_configuration:
uniform_bucket_level_access:
enabled: false
register: result
- name: Assert changed is true and IAM UBLA is disabled
ansible.builtin.assert:
that:
- result.changed == true
- result.iamConfiguration.uniformBucketLevelAccess.enabled == false
# --------------------------------------------------------------------------
always:
- name: Clean up buckets
google.cloud.gcp_storage_bucket:
name: "{{ resource_name }}-{{ item }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file | default(omit) }}"
state: absent
loop:
- default
- pap
- ublae
- ublad

View file

@ -1,3 +1,6 @@
---
- name: Generated tests
ansible.builtin.include_tasks: autogen.yml
- name: Tests for IAM Configuration support
ansible.builtin.include_tasks: iam_configuration.yml