From 2b35fbf4047487d7cc9067cebefc119ac853e537 Mon Sep 17 00:00:00 2001 From: "Sieradzki, Lukasz" Date: Fri, 8 Nov 2024 23:02:23 +0100 Subject: [PATCH] https://github.com/ansible-collections/google.cloud/issues/657 --- plugins/modules/gcp_pubsub_subscription.py | 22 ++++++++++--- scripts/bootstrap-project.sh | 2 ++ .../gcp_pubsub_subscription/tasks/autogen.yml | 32 ++++++++++++++++--- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/plugins/modules/gcp_pubsub_subscription.py b/plugins/modules/gcp_pubsub_subscription.py index bc706f0..f55c0d5 100644 --- a/plugins/modules/gcp_pubsub_subscription.py +++ b/plugins/modules/gcp_pubsub_subscription.py @@ -92,14 +92,14 @@ options: type: str max_duration: description: - - Subscription writes a new output file if the specified value of max duration is exceeded. Min: 1m, max: 10m. + - Subscription writes a new output file if the specified value of max duration is exceeded. Min: 60s, max: 600s. required: true type: str max_bytes: description: - - Cloud Storage Subscription writes a new output file if the specified value of max bytes is exceeded. Min: 1KB, max: 10GiB. + - Cloud Storage Subscription writes a new output file if the specified value of max bytes is exceeded. Min: 1000, max: 10737418240. required: false - type: str + type: int max_messages: description: - Cloud Storage Subscription writes a new output file if the specified number of messages is exceeded. Min: 1000. @@ -643,7 +643,7 @@ def main(): file_suffix=dict(type='str'), file_datetime_format=dict(type='str'), max_duration=dict(type='str'), - max_bytes=dict(type='str'), + max_bytes=dict(type='int'), max_messages=dict(type='int'), output_format=dict(type='str'), write_metadata=dict(type='bool'), @@ -999,6 +999,20 @@ class SubscriptionCloudStorageConfig(object): else {}, } ) + storageConfig = { + u'bucket': self.request.get('bucket', {}), + u'filenamePrefix': self.request.get('filenamePrefix', {}), + u'filenameSuffix': self.request.get('filenameSuffix', {}), + u'filenameDatetimeFormat': self.request.get('filenameDatetimeFormat', {}), + u'maxDuration': self.request.get('maxDuration', {}), + u'maxBytes': self.request.get('maxBytes', {}), + u'maxMessages': self.request.get('maxMessages', {}), + u'avroConfig': {'writeMetadata': self.request.get('avroConfig', {}).get('writeMetadata', False), + 'useTopicSchema': self.request.get('avroConfig', {}).get('useTopicSchema', False)} + if self.request.get('avroConfig', {}) + else {}, + } + return remove_nones_from_dict(storageConfig) if self.request else storageConfig if __name__ == '__main__': diff --git a/scripts/bootstrap-project.sh b/scripts/bootstrap-project.sh index a28f42c..3e90c21 100755 --- a/scripts/bootstrap-project.sh +++ b/scripts/bootstrap-project.sh @@ -32,6 +32,8 @@ SERVICE_LIST=( REQUIRED_ROLE_LIST=( "roles/storage.objectAdmin" + "roles/storage.legacyBucketReader" + "roles/storage.objectCreator" "roles/source.admin" ) diff --git a/tests/integration/targets/gcp_pubsub_subscription/tasks/autogen.yml b/tests/integration/targets/gcp_pubsub_subscription/tasks/autogen.yml index b431e27..bdce0e6 100644 --- a/tests/integration/targets/gcp_pubsub_subscription/tasks/autogen.yml +++ b/tests/integration/targets/gcp_pubsub_subscription/tasks/autogen.yml @@ -21,6 +21,13 @@ service_account_file: "{{ gcp_cred_file | default(omit) }}" state: present register: topic +- name: Create a bucket + google.cloud.gcp_storage_bucket: + name: topic-subscription-bucket + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file | default(omit) }}" + state: present - name: Delete a subscription google.cloud.gcp_pubsub_subscription: name: "{{ resource_name }}" @@ -73,11 +80,20 @@ that: - result.changed == false #---------------------------------------------------------- -- name: Update ack_deadline_seconds of a subscription that already exists +- name: Update cloudStorageConfig of a subscription that already exists google.cloud.gcp_pubsub_subscription: name: "{{ resource_name }}" topic: "{{ topic }}" - ack_deadline_seconds: 500 + ack_deadline_seconds: 300 + cloud_storage: { + bucket: "topic-subscription-bucket", + file_prefix: "test_", + file_suffix: "_test", + max_bytes: 10737418240, + max_duration: "600s", + output_format: "avro", + write_metadata: true + } project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file | default(omit) }}" @@ -92,7 +108,7 @@ google.cloud.gcp_pubsub_subscription: name: "{{ resource_name }}" topic: "{{ topic }}" - ack_deadline_seconds: 500 + ack_deadline_seconds: 300 project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file | default(omit) }}" @@ -119,7 +135,7 @@ google.cloud.gcp_pubsub_subscription: name: "{{ resource_name }}" topic: "{{ topic }}" - ack_deadline_seconds: 500 + ack_deadline_seconds: 300 project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file | default(omit) }}" @@ -141,3 +157,11 @@ state: absent register: topic ignore_errors: true + +- name: Delete a bucket + google.cloud.gcp_storage_bucket: + name: topic-subscription-bucket + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file | default(omit) }}" + state: absent