| 1 |
--- |
| 2 |
- name: Rds_instance / states 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 - check_mode |
| 25 |
amazon.aws.rds_instance: |
| 26 |
id: "{{ instance_id }}" |
| 27 |
state: present |
| 28 |
engine: mariadb |
| 29 |
username: "{{ username }}" |
| 30 |
password: "{{ password }}" |
| 31 |
db_instance_class: "{{ db_instance_class }}" |
| 32 |
allocated_storage: "{{ allocated_storage }}" |
| 33 |
deletion_protection: true |
| 34 |
tags: |
| 35 |
Name: "{{ instance_id }}" |
| 36 |
Created_by: Ansible rds_instance tests |
| 37 |
register: result |
| 38 |
check_mode: true |
| 39 |
|
| 40 |
- ansible.builtin.assert: |
| 41 |
that: |
| 42 |
- result.changed |
| 43 |
|
| 44 |
- name: Create a mariadb instance |
| 45 |
amazon.aws.rds_instance: |
| 46 |
id: "{{ instance_id }}" |
| 47 |
state: present |
| 48 |
engine: mariadb |
| 49 |
username: "{{ username }}" |
| 50 |
password: "{{ password }}" |
| 51 |
db_instance_class: "{{ db_instance_class }}" |
| 52 |
allocated_storage: "{{ allocated_storage }}" |
| 53 |
deletion_protection: true |
| 54 |
tags: |
| 55 |
Name: "{{ instance_id }}" |
| 56 |
Created_by: Ansible rds_instance tests |
| 57 |
register: result |
| 58 |
|
| 59 |
- ansible.builtin.assert: |
| 60 |
that: |
| 61 |
- result.changed |
| 62 |
- result.db_instance_identifier == instance_id |
| 63 |
- result.tags | length == 2 |
| 64 |
- result.tags.Name == instance_id |
| 65 |
- result.tags.Created_by == 'Ansible rds_instance tests' |
| 66 |
- result.deletion_protection == True |
| 67 |
|
| 68 |
- name: Create a mariadb instance (idempotence) - check_mode |
| 69 |
amazon.aws.rds_instance: |
| 70 |
id: "{{ instance_id }}" |
| 71 |
state: present |
| 72 |
engine: mariadb |
| 73 |
username: "{{ username }}" |
| 74 |
password: "{{ password }}" |
| 75 |
db_instance_class: "{{ db_instance_class }}" |
| 76 |
allocated_storage: "{{ allocated_storage }}" |
| 77 |
deletion_protection: true |
| 78 |
tags: |
| 79 |
Name: "{{ instance_id }}" |
| 80 |
Created_by: Ansible rds_instance tests |
| 81 |
register: result |
| 82 |
check_mode: true |
| 83 |
|
| 84 |
- ansible.builtin.assert: |
| 85 |
that: |
| 86 |
- not result.changed |
| 87 |
|
| 88 |
- name: Create a mariadb instance (idempotence) |
| 89 |
amazon.aws.rds_instance: |
| 90 |
id: "{{ instance_id }}" |
| 91 |
state: present |
| 92 |
engine: mariadb |
| 93 |
username: "{{ username }}" |
| 94 |
password: "{{ password }}" |
| 95 |
db_instance_class: "{{ db_instance_class }}" |
| 96 |
allocated_storage: "{{ allocated_storage }}" |
| 97 |
deletion_protection: true |
| 98 |
tags: |
| 99 |
Name: "{{ instance_id }}" |
| 100 |
Created_by: Ansible rds_instance tests |
| 101 |
register: result |
| 102 |
|
| 103 |
- ansible.builtin.assert: |
| 104 |
that: |
| 105 |
- not result.changed |
| 106 |
- result.db_instance_identifier == instance_id |
| 107 |
- result.tags | length == 2 |
| 108 |
- result.tags.Name == instance_id |
| 109 |
- result.tags.Created_by == 'Ansible rds_instance tests' |
| 110 |
- result.deletion_protection == True |
| 111 |
|
| 112 |
# ------------------------------------------------------------------------------------------ |
| 113 |
# Test stopping / rebooting instances |
| 114 |
|
| 115 |
- name: Reboot a stopped instance - check_mode |
| 116 |
amazon.aws.rds_instance: |
| 117 |
id: "{{ instance_id }}" |
| 118 |
state: rebooted |
| 119 |
register: result |
| 120 |
check_mode: true |
| 121 |
|
| 122 |
- ansible.builtin.assert: |
| 123 |
that: |
| 124 |
- result.changed |
| 125 |
|
| 126 |
- name: Reboot a stopped instance |
| 127 |
amazon.aws.rds_instance: |
| 128 |
id: "{{ instance_id }}" |
| 129 |
state: rebooted |
| 130 |
register: result |
| 131 |
|
| 132 |
- ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- result.changed |
| 135 |
|
| 136 |
# ------------------------------------------------------------------------------------------ |
| 137 |
|
| 138 |
- name: Stop the instance - check_mode |
| 139 |
amazon.aws.rds_instance: |
| 140 |
id: "{{ instance_id }}" |
| 141 |
state: stopped |
| 142 |
register: result |
| 143 |
check_mode: true |
| 144 |
|
| 145 |
- ansible.builtin.assert: |
| 146 |
that: |
| 147 |
- result.changed |
| 148 |
|
| 149 |
- name: Stop the instance |
| 150 |
amazon.aws.rds_instance: |
| 151 |
id: "{{ instance_id }}" |
| 152 |
state: stopped |
| 153 |
register: result |
| 154 |
|
| 155 |
- ansible.builtin.assert: |
| 156 |
that: |
| 157 |
- result.changed |
| 158 |
|
| 159 |
- name: Stop the instance (idempotence) - check_mode |
| 160 |
amazon.aws.rds_instance: |
| 161 |
id: "{{ instance_id }}" |
| 162 |
state: stopped |
| 163 |
register: result |
| 164 |
check_mode: true |
| 165 |
|
| 166 |
- ansible.builtin.assert: |
| 167 |
that: |
| 168 |
- not result.changed |
| 169 |
|
| 170 |
- name: Stop the instance (idempotence) |
| 171 |
amazon.aws.rds_instance: |
| 172 |
id: "{{ instance_id }}" |
| 173 |
state: stopped |
| 174 |
register: result |
| 175 |
|
| 176 |
- ansible.builtin.assert: |
| 177 |
that: |
| 178 |
- not result.changed |
| 179 |
|
| 180 |
# ------------------------------------------------------------------------------------------ |
| 181 |
|
| 182 |
- name: Start the instance - check_mode |
| 183 |
amazon.aws.rds_instance: |
| 184 |
id: "{{ instance_id }}" |
| 185 |
state: started |
| 186 |
register: result |
| 187 |
check_mode: true |
| 188 |
|
| 189 |
- ansible.builtin.assert: |
| 190 |
that: |
| 191 |
- result.changed |
| 192 |
|
| 193 |
- name: Start the instance |
| 194 |
amazon.aws.rds_instance: |
| 195 |
id: "{{ instance_id }}" |
| 196 |
state: started |
| 197 |
register: result |
| 198 |
|
| 199 |
- ansible.builtin.assert: |
| 200 |
that: |
| 201 |
- result.changed |
| 202 |
|
| 203 |
- name: Start the instance (idempotence) - check_mode |
| 204 |
amazon.aws.rds_instance: |
| 205 |
id: "{{ instance_id }}" |
| 206 |
state: started |
| 207 |
register: result |
| 208 |
check_mode: true |
| 209 |
|
| 210 |
- ansible.builtin.assert: |
| 211 |
that: |
| 212 |
- not result.changed |
| 213 |
|
| 214 |
- name: Start the instance (idempotence) |
| 215 |
amazon.aws.rds_instance: |
| 216 |
id: "{{ instance_id }}" |
| 217 |
state: started |
| 218 |
register: result |
| 219 |
|
| 220 |
- ansible.builtin.assert: |
| 221 |
that: |
| 222 |
- not result.changed |
| 223 |
|
| 224 |
# ------------------------------------------------------------------------------------------ |
| 225 |
# Test deletion protection / deletion |
| 226 |
|
| 227 |
- name: Ensure instance exists prior to deleting |
| 228 |
amazon.aws.rds_instance_info: |
| 229 |
db_instance_identifier: "{{ instance_id }}" |
| 230 |
register: db_info |
| 231 |
|
| 232 |
- ansible.builtin.assert: |
| 233 |
that: |
| 234 |
- db_info.instances | length == 1 |
| 235 |
|
| 236 |
- name: Attempt to delete DB instance with deletion protection (should fail) |
| 237 |
amazon.aws.rds_instance: |
| 238 |
id: "{{ instance_id }}" |
| 239 |
state: absent |
| 240 |
skip_final_snapshot: true |
| 241 |
register: result |
| 242 |
ignore_errors: true |
| 243 |
|
| 244 |
- ansible.builtin.assert: |
| 245 |
that: |
| 246 |
- result.failed |
| 247 |
|
| 248 |
- name: Turn off deletion protection |
| 249 |
amazon.aws.rds_instance: |
| 250 |
id: "{{ instance_id }}" |
| 251 |
deletion_protection: false |
| 252 |
register: result |
| 253 |
|
| 254 |
- ansible.builtin.assert: |
| 255 |
that: |
| 256 |
- result.changed |
| 257 |
- result.deletion_protection == False |
| 258 |
|
| 259 |
- name: Delete the instance - check_mode |
| 260 |
amazon.aws.rds_instance: |
| 261 |
id: "{{ instance_id }}" |
| 262 |
state: absent |
| 263 |
skip_final_snapshot: true |
| 264 |
register: result |
| 265 |
check_mode: true |
| 266 |
|
| 267 |
- ansible.builtin.assert: |
| 268 |
that: |
| 269 |
- result.changed |
| 270 |
|
| 271 |
- name: Delete the instance |
| 272 |
amazon.aws.rds_instance: |
| 273 |
id: "{{ instance_id }}" |
| 274 |
state: absent |
| 275 |
skip_final_snapshot: true |
| 276 |
register: result |
| 277 |
|
| 278 |
- ansible.builtin.assert: |
| 279 |
that: |
| 280 |
- result.changed |
| 281 |
|
| 282 |
- name: Ensure instance was deleted |
| 283 |
amazon.aws.rds_instance_info: |
| 284 |
db_instance_identifier: "{{ instance_id }}" |
| 285 |
register: db_info |
| 286 |
|
| 287 |
- ansible.builtin.assert: |
| 288 |
that: |
| 289 |
- db_info.instances | length == 0 |
| 290 |
|
| 291 |
- name: Delete the instance (idempotence) - check_mode |
| 292 |
amazon.aws.rds_instance: |
| 293 |
id: "{{ instance_id }}" |
| 294 |
state: absent |
| 295 |
skip_final_snapshot: true |
| 296 |
register: result |
| 297 |
check_mode: true |
| 298 |
|
| 299 |
- ansible.builtin.assert: |
| 300 |
that: |
| 301 |
- not result.changed |
| 302 |
|
| 303 |
- name: Delete the instance (idempotence) |
| 304 |
amazon.aws.rds_instance: |
| 305 |
id: "{{ instance_id }}" |
| 306 |
state: absent |
| 307 |
skip_final_snapshot: true |
| 308 |
register: result |
| 309 |
|
| 310 |
- ansible.builtin.assert: |
| 311 |
that: |
| 312 |
- not result.changed |
| 313 |
|
| 314 |
always: |
| 315 |
- name: Remove DB instance |
| 316 |
amazon.aws.rds_instance: |
| 317 |
id: "{{ instance_id }}" |
| 318 |
state: absent |
| 319 |
skip_final_snapshot: true |
| 320 |
wait: false |
| 321 |
ignore_errors: true |