| 1 |
--- |
| 2 |
# A Note about ec2 environment variable name preference: |
| 3 |
# - EC2_URL -> AWS_URL |
| 4 |
# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY |
| 5 |
# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY |
| 6 |
# - EC2_REGION -> AWS_REGION |
| 7 |
# |
| 8 |
|
| 9 |
- module_defaults: |
| 10 |
group/aws: |
| 11 |
access_key: "{{ aws_access_key }}" |
| 12 |
secret_key: "{{ aws_secret_key }}" |
| 13 |
session_token: "{{ security_token | default(omit) }}" |
| 14 |
region: "{{ aws_region }}" |
| 15 |
block: |
| 16 |
|
| 17 |
# ============================================================ |
| 18 |
- name: test failure with no parameters |
| 19 |
redshift: |
| 20 |
register: result |
| 21 |
ignore_errors: true |
| 22 |
|
| 23 |
- name: assert failure with no parameters |
| 24 |
assert: |
| 25 |
that: |
| 26 |
- 'result.failed' |
| 27 |
- 'result.msg == "missing required arguments: command, identifier"' |
| 28 |
|
| 29 |
# ============================================================ |
| 30 |
- name: test failure with only identifier |
| 31 |
redshift: |
| 32 |
identifier: '{{ redshift_cluster_name }}' |
| 33 |
register: result |
| 34 |
ignore_errors: true |
| 35 |
|
| 36 |
- name: assert failure with only identifier |
| 37 |
assert: |
| 38 |
that: |
| 39 |
- 'result.failed' |
| 40 |
- 'result.msg == "missing required arguments: command"' |
| 41 |
|
| 42 |
# ============================================================ |
| 43 |
- name: test create with no identifier |
| 44 |
redshift: |
| 45 |
command: create |
| 46 |
register: result |
| 47 |
ignore_errors: true |
| 48 |
|
| 49 |
- name: assert failure with no identifier |
| 50 |
assert: |
| 51 |
that: |
| 52 |
- 'result.failed' |
| 53 |
- 'result.msg == "missing required arguments: identifier"' |
| 54 |
|
| 55 |
# ============================================================ |
| 56 |
- name: test create with missing node_type |
| 57 |
redshift: |
| 58 |
command: create |
| 59 |
identifier: "{{ redshift_cluster_name }}" |
| 60 |
register: result |
| 61 |
ignore_errors: true |
| 62 |
|
| 63 |
- name: assert failure with missing node_type |
| 64 |
assert: |
| 65 |
that: |
| 66 |
- 'result.failed' |
| 67 |
- 'result.msg == "command is create but all of the following are missing: node_type, username, password"' |
| 68 |
|
| 69 |
# ============================================================ |
| 70 |
|
| 71 |
- name: test create with missing password |
| 72 |
redshift: |
| 73 |
command: create |
| 74 |
identifier: "{{ redshift_cluster_name }}" |
| 75 |
username: "{{ redshift_master_username }}" |
| 76 |
register: result |
| 77 |
ignore_errors: true |
| 78 |
|
| 79 |
- name: assert create failure with missing password |
| 80 |
assert: |
| 81 |
that: |
| 82 |
- 'result.failed' |
| 83 |
- 'result.msg == "command is create but all of the following are missing: node_type, password"' |
| 84 |
|
| 85 |
# ============================================================ |
| 86 |
|
| 87 |
- name: test create with missing username |
| 88 |
redshift: |
| 89 |
command: create |
| 90 |
identifier: "{{ redshift_cluster_name }}" |
| 91 |
password: "{{ reshift_master_password }}" |
| 92 |
register: result |
| 93 |
ignore_errors: true |
| 94 |
|
| 95 |
- name: assert create failure with missing username |
| 96 |
assert: |
| 97 |
that: |
| 98 |
- 'result.failed' |
| 99 |
- 'result.msg == "command is create but all of the following are missing: node_type, username"' |
| 100 |
|
| 101 |
# ============================================================ |
| 102 |
|
| 103 |
- name: test create with default params |
| 104 |
redshift: |
| 105 |
command: create |
| 106 |
identifier: "{{ redshift_cluster_name }}" |
| 107 |
username: "{{ redshift_master_username }}" |
| 108 |
password: "{{ reshift_master_password }}" |
| 109 |
node_type: "{{ node_type }}" |
| 110 |
wait: yes |
| 111 |
wait_timeout: 1000 |
| 112 |
tags: |
| 113 |
foo: bar |
| 114 |
Tizio: Caio |
| 115 |
register: result |
| 116 |
- debug: |
| 117 |
msg: "{{ result }}" |
| 118 |
verbosity: 1 |
| 119 |
- name: assert create success |
| 120 |
assert: |
| 121 |
that: |
| 122 |
- 'result.changed' |
| 123 |
- result.cluster.identifier == redshift_cluster_name |
| 124 |
- 'result.cluster.tags.foo == "bar"' |
| 125 |
- 'result.cluster.tags.Tizio == "Caio"' |
| 126 |
|
| 127 |
# ============================================================ |
| 128 |
|
| 129 |
- name: test create again with default params |
| 130 |
redshift: |
| 131 |
command: create |
| 132 |
identifier: "{{ redshift_cluster_name }}" |
| 133 |
username: "{{ redshift_master_username }}" |
| 134 |
password: "{{ reshift_master_password }}" |
| 135 |
node_type: "{{ node_type }}" |
| 136 |
wait_timeout: 600 |
| 137 |
tags: |
| 138 |
foo: bar |
| 139 |
Tizio: Caio |
| 140 |
register: result |
| 141 |
|
| 142 |
- name: assert no change gets made to the existing cluster |
| 143 |
assert: |
| 144 |
that: |
| 145 |
- 'not result.changed' |
| 146 |
- result.cluster.identifier == redshift_cluster_name |
| 147 |
- 'result.cluster.tags.foo == "bar"' |
| 148 |
- 'result.cluster.tags.Tizio == "Caio"' |
| 149 |
- 'result.cluster.tags | count() == 2' |
| 150 |
|
| 151 |
# ============================================================ |
| 152 |
|
| 153 |
- name: test modify cluster |
| 154 |
redshift: |
| 155 |
command: modify |
| 156 |
identifier: "{{ redshift_cluster_name }}" |
| 157 |
new_cluster_identifier: "{{ redshift_cluster_name }}-modified" |
| 158 |
enhanced_vpc_routing: True |
| 159 |
wait: yes |
| 160 |
wait_timeout: 1000 |
| 161 |
tags: |
| 162 |
foo: bar |
| 163 |
register: result |
| 164 |
|
| 165 |
- name: assert cluster was modified |
| 166 |
assert: |
| 167 |
that: |
| 168 |
- 'result.changed' |
| 169 |
- result.cluster.identifier == redshift_cluster_name ~ '-modified' |
| 170 |
- 'result.cluster.enhanced_vpc_routing == True' |
| 171 |
- 'result.cluster.tags | count() == 1' |
| 172 |
- 'result.cluster.tags.foo == "bar"' |
| 173 |
|
| 174 |
# ============================================================ |
| 175 |
- name: test delete with no cluster identifier |
| 176 |
redshift: |
| 177 |
command: delete |
| 178 |
register: result |
| 179 |
ignore_errors: true |
| 180 |
|
| 181 |
- name: assert failure with no identifier |
| 182 |
assert: |
| 183 |
that: |
| 184 |
- 'result.failed' |
| 185 |
- 'result.msg == "missing required arguments: identifier"' |
| 186 |
|
| 187 |
# ============================================================ |
| 188 |
- name: test delete with no snapshot id |
| 189 |
redshift: |
| 190 |
command: delete |
| 191 |
identifier: "{{ redshift_cluster_name }}" |
| 192 |
register: result |
| 193 |
ignore_errors: true |
| 194 |
|
| 195 |
- name: assert failure for no snapshot identifier |
| 196 |
assert: |
| 197 |
that: |
| 198 |
- 'result.failed' |
| 199 |
- 'result.msg == "Need to specify final_cluster_snapshot_identifier if skip_final_cluster_snapshot is False"' |
| 200 |
|
| 201 |
|
| 202 |
# ============================================================ |
| 203 |
- name: test successful delete |
| 204 |
redshift: |
| 205 |
command: delete |
| 206 |
identifier: "{{ redshift_cluster_name }}-modified" |
| 207 |
skip_final_cluster_snapshot: true |
| 208 |
wait: yes |
| 209 |
wait_timeout: 1200 |
| 210 |
register: result |
| 211 |
|
| 212 |
- name: assert delete |
| 213 |
assert: |
| 214 |
that: |
| 215 |
- 'result.changed' |
| 216 |
|
| 217 |
# ============================================================ |
| 218 |
|
| 219 |
- name: test create multi-node cluster with custom db-name |
| 220 |
redshift: |
| 221 |
command: create |
| 222 |
identifier: "{{ redshift_cluster_name }}" |
| 223 |
username: "{{ redshift_master_username }}" |
| 224 |
password: "{{ reshift_master_password }}" |
| 225 |
node_type: "{{ node_type }}" |
| 226 |
cluster_type: multi-node |
| 227 |
number_of_nodes: 3 |
| 228 |
wait: yes |
| 229 |
db_name: "integration_test" |
| 230 |
wait_timeout: 1800 |
| 231 |
register: result |
| 232 |
|
| 233 |
- name: assert create |
| 234 |
assert: |
| 235 |
that: |
| 236 |
- 'result.changed' |
| 237 |
- result.cluster.identifier == redshift_cluster_name |
| 238 |
- 'result.cluster.db_name == "integration_test"' |
| 239 |
|
| 240 |
# ============================================================ |
| 241 |
|
| 242 |
- name: test tag update on existing cluster |
| 243 |
redshift: |
| 244 |
command: create |
| 245 |
identifier: "{{ redshift_cluster_name }}" |
| 246 |
username: "{{ redshift_master_username }}" |
| 247 |
password: "{{ reshift_master_password }}" |
| 248 |
node_type: "{{ node_type }}" |
| 249 |
cluster_type: multi-node |
| 250 |
number_of_nodes: 3 |
| 251 |
wait: yes |
| 252 |
db_name: "integration_test" |
| 253 |
tags: |
| 254 |
foo: bar |
| 255 |
wait_timeout: 1800 |
| 256 |
register: result |
| 257 |
|
| 258 |
|
| 259 |
- name: assert tags change |
| 260 |
assert: |
| 261 |
that: |
| 262 |
- 'result.changed' |
| 263 |
- result.cluster.identifier == redshift_cluster_name |
| 264 |
- 'result.cluster.db_name == "integration_test"' |
| 265 |
- 'result.cluster.tags.foo == "bar"' |
| 266 |
|
| 267 |
|
| 268 |
# ============================================================ |
| 269 |
|
| 270 |
- name: test purge tags |
| 271 |
redshift: |
| 272 |
command: create |
| 273 |
identifier: "{{ redshift_cluster_name }}" |
| 274 |
username: "{{ redshift_master_username }}" |
| 275 |
password: "{{ reshift_master_password }}" |
| 276 |
node_type: "{{ node_type }}" |
| 277 |
cluster_type: multi-node |
| 278 |
number_of_nodes: 3 |
| 279 |
wait: yes |
| 280 |
db_name: "integration_test" |
| 281 |
tags: |
| 282 |
test1: value1 |
| 283 |
purge_tags: false |
| 284 |
wait_timeout: 1800 |
| 285 |
register: result |
| 286 |
|
| 287 |
|
| 288 |
- name: assert tags change |
| 289 |
assert: |
| 290 |
that: |
| 291 |
- 'result.changed' |
| 292 |
- result.cluster.identifier == redshift_cluster_name |
| 293 |
- 'result.cluster.db_name == "integration_test"' |
| 294 |
- 'result.cluster.tags.test1 == "value1"' |
| 295 |
- 'result.cluster.tags.foo == "bar"' |
| 296 |
- 'result.cluster.tags | count() == 2' |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
# ============================================================ |
| 301 |
|
| 302 |
- name: test no change to tags when tags is None |
| 303 |
redshift: |
| 304 |
command: create |
| 305 |
identifier: "{{ redshift_cluster_name }}" |
| 306 |
username: "{{ redshift_master_username }}" |
| 307 |
password: "{{ reshift_master_password }}" |
| 308 |
node_type: "{{ node_type }}" |
| 309 |
cluster_type: multi-node |
| 310 |
number_of_nodes: 3 |
| 311 |
wait: yes |
| 312 |
db_name: "integration_test" |
| 313 |
wait_timeout: 1800 |
| 314 |
register: result |
| 315 |
|
| 316 |
|
| 317 |
- name: assert create |
| 318 |
assert: |
| 319 |
that: |
| 320 |
- 'not result.changed' |
| 321 |
- result.cluster.identifier == redshift_cluster_name |
| 322 |
- 'result.cluster.db_name == "integration_test"' |
| 323 |
- 'result.cluster.tags | count() == 2' |
| 324 |
|
| 325 |
|
| 326 |
# ============================================================ |
| 327 |
|
| 328 |
- name: test successful delete of multi-node cluster |
| 329 |
redshift: |
| 330 |
command: delete |
| 331 |
identifier: "{{ redshift_cluster_name }}" |
| 332 |
skip_final_cluster_snapshot: true |
| 333 |
wait: yes |
| 334 |
wait_timeout: 1200 |
| 335 |
register: result |
| 336 |
|
| 337 |
- name: assert delete |
| 338 |
assert: |
| 339 |
that: |
| 340 |
- 'result.changed' |
| 341 |
|
| 342 |
always: |
| 343 |
|
| 344 |
- name: Remove cluster if tests failed |
| 345 |
redshift: |
| 346 |
command: delete |
| 347 |
identifier: "{{ item }}" |
| 348 |
skip_final_cluster_snapshot: true |
| 349 |
wait: yes |
| 350 |
wait_timeout: 1200 |
| 351 |
register: cleanup |
| 352 |
ignore_errors: yes |
| 353 |
retries: 10 |
| 354 |
delay: 10 |
| 355 |
until: cleanup is success |
| 356 |
loop: |
| 357 |
- "{{ redshift_cluster_name }}" |
| 358 |
- "{{ redshift_cluster_name }}-modified" |