| 1 |
--- |
| 2 |
- name: Rds_instance / modify integration tests |
| 3 |
|
| 4 |
module_defaults: |
| 5 |
group/aws: |
| 6 |
access_key: "{{ aws_access_key }}" |
| 7 |
secret_key: "{{ aws_secret_key }}" |
| 8 |
session_token: "{{ security_token | default(omit) }}" |
| 9 |
region: "{{ aws_region }}" |
| 10 |
|
| 11 |
block: |
| 12 |
- name: Ensure the resource doesn't exist |
| 13 |
amazon.aws.rds_instance: |
| 14 |
id: "{{ instance_id }}" |
| 15 |
state: absent |
| 16 |
skip_final_snapshot: true |
| 17 |
register: result |
| 18 |
|
| 19 |
- ansible.builtin.assert: |
| 20 |
that: |
| 21 |
- not result.changed |
| 22 |
ignore_errors: true |
| 23 |
|
| 24 |
- name: Create a mariadb instance |
| 25 |
amazon.aws.rds_instance: |
| 26 |
id: "{{ instance_id }}" |
| 27 |
state: present |
| 28 |
engine: mariadb |
| 29 |
engine_version: "{{ mariadb_engine_version }}" |
| 30 |
allow_major_version_upgrade: true |
| 31 |
username: "{{ username }}" |
| 32 |
password: "{{ password }}" |
| 33 |
db_instance_class: "{{ db_instance_class }}" |
| 34 |
allocated_storage: "{{ allocated_storage }}" |
| 35 |
tags: |
| 36 |
Name: "{{ instance_id }}" |
| 37 |
Created_by: Ansible rds_instance tests |
| 38 |
register: result |
| 39 |
|
| 40 |
- ansible.builtin.assert: |
| 41 |
that: |
| 42 |
- result.changed |
| 43 |
- result.db_instance_identifier == instance_id |
| 44 |
|
| 45 |
- name: Create a DB instance with an invalid engine |
| 46 |
amazon.aws.rds_instance: |
| 47 |
id: "{{ instance_id }}" |
| 48 |
state: present |
| 49 |
engine: thisisnotavalidengine |
| 50 |
username: "{{ username }}" |
| 51 |
password: "{{ password }}" |
| 52 |
db_instance_class: "{{ db_instance_class }}" |
| 53 |
allocated_storage: "{{ allocated_storage }}" |
| 54 |
register: result |
| 55 |
ignore_errors: true |
| 56 |
|
| 57 |
- ansible.builtin.assert: |
| 58 |
that: |
| 59 |
- result.failed |
| 60 |
- '"value of engine must be one of" in result.msg' |
| 61 |
|
| 62 |
- name: Add IAM roles to mariadb (should fail - iam roles not supported for mariadb) |
| 63 |
amazon.aws.rds_instance: |
| 64 |
id: "{{ instance_id }}" |
| 65 |
state: present |
| 66 |
engine: mariadb |
| 67 |
engine_version: "{{ mariadb_engine_version }}" |
| 68 |
allow_major_version_upgrade: true |
| 69 |
username: "{{ username }}" |
| 70 |
password: "{{ password }}" |
| 71 |
db_instance_class: "{{ db_instance_class }}" |
| 72 |
allocated_storage: "{{ allocated_storage }}" |
| 73 |
iam_roles: |
| 74 |
- role_arn: my_role |
| 75 |
feature_name: my_feature |
| 76 |
register: result |
| 77 |
ignore_errors: true |
| 78 |
|
| 79 |
- ansible.builtin.assert: |
| 80 |
that: |
| 81 |
- result.failed |
| 82 |
- '"is not valid for adding IAM roles" in result.msg' |
| 83 |
|
| 84 |
# TODO: test modifying db_subnet_group_name, db_security_groups, db_parameter_group_name, option_group_name, |
| 85 |
# monitoring_role_arn, monitoring_interval, domain, domain_iam_role_name |
| 86 |
|
| 87 |
# ------------------------------------------------------------------------------------------ |
| 88 |
- name: Modify the storage type without immediate application - check_mode |
| 89 |
amazon.aws.rds_instance: |
| 90 |
id: "{{ instance_id }}" |
| 91 |
state: present |
| 92 |
storage_type: gp3 |
| 93 |
apply_immediately: false |
| 94 |
register: result |
| 95 |
check_mode: true |
| 96 |
|
| 97 |
- ansible.builtin.assert: |
| 98 |
that: |
| 99 |
- result.changed |
| 100 |
- result.storage_type == "gp2" |
| 101 |
|
| 102 |
- name: Modify the storage type without immediate application |
| 103 |
amazon.aws.rds_instance: |
| 104 |
id: "{{ instance_id }}" |
| 105 |
state: present |
| 106 |
storage_type: gp3 |
| 107 |
apply_immediately: false |
| 108 |
register: result |
| 109 |
|
| 110 |
- ansible.builtin.assert: |
| 111 |
that: |
| 112 |
- result.changed |
| 113 |
- result.pending_modified_values.storage_type == "gp3" |
| 114 |
- result.storage_type == "gp2" |
| 115 |
|
| 116 |
- name: Modify the storage type without immediate application - idempotent |
| 117 |
amazon.aws.rds_instance: |
| 118 |
id: "{{ instance_id }}" |
| 119 |
state: present |
| 120 |
storage_type: gp3 |
| 121 |
apply_immediately: false |
| 122 |
register: result |
| 123 |
check_mode: true |
| 124 |
|
| 125 |
- ansible.builtin.assert: |
| 126 |
that: |
| 127 |
- not result.changed |
| 128 |
- result.pending_modified_values.storage_type == "gp3" |
| 129 |
- result.storage_type == "gp2" |
| 130 |
|
| 131 |
- name: Modify the storage type back to gp2 without immediate application |
| 132 |
amazon.aws.rds_instance: |
| 133 |
id: "{{ instance_id }}" |
| 134 |
state: present |
| 135 |
storage_type: gp2 |
| 136 |
apply_immediately: false |
| 137 |
register: result |
| 138 |
|
| 139 |
- ansible.builtin.assert: |
| 140 |
that: |
| 141 |
- result.changed |
| 142 |
- result.pending_modified_values == {} |
| 143 |
- result.storage_type == "gp2" |
| 144 |
|
| 145 |
- name: Modify the instance name without immediate application - check_mode |
| 146 |
amazon.aws.rds_instance: |
| 147 |
id: "{{ instance_id }}" |
| 148 |
state: present |
| 149 |
new_id: "{{ modified_instance_id }}" |
| 150 |
apply_immediately: false |
| 151 |
register: result |
| 152 |
check_mode: true |
| 153 |
|
| 154 |
- ansible.builtin.assert: |
| 155 |
that: |
| 156 |
- result.changed |
| 157 |
|
| 158 |
- name: Modify the instance name without immediate application |
| 159 |
amazon.aws.rds_instance: |
| 160 |
id: "{{ instance_id }}" |
| 161 |
state: present |
| 162 |
new_id: "{{ modified_instance_id }}" |
| 163 |
apply_immediately: false |
| 164 |
register: result |
| 165 |
|
| 166 |
- ansible.builtin.assert: |
| 167 |
that: |
| 168 |
- result.changed |
| 169 |
- result.db_instance_identifier == instance_id |
| 170 |
|
| 171 |
- name: Immediately apply the pending update - check_mode |
| 172 |
amazon.aws.rds_instance: |
| 173 |
id: "{{ instance_id }}" |
| 174 |
state: present |
| 175 |
new_id: "{{ modified_instance_id }}" |
| 176 |
apply_immediately: true |
| 177 |
register: result |
| 178 |
check_mode: true |
| 179 |
|
| 180 |
- ansible.builtin.assert: |
| 181 |
that: |
| 182 |
- result.changed |
| 183 |
|
| 184 |
- name: Immediately apply the pending update |
| 185 |
amazon.aws.rds_instance: |
| 186 |
id: "{{ instance_id }}" |
| 187 |
state: present |
| 188 |
new_id: "{{ modified_instance_id }}" |
| 189 |
apply_immediately: true |
| 190 |
register: result |
| 191 |
|
| 192 |
- ansible.builtin.assert: |
| 193 |
that: |
| 194 |
- result.changed |
| 195 |
- result.db_instance_identifier == modified_instance_id |
| 196 |
|
| 197 |
# Test modifying CA certificate identifier ------------------------------------------- |
| 198 |
|
| 199 |
- name: Modify the CA certificate identifier to rds-ca-ecc384-g1 - check_mode |
| 200 |
amazon.aws.rds_instance: |
| 201 |
state: present |
| 202 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 203 |
allow_major_version_upgrade: true |
| 204 |
ca_certificate_identifier: rds-ca-ecc384-g1 |
| 205 |
apply_immediately: true |
| 206 |
tags: |
| 207 |
Name: "{{ modified_instance_id }}" |
| 208 |
Created_by: Ansible rds_instance tests |
| 209 |
register: result |
| 210 |
check_mode: true |
| 211 |
|
| 212 |
- name: Get curent CA certificate identifier |
| 213 |
amazon.aws.rds_instance_info: |
| 214 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 215 |
register: db_info |
| 216 |
- name: Assert that CA certificate identifier has been modified - check_mode |
| 217 |
ansible.builtin.assert: |
| 218 |
that: |
| 219 |
- result is changed |
| 220 |
- result is not failed |
| 221 |
- db_info.instances[0].ca_certificate_identifier != "rds-ca-ecc384-g1" |
| 222 |
|
| 223 |
- name: Modify the CA certificate identifier to rds-ca-ecc384-g1 |
| 224 |
amazon.aws.rds_instance: |
| 225 |
state: present |
| 226 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 227 |
allow_major_version_upgrade: true |
| 228 |
ca_certificate_identifier: rds-ca-ecc384-g1 |
| 229 |
apply_immediately: true |
| 230 |
tags: |
| 231 |
Name: "{{ modified_instance_id }}" |
| 232 |
Created_by: Ansible rds_instance tests |
| 233 |
register: result |
| 234 |
|
| 235 |
- name: Get curent CA certificate identifier |
| 236 |
amazon.aws.rds_instance_info: |
| 237 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 238 |
register: db_info |
| 239 |
retries: 20 |
| 240 |
delay: 10 |
| 241 |
until: db_info.instances[0].ca_certificate_identifier == "rds-ca-ecc384-g1" |
| 242 |
- name: Assert that CA certificate identifier has been modified |
| 243 |
ansible.builtin.assert: |
| 244 |
that: |
| 245 |
- result is changed |
| 246 |
- result is not failed |
| 247 |
- db_info.instances[0].ca_certificate_identifier == "rds-ca-ecc384-g1" |
| 248 |
|
| 249 |
- name: Modify the CA certificate identifier to rds-ca-ecc384-g1 - idempotent |
| 250 |
amazon.aws.rds_instance: |
| 251 |
state: present |
| 252 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 253 |
ca_certificate_identifier: rds-ca-ecc384-g1 |
| 254 |
apply_immediately: true |
| 255 |
tags: |
| 256 |
Name: "{{ modified_instance_id }}" |
| 257 |
Created_by: Ansible rds_instance tests |
| 258 |
register: result |
| 259 |
|
| 260 |
- name: Get curent CA certificate identifier |
| 261 |
amazon.aws.rds_instance_info: |
| 262 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 263 |
register: db_info |
| 264 |
retries: 20 |
| 265 |
delay: 10 |
| 266 |
until: db_info.instances[0].ca_certificate_identifier == "rds-ca-ecc384-g1" |
| 267 |
- name: Assert that CA certificate identifier has been modified |
| 268 |
ansible.builtin.assert: |
| 269 |
that: |
| 270 |
- result is not changed |
| 271 |
- result is not failed |
| 272 |
- db_info.instances[0].ca_certificate_identifier == "rds-ca-ecc384-g1" |
| 273 |
|
| 274 |
- name: Modify the CA certificate identifier to rds-ca-ecc384-g1 - idempotent - check_mode |
| 275 |
amazon.aws.rds_instance: |
| 276 |
state: present |
| 277 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 278 |
ca_certificate_identifier: rds-ca-ecc384-g1 |
| 279 |
apply_immediately: true |
| 280 |
tags: |
| 281 |
Name: "{{ modified_instance_id }}" |
| 282 |
Created_by: Ansible rds_instance tests |
| 283 |
register: result |
| 284 |
check_mode: true |
| 285 |
|
| 286 |
- name: Get curent CA certificate identifier |
| 287 |
amazon.aws.rds_instance_info: |
| 288 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 289 |
register: db_info |
| 290 |
retries: 20 |
| 291 |
delay: 10 |
| 292 |
until: db_info.instances[0].ca_certificate_identifier == "rds-ca-ecc384-g1" |
| 293 |
- name: Assert that CA certificate identifier has been modified |
| 294 |
ansible.builtin.assert: |
| 295 |
that: |
| 296 |
- result is not changed |
| 297 |
- result is not failed |
| 298 |
- db_info.instances[0].ca_certificate_identifier == "rds-ca-ecc384-g1" |
| 299 |
# Test modifying CA certificate identifier Complete------------------------------------------- |
| 300 |
|
| 301 |
# Test modifying cloudwatch log exports ------------------------------------------- |
| 302 |
- name: Enable all cloudwatch log exports - check_mode |
| 303 |
amazon.aws.rds_instance: |
| 304 |
state: present |
| 305 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 306 |
enable_cloudwatch_logs_exports: ["audit", "error", "general", "slowquery"] |
| 307 |
register: result |
| 308 |
check_mode: true |
| 309 |
|
| 310 |
- name: Get current cloudwatch log exports |
| 311 |
amazon.aws.rds_instance_info: |
| 312 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 313 |
register: db_info |
| 314 |
- name: Assert that cloudwatch log exports has been modified - check_mode |
| 315 |
ansible.builtin.assert: |
| 316 |
that: |
| 317 |
- result is changed |
| 318 |
- result is not failed |
| 319 |
- db_info.instances[0].enabled_cloudwatch_logs_exports is not defined |
| 320 |
|
| 321 |
- name: Enable all cloudwatch log exports |
| 322 |
amazon.aws.rds_instance: |
| 323 |
state: present |
| 324 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 325 |
enable_cloudwatch_logs_exports: ["audit", "error", "general", "slowquery"] |
| 326 |
register: result |
| 327 |
|
| 328 |
- name: Get current cloudwatch log exports |
| 329 |
amazon.aws.rds_instance_info: |
| 330 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 331 |
register: db_info |
| 332 |
# It applies immediately but takes a couple seconds |
| 333 |
until: |
| 334 |
- db_info.instances[0].db_instance_status == 'available' |
| 335 |
- not db_info.instances[0].pending_modified_values |
| 336 |
retries: 10 |
| 337 |
delay: 20 |
| 338 |
|
| 339 |
- name: Assert that cloudwatch log exports has been modified |
| 340 |
ansible.builtin.assert: |
| 341 |
that: |
| 342 |
- result is changed |
| 343 |
- result is not failed |
| 344 |
- db_info.instances[0].enabled_cloudwatch_logs_exports | length == 4 |
| 345 |
|
| 346 |
- name: Enable all cloudwatch log exports - idempotent |
| 347 |
amazon.aws.rds_instance: |
| 348 |
state: present |
| 349 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 350 |
enable_cloudwatch_logs_exports: ["audit", "error", "general", "slowquery"] |
| 351 |
register: result |
| 352 |
|
| 353 |
- name: Get current cloudwatch log exports |
| 354 |
amazon.aws.rds_instance_info: |
| 355 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 356 |
register: db_info |
| 357 |
- name: Assert that cloudwatch log exports has not been modified |
| 358 |
ansible.builtin.assert: |
| 359 |
that: |
| 360 |
- result is not changed |
| 361 |
- result is not failed |
| 362 |
- not result.pending_modified_values |
| 363 |
- db_info.instances[0].enabled_cloudwatch_logs_exports | length == 4 |
| 364 |
|
| 365 |
- name: Disable some cloudwatch log exports - check_mode |
| 366 |
amazon.aws.rds_instance: |
| 367 |
state: present |
| 368 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 369 |
enable_cloudwatch_logs_exports: ["audit", "error"] |
| 370 |
register: result |
| 371 |
check_mode: true |
| 372 |
|
| 373 |
- name: Get current cloudwatch log exports |
| 374 |
amazon.aws.rds_instance_info: |
| 375 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 376 |
register: db_info |
| 377 |
- name: Assert that cloudwatch log exports has been modified - check_mode |
| 378 |
ansible.builtin.assert: |
| 379 |
that: |
| 380 |
- result is changed |
| 381 |
- result is not failed |
| 382 |
- db_info.instances[0].enabled_cloudwatch_logs_exports | length == 4 |
| 383 |
|
| 384 |
- name: Disable some cloudwatch log exports |
| 385 |
amazon.aws.rds_instance: |
| 386 |
state: present |
| 387 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 388 |
enable_cloudwatch_logs_exports: ["audit", "error"] |
| 389 |
register: result |
| 390 |
|
| 391 |
- name: Get current cloudwatch log exports |
| 392 |
amazon.aws.rds_instance_info: |
| 393 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 394 |
register: db_info |
| 395 |
until: |
| 396 |
- db_info.instances[0].db_instance_status == 'available' |
| 397 |
- not db_info.instances[0].pending_modified_values |
| 398 |
retries: 10 |
| 399 |
delay: 20 |
| 400 |
|
| 401 |
- name: Assert that cloudwatch log exports has been modified |
| 402 |
ansible.builtin.assert: |
| 403 |
that: |
| 404 |
- result is changed |
| 405 |
- result is not failed |
| 406 |
- db_info.instances[0].enabled_cloudwatch_logs_exports | length == 2 |
| 407 |
|
| 408 |
- name: Disable all cloudwatch log exports - no purge |
| 409 |
amazon.aws.rds_instance: |
| 410 |
state: present |
| 411 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 412 |
enable_cloudwatch_logs_exports: [] |
| 413 |
purge_cloudwatch_logs_exports: false |
| 414 |
register: result |
| 415 |
|
| 416 |
- name: Get current cloudwatch log exports |
| 417 |
amazon.aws.rds_instance_info: |
| 418 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 419 |
register: db_info |
| 420 |
- name: Assert that cloudwatch log exports has not been modified |
| 421 |
ansible.builtin.assert: |
| 422 |
that: |
| 423 |
- result is not changed |
| 424 |
- result is not failed |
| 425 |
- not result.pending_modified_values |
| 426 |
- db_info.instances[0].enabled_cloudwatch_logs_exports | length == 2 |
| 427 |
|
| 428 |
- name: Disable all cloudwatch log exports - check_mode |
| 429 |
amazon.aws.rds_instance: |
| 430 |
state: present |
| 431 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 432 |
enable_cloudwatch_logs_exports: [] |
| 433 |
register: result |
| 434 |
check_mode: true |
| 435 |
|
| 436 |
- name: Get current cloudwatch log exports |
| 437 |
amazon.aws.rds_instance_info: |
| 438 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 439 |
register: db_info |
| 440 |
- name: Assert that cloudwatch log exports has been modified - check_mode |
| 441 |
ansible.builtin.assert: |
| 442 |
that: |
| 443 |
- result is changed |
| 444 |
- result is not failed |
| 445 |
- db_info.instances[0].enabled_cloudwatch_logs_exports | length == 2 |
| 446 |
|
| 447 |
- name: Disable all cloudwatch log exports |
| 448 |
amazon.aws.rds_instance: |
| 449 |
state: present |
| 450 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 451 |
enable_cloudwatch_logs_exports: [] |
| 452 |
register: result |
| 453 |
|
| 454 |
- name: Get current cloudwatch log exports |
| 455 |
amazon.aws.rds_instance_info: |
| 456 |
db_instance_identifier: "{{ modified_instance_id }}" |
| 457 |
register: db_info |
| 458 |
until: |
| 459 |
- db_info.instances[0].db_instance_status == 'available' |
| 460 |
- not db_info.instances[0].pending_modified_values |
| 461 |
retries: 10 |
| 462 |
delay: 20 |
| 463 |
|
| 464 |
- name: Assert that cloudwatch log exports has been modified |
| 465 |
ansible.builtin.assert: |
| 466 |
that: |
| 467 |
- result is changed |
| 468 |
- result is not failed |
| 469 |
- db_info.instances[0].enabled_cloudwatch_logs_exports is not defined |
| 470 |
# Test modifying cloudwatch log exports Complete------------------------------------------- |
| 471 |
|
| 472 |
always: |
| 473 |
- name: Delete the instance |
| 474 |
amazon.aws.rds_instance: |
| 475 |
id: "{{ item }}" |
| 476 |
state: absent |
| 477 |
skip_final_snapshot: true |
| 478 |
wait: false |
| 479 |
ignore_errors: true |
| 480 |
loop: |
| 481 |
- "{{ instance_id }}" |
| 482 |
- "{{ modified_instance_id }}" |