| 1 |
--- |
| 2 |
- name: Rds_instance / sgroups 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: Create a VPC |
| 13 |
amazon.aws.ec2_vpc_net: |
| 14 |
name: "{{ resource_prefix }}-vpc" |
| 15 |
state: present |
| 16 |
cidr_block: 10.122.122.128/26 |
| 17 |
tags: |
| 18 |
Name: "{{ resource_prefix }}-vpc" |
| 19 |
Description: created by rds_instance integration tests |
| 20 |
register: vpc_result |
| 21 |
|
| 22 |
- name: Create subnets |
| 23 |
amazon.aws.ec2_vpc_subnet: |
| 24 |
cidr: "{{ item.cidr }}" |
| 25 |
az: "{{ item.zone }}" |
| 26 |
vpc_id: "{{ vpc_result.vpc.id }}" |
| 27 |
tags: |
| 28 |
Name: "{{ resource_prefix }}-subnet" |
| 29 |
Description: created by rds_instance integration tests |
| 30 |
state: present |
| 31 |
register: subnets_result |
| 32 |
loop: |
| 33 |
- { cidr: 10.122.122.128/28, zone: "{{ aws_region }}a" } |
| 34 |
- { cidr: 10.122.122.144/28, zone: "{{ aws_region }}b" } |
| 35 |
- { cidr: 10.122.122.160/28, zone: "{{ aws_region }}c" } |
| 36 |
|
| 37 |
- name: Create security groups |
| 38 |
amazon.aws.ec2_security_group: |
| 39 |
name: "{{ item }}" |
| 40 |
description: created by rds_instance integration tests |
| 41 |
state: present |
| 42 |
register: sgs_result |
| 43 |
loop: |
| 44 |
- "{{ resource_prefix }}-sg-1" |
| 45 |
- "{{ resource_prefix }}-sg-2" |
| 46 |
- "{{ resource_prefix }}-sg-3" |
| 47 |
|
| 48 |
- name: Ensure the resource doesn't exist |
| 49 |
amazon.aws.rds_instance: |
| 50 |
id: "{{ instance_id }}" |
| 51 |
state: absent |
| 52 |
skip_final_snapshot: true |
| 53 |
register: result |
| 54 |
|
| 55 |
- ansible.builtin.assert: |
| 56 |
that: |
| 57 |
- not result.changed |
| 58 |
ignore_errors: true |
| 59 |
|
| 60 |
# ------------------------------------------------------------------------------------------ |
| 61 |
|
| 62 |
- name: Create a DB instance in the VPC with two security groups - check_mode |
| 63 |
amazon.aws.rds_instance: |
| 64 |
id: "{{ instance_id }}" |
| 65 |
state: present |
| 66 |
engine: mariadb |
| 67 |
username: "{{ username }}" |
| 68 |
password: "{{ password }}" |
| 69 |
db_instance_class: "{{ db_instance_class }}" |
| 70 |
allocated_storage: "{{ allocated_storage }}" |
| 71 |
vpc_security_group_ids: |
| 72 |
- "{{ sgs_result.results.0.group_id }}" |
| 73 |
- "{{ sgs_result.results.1.group_id }}" |
| 74 |
register: result |
| 75 |
check_mode: true |
| 76 |
|
| 77 |
- ansible.builtin.assert: |
| 78 |
that: |
| 79 |
- result.changed |
| 80 |
|
| 81 |
- name: Create a DB instance in the VPC with two security groups |
| 82 |
amazon.aws.rds_instance: |
| 83 |
id: "{{ instance_id }}" |
| 84 |
state: present |
| 85 |
engine: mariadb |
| 86 |
username: "{{ username }}" |
| 87 |
password: "{{ password }}" |
| 88 |
db_instance_class: "{{ db_instance_class }}" |
| 89 |
allocated_storage: "{{ allocated_storage }}" |
| 90 |
vpc_security_group_ids: |
| 91 |
- "{{ sgs_result.results.0.group_id }}" |
| 92 |
- "{{ sgs_result.results.1.group_id }}" |
| 93 |
register: result |
| 94 |
|
| 95 |
- ansible.builtin.assert: |
| 96 |
that: |
| 97 |
- result.changed |
| 98 |
- result.db_instance_identifier == instance_id |
| 99 |
- result.vpc_security_groups | selectattr('status', 'in', ['active', 'adding']) | list | length == 2 |
| 100 |
|
| 101 |
- name: Create a DB instance in the VPC with two security groups (idempotence) - check_mode |
| 102 |
amazon.aws.rds_instance: |
| 103 |
id: "{{ instance_id }}" |
| 104 |
state: present |
| 105 |
engine: mariadb |
| 106 |
username: "{{ username }}" |
| 107 |
password: "{{ password }}" |
| 108 |
db_instance_class: "{{ db_instance_class }}" |
| 109 |
allocated_storage: "{{ allocated_storage }}" |
| 110 |
vpc_security_group_ids: |
| 111 |
- "{{ sgs_result.results.0.group_id }}" |
| 112 |
- "{{ sgs_result.results.1.group_id }}" |
| 113 |
register: result |
| 114 |
check_mode: true |
| 115 |
|
| 116 |
- ansible.builtin.assert: |
| 117 |
that: |
| 118 |
- not result.changed |
| 119 |
|
| 120 |
- name: Create a DB instance in the VPC with two security groups (idempotence) |
| 121 |
amazon.aws.rds_instance: |
| 122 |
id: "{{ instance_id }}" |
| 123 |
state: present |
| 124 |
engine: mariadb |
| 125 |
username: "{{ username }}" |
| 126 |
password: "{{ password }}" |
| 127 |
db_instance_class: "{{ db_instance_class }}" |
| 128 |
allocated_storage: "{{ allocated_storage }}" |
| 129 |
vpc_security_group_ids: |
| 130 |
- "{{ sgs_result.results.0.group_id }}" |
| 131 |
- "{{ sgs_result.results.1.group_id }}" |
| 132 |
register: result |
| 133 |
|
| 134 |
- ansible.builtin.assert: |
| 135 |
that: |
| 136 |
- not result.changed |
| 137 |
- result.db_instance_identifier == instance_id |
| 138 |
- result.vpc_security_groups | selectattr('status', 'in', ['active', 'adding']) | list | length == 2 |
| 139 |
|
| 140 |
# ------------------------------------------------------------------------------------------ |
| 141 |
|
| 142 |
- name: Add a new security group without purge - check_mode |
| 143 |
amazon.aws.rds_instance: |
| 144 |
id: "{{ instance_id }}" |
| 145 |
state: present |
| 146 |
vpc_security_group_ids: |
| 147 |
- "{{ sgs_result.results.2.group_id }}" |
| 148 |
apply_immediately: true |
| 149 |
purge_security_groups: false |
| 150 |
check_mode: true |
| 151 |
register: result |
| 152 |
|
| 153 |
- ansible.builtin.assert: |
| 154 |
that: |
| 155 |
- result.changed |
| 156 |
- result.db_instance_identifier == instance_id |
| 157 |
|
| 158 |
- name: Add a new security group without purge |
| 159 |
amazon.aws.rds_instance: |
| 160 |
id: "{{ instance_id }}" |
| 161 |
state: present |
| 162 |
vpc_security_group_ids: |
| 163 |
- "{{ sgs_result.results.2.group_id }}" |
| 164 |
apply_immediately: true |
| 165 |
purge_security_groups: false |
| 166 |
register: result |
| 167 |
|
| 168 |
- ansible.builtin.assert: |
| 169 |
that: |
| 170 |
- result.changed |
| 171 |
- result.db_instance_identifier == instance_id |
| 172 |
- result.vpc_security_groups | selectattr('status', 'in', ['active', 'adding']) | list | length == 3 |
| 173 |
|
| 174 |
- name: Add a new security group without purge (idempotence) - check_mode |
| 175 |
amazon.aws.rds_instance: |
| 176 |
id: "{{ instance_id }}" |
| 177 |
state: present |
| 178 |
vpc_security_group_ids: |
| 179 |
- "{{ sgs_result.results.2.group_id }}" |
| 180 |
apply_immediately: true |
| 181 |
purge_security_groups: false |
| 182 |
register: result |
| 183 |
check_mode: true |
| 184 |
|
| 185 |
- ansible.builtin.assert: |
| 186 |
that: |
| 187 |
- not result.changed |
| 188 |
- result.db_instance_identifier == instance_id |
| 189 |
|
| 190 |
- name: Add a new security group without purge (idempotence) |
| 191 |
amazon.aws.rds_instance: |
| 192 |
id: "{{ instance_id }}" |
| 193 |
state: present |
| 194 |
vpc_security_group_ids: |
| 195 |
- "{{ sgs_result.results.2.group_id }}" |
| 196 |
apply_immediately: true |
| 197 |
purge_security_groups: false |
| 198 |
register: result |
| 199 |
|
| 200 |
- ansible.builtin.assert: |
| 201 |
that: |
| 202 |
- not result.changed |
| 203 |
- result.db_instance_identifier == instance_id |
| 204 |
- result.vpc_security_groups | selectattr('status', 'in', ['active', 'adding']) | list | length == 3 |
| 205 |
|
| 206 |
# ------------------------------------------------------------------------------------------ |
| 207 |
|
| 208 |
- name: Add a security group with purge - check_mode |
| 209 |
amazon.aws.rds_instance: |
| 210 |
id: "{{ instance_id }}" |
| 211 |
state: present |
| 212 |
vpc_security_group_ids: |
| 213 |
- "{{ sgs_result.results.2.group_id }}" |
| 214 |
apply_immediately: true |
| 215 |
register: result |
| 216 |
check_mode: true |
| 217 |
|
| 218 |
- ansible.builtin.assert: |
| 219 |
that: |
| 220 |
- result.changed |
| 221 |
|
| 222 |
- name: Add a security group with purge |
| 223 |
amazon.aws.rds_instance: |
| 224 |
id: "{{ instance_id }}" |
| 225 |
state: present |
| 226 |
vpc_security_group_ids: |
| 227 |
- "{{ sgs_result.results.2.group_id }}" |
| 228 |
apply_immediately: true |
| 229 |
register: result |
| 230 |
|
| 231 |
- ansible.builtin.assert: |
| 232 |
that: |
| 233 |
- result.changed |
| 234 |
- result.db_instance_identifier == instance_id |
| 235 |
- result.vpc_security_groups | selectattr('status', 'in', ['active', 'adding']) | list | length == 1 |
| 236 |
- result.vpc_security_groups | selectattr('status', 'equalto', 'removing') | list | length == 2 |
| 237 |
|
| 238 |
- name: Add a security group with purge (idempotence) - check_mode |
| 239 |
amazon.aws.rds_instance: |
| 240 |
id: "{{ instance_id }}" |
| 241 |
state: present |
| 242 |
vpc_security_group_ids: |
| 243 |
- "{{ sgs_result.results.2.group_id }}" |
| 244 |
apply_immediately: true |
| 245 |
register: result |
| 246 |
check_mode: true |
| 247 |
|
| 248 |
- ansible.builtin.assert: |
| 249 |
that: |
| 250 |
- not result.changed |
| 251 |
|
| 252 |
- name: Add a security group with purge (idempotence) |
| 253 |
amazon.aws.rds_instance: |
| 254 |
id: "{{ instance_id }}" |
| 255 |
state: present |
| 256 |
vpc_security_group_ids: |
| 257 |
- "{{ sgs_result.results.2.group_id }}" |
| 258 |
apply_immediately: true |
| 259 |
register: result |
| 260 |
|
| 261 |
- ansible.builtin.assert: |
| 262 |
that: |
| 263 |
- not result.changed |
| 264 |
- result.db_instance_identifier == instance_id |
| 265 |
- result.vpc_security_groups | selectattr('status', 'in', ['active', 'adding']) | list | length == 1 |
| 266 |
|
| 267 |
always: |
| 268 |
- name: Ensure the resource doesn't exist |
| 269 |
amazon.aws.rds_instance: |
| 270 |
id: "{{ instance_id }}" |
| 271 |
state: absent |
| 272 |
skip_final_snapshot: true |
| 273 |
register: result |
| 274 |
ignore_errors: true |
| 275 |
|
| 276 |
- name: Remove security groups |
| 277 |
amazon.aws.ec2_security_group: |
| 278 |
name: "{{ item }}" |
| 279 |
description: created by rds_instance integration tests |
| 280 |
state: absent |
| 281 |
register: sgs_result |
| 282 |
loop: |
| 283 |
- "{{ resource_prefix }}-sg-1" |
| 284 |
- "{{ resource_prefix }}-sg-2" |
| 285 |
- "{{ resource_prefix }}-sg-3" |
| 286 |
ignore_errors: true |
| 287 |
retries: 30 |
| 288 |
until: sgs_result is not failed |
| 289 |
delay: 10 |
| 290 |
|
| 291 |
- name: Remove subnets |
| 292 |
amazon.aws.ec2_vpc_subnet: |
| 293 |
cidr: "{{ item.cidr }}" |
| 294 |
az: "{{ item.zone }}" |
| 295 |
vpc_id: "{{ vpc_result.vpc.id }}" |
| 296 |
tags: |
| 297 |
Name: "{{ resource_prefix }}-subnet" |
| 298 |
Description: created by rds_instance integration tests |
| 299 |
state: absent |
| 300 |
register: subnets |
| 301 |
ignore_errors: true |
| 302 |
retries: 30 |
| 303 |
until: subnets is not failed |
| 304 |
delay: 10 |
| 305 |
loop: |
| 306 |
- { cidr: 10.122.122.128/28, zone: "{{ aws_region }}a" } |
| 307 |
- { cidr: 10.122.122.144/28, zone: "{{ aws_region }}b" } |
| 308 |
- { cidr: 10.122.122.160/28, zone: "{{ aws_region }}c" } |
| 309 |
- { cidr: 10.122.122.176/28, zone: "{{ aws_region }}d" } |
| 310 |
|
| 311 |
- name: Delete VPC |
| 312 |
amazon.aws.ec2_vpc_net: |
| 313 |
name: "{{ resource_prefix }}-vpc" |
| 314 |
state: absent |
| 315 |
cidr_block: 10.122.122.128/26 |
| 316 |
tags: |
| 317 |
Name: "{{ resource_prefix }}-vpc" |
| 318 |
Description: created by rds_instance integration tests |
| 319 |
register: vpc_result |
| 320 |
ignore_errors: true |
| 321 |
retries: 30 |
| 322 |
until: vpc_result is not failed |
| 323 |
delay: 10 |