| 1 |
--- |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
- name: Create a topic |
| 17 |
google.cloud.gcp_pubsub_topic: |
| 18 |
name: topic-subscription |
| 19 |
project: "{{ gcp_project }}" |
| 20 |
auth_kind: "{{ gcp_cred_kind }}" |
| 21 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 22 |
state: present |
| 23 |
register: topic |
| 24 |
- name: Create a bucket |
| 25 |
google.cloud.gcp_storage_bucket: |
| 26 |
name: topic-subscription-bucket |
| 27 |
project: "{{ gcp_project }}" |
| 28 |
auth_kind: "{{ gcp_cred_kind }}" |
| 29 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 30 |
state: present |
| 31 |
- name: Delete a subscription |
| 32 |
google.cloud.gcp_pubsub_subscription: |
| 33 |
name: "{{ resource_name }}" |
| 34 |
topic: "{{ topic }}" |
| 35 |
ack_deadline_seconds: 300 |
| 36 |
project: "{{ gcp_project }}" |
| 37 |
auth_kind: "{{ gcp_cred_kind }}" |
| 38 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 39 |
state: absent |
| 40 |
|
| 41 |
- name: Create a subscription |
| 42 |
google.cloud.gcp_pubsub_subscription: |
| 43 |
name: "{{ resource_name }}" |
| 44 |
topic: "{{ topic }}" |
| 45 |
ack_deadline_seconds: 300 |
| 46 |
project: "{{ gcp_project }}" |
| 47 |
auth_kind: "{{ gcp_cred_kind }}" |
| 48 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 49 |
state: present |
| 50 |
register: result |
| 51 |
- name: Assert changed is true |
| 52 |
ansible.builtin.assert: |
| 53 |
that: |
| 54 |
- result.changed == true |
| 55 |
- name: Verify that subscription was created |
| 56 |
google.cloud.gcp_pubsub_subscription_info: |
| 57 |
project: "{{ gcp_project }}" |
| 58 |
auth_kind: "{{ gcp_cred_kind }}" |
| 59 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 60 |
scopes: |
| 61 |
- https://www.googleapis.com/auth/pubsub |
| 62 |
register: results |
| 63 |
- name: Verify that command succeeded |
| 64 |
ansible.builtin.assert: |
| 65 |
that: |
| 66 |
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 1 |
| 67 |
|
| 68 |
- name: Create a subscription that already exists |
| 69 |
google.cloud.gcp_pubsub_subscription: |
| 70 |
name: "{{ resource_name }}" |
| 71 |
topic: "{{ topic }}" |
| 72 |
ack_deadline_seconds: 300 |
| 73 |
project: "{{ gcp_project }}" |
| 74 |
auth_kind: "{{ gcp_cred_kind }}" |
| 75 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 76 |
state: present |
| 77 |
register: result |
| 78 |
- name: Assert changed is false |
| 79 |
ansible.builtin.assert: |
| 80 |
that: |
| 81 |
- result.changed == false |
| 82 |
|
| 83 |
- name: Update a subscription |
| 84 |
google.cloud.gcp_pubsub_subscription: |
| 85 |
name: "{{ resource_name }}" |
| 86 |
topic: "{{ topic }}" |
| 87 |
ack_deadline_seconds: 60 |
| 88 |
project: "{{ gcp_project }}" |
| 89 |
auth_kind: "{{ gcp_cred_kind }}" |
| 90 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 91 |
state: present |
| 92 |
register: result |
| 93 |
- name: Assert changed is true |
| 94 |
ansible.builtin.assert: |
| 95 |
that: |
| 96 |
- result.changed == true |
| 97 |
|
| 98 |
- name: Update cloudStorageConfig of a subscription that already exists |
| 99 |
google.cloud.gcp_pubsub_subscription: |
| 100 |
name: "{{ resource_name }}" |
| 101 |
topic: "{{ topic }}" |
| 102 |
ack_deadline_seconds: 300 |
| 103 |
cloud_storage: { |
| 104 |
bucket: "topic-subscription-bucket", |
| 105 |
file_prefix: "test_", |
| 106 |
file_suffix: "_test", |
| 107 |
max_bytes: 10737418240, |
| 108 |
max_duration: "600s", |
| 109 |
output_format: "avro", |
| 110 |
write_metadata: true |
| 111 |
} |
| 112 |
project: "{{ gcp_project }}" |
| 113 |
auth_kind: "{{ gcp_cred_kind }}" |
| 114 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 115 |
state: present |
| 116 |
register: result |
| 117 |
- name: Assert changed is true |
| 118 |
ansible.builtin.assert: |
| 119 |
that: |
| 120 |
- result.changed == true |
| 121 |
|
| 122 |
- name: Delete a subscription |
| 123 |
google.cloud.gcp_pubsub_subscription: |
| 124 |
name: "{{ resource_name }}" |
| 125 |
topic: "{{ topic }}" |
| 126 |
ack_deadline_seconds: 300 |
| 127 |
project: "{{ gcp_project }}" |
| 128 |
auth_kind: "{{ gcp_cred_kind }}" |
| 129 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 130 |
state: absent |
| 131 |
register: result |
| 132 |
- name: Assert changed is true |
| 133 |
ansible.builtin.assert: |
| 134 |
that: |
| 135 |
- result.changed == true |
| 136 |
- name: Verify that subscription was deleted |
| 137 |
google.cloud.gcp_pubsub_subscription_info: |
| 138 |
project: "{{ gcp_project }}" |
| 139 |
auth_kind: "{{ gcp_cred_kind }}" |
| 140 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 141 |
scopes: |
| 142 |
- https://www.googleapis.com/auth/pubsub |
| 143 |
register: results |
| 144 |
- name: Verify that command succeeded |
| 145 |
ansible.builtin.assert: |
| 146 |
that: |
| 147 |
- results['resources'] | map(attribute='name') | select("match", ".*{{ resource_name }}.*") | list | length == 0 |
| 148 |
|
| 149 |
- name: Delete a subscription that does not exist |
| 150 |
google.cloud.gcp_pubsub_subscription: |
| 151 |
name: "{{ resource_name }}" |
| 152 |
topic: "{{ topic }}" |
| 153 |
ack_deadline_seconds: 300 |
| 154 |
project: "{{ gcp_project }}" |
| 155 |
auth_kind: "{{ gcp_cred_kind }}" |
| 156 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 157 |
state: absent |
| 158 |
register: result |
| 159 |
- name: Assert changed is false |
| 160 |
ansible.builtin.assert: |
| 161 |
that: |
| 162 |
- result.changed == false |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
- name: Delete a topic |
| 167 |
google.cloud.gcp_pubsub_topic: |
| 168 |
name: topic-subscription |
| 169 |
project: "{{ gcp_project }}" |
| 170 |
auth_kind: "{{ gcp_cred_kind }}" |
| 171 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 172 |
state: absent |
| 173 |
register: topic |
| 174 |
ignore_errors: true |
| 175 |
|
| 176 |
- name: Delete a bucket |
| 177 |
google.cloud.gcp_storage_bucket: |
| 178 |
name: topic-subscription-bucket |
| 179 |
project: "{{ gcp_project }}" |
| 180 |
auth_kind: "{{ gcp_cred_kind }}" |
| 181 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 182 |
state: absent |