| 1 |
--- |
| 2 |
- name: Try running some rapid fire create/delete tests |
| 3 |
block: |
| 4 |
- name: Minimal IAM Role without instance profile (rapid) |
| 5 |
amazon.aws.iam_role: |
| 6 |
name: "{{ test_role }}" |
| 7 |
create_instance_profile: false |
| 8 |
register: iam_role |
| 9 |
- name: Minimal IAM Role without instance profile (rapid) |
| 10 |
amazon.aws.iam_role: |
| 11 |
name: "{{ test_role }}" |
| 12 |
create_instance_profile: false |
| 13 |
register: iam_role_again |
| 14 |
- ansible.builtin.assert: |
| 15 |
that: |
| 16 |
- iam_role is changed |
| 17 |
- iam_role_again is not changed |
| 18 |
|
| 19 |
- name: Remove IAM Role (rapid) |
| 20 |
amazon.aws.iam_role: |
| 21 |
state: absent |
| 22 |
name: "{{ test_role }}" |
| 23 |
register: iam_role |
| 24 |
- name: Remove IAM Role (rapid) |
| 25 |
amazon.aws.iam_role: |
| 26 |
state: absent |
| 27 |
name: "{{ test_role }}" |
| 28 |
register: iam_role_again |
| 29 |
- ansible.builtin.assert: |
| 30 |
that: |
| 31 |
- iam_role is changed |
| 32 |
- iam_role_again is not changed |
| 33 |
|
| 34 |
- name: Minimal IAM Role without instance profile (rapid) |
| 35 |
amazon.aws.iam_role: |
| 36 |
name: "{{ test_role }}" |
| 37 |
create_instance_profile: false |
| 38 |
register: iam_role |
| 39 |
- name: Remove IAM Role (rapid) |
| 40 |
amazon.aws.iam_role: |
| 41 |
state: absent |
| 42 |
name: "{{ test_role }}" |
| 43 |
register: iam_role_again |
| 44 |
- ansible.builtin.assert: |
| 45 |
that: |
| 46 |
- iam_role is changed |
| 47 |
- iam_role_again is changed |
| 48 |
|
| 49 |
# =================================================================== |
| 50 |
# Role Creation |
| 51 |
# (without Instance profile) |
| 52 |
- name: Iam_role_info before Role creation (no args) |
| 53 |
amazon.aws.iam_role_info: |
| 54 |
register: role_info |
| 55 |
- ansible.builtin.assert: |
| 56 |
that: |
| 57 |
- role_info is succeeded |
| 58 |
|
| 59 |
- name: Iam_role_info before Role creation (search for test role) |
| 60 |
amazon.aws.iam_role_info: |
| 61 |
name: "{{ test_role }}" |
| 62 |
register: role_info |
| 63 |
- ansible.builtin.assert: |
| 64 |
that: |
| 65 |
- role_info is succeeded |
| 66 |
- role_info.iam_roles | length == 0 |
| 67 |
|
| 68 |
- name: Minimal IAM Role (CHECK MODE) |
| 69 |
amazon.aws.iam_role: |
| 70 |
name: "{{ test_role }}" |
| 71 |
create_instance_profile: false |
| 72 |
register: iam_role |
| 73 |
check_mode: true |
| 74 |
- ansible.builtin.assert: |
| 75 |
that: |
| 76 |
- iam_role is changed |
| 77 |
|
| 78 |
- name: Iam_role_info after Role creation in check_mode |
| 79 |
amazon.aws.iam_role_info: |
| 80 |
name: "{{ test_role }}" |
| 81 |
register: role_info |
| 82 |
- ansible.builtin.assert: |
| 83 |
that: |
| 84 |
- role_info is succeeded |
| 85 |
- role_info.iam_roles | length == 0 |
| 86 |
|
| 87 |
- name: Minimal IAM Role without instance profile |
| 88 |
amazon.aws.iam_role: |
| 89 |
name: "{{ test_role }}" |
| 90 |
create_instance_profile: false |
| 91 |
register: iam_role |
| 92 |
- ansible.builtin.assert: |
| 93 |
that: |
| 94 |
- iam_role is changed |
| 95 |
- iam_role.iam_role.role_name == test_role |
| 96 |
- iam_role.iam_role.arn.startswith("arn") |
| 97 |
- iam_role.iam_role.arn.endswith("role/" + test_role ) |
| 98 |
- '"assume_role_policy_document" in iam_role.iam_role' |
| 99 |
- '"assume_role_policy_document_raw" in iam_role.iam_role' |
| 100 |
- iam_role.iam_role.assume_role_policy_document_raw == assume_deny_policy |
| 101 |
- iam_role.iam_role.attached_policies | length == 0 |
| 102 |
- iam_role.iam_role.max_session_duration == 3600 |
| 103 |
- iam_role.iam_role.path == '/' |
| 104 |
- iam_role.iam_role.role_name == test_role |
| 105 |
- '"create_date" in iam_role.iam_role' |
| 106 |
- '"role_id" in iam_role.iam_role' |
| 107 |
|
| 108 |
- name: Minimal IAM Role without instance profile (no change) - check mode |
| 109 |
amazon.aws.iam_role: |
| 110 |
name: "{{ test_role }}" |
| 111 |
create_instance_profile: false |
| 112 |
register: iam_role |
| 113 |
check_mode: true |
| 114 |
- ansible.builtin.assert: |
| 115 |
that: |
| 116 |
- iam_role is not changed |
| 117 |
|
| 118 |
- name: Minimal IAM Role without instance profile (no change) |
| 119 |
amazon.aws.iam_role: |
| 120 |
name: "{{ test_role }}" |
| 121 |
create_instance_profile: false |
| 122 |
register: iam_role |
| 123 |
- ansible.builtin.assert: |
| 124 |
that: |
| 125 |
- iam_role is not changed |
| 126 |
- iam_role.iam_role.role_name == test_role |
| 127 |
|
| 128 |
- name: Iam_role_info after Role creation |
| 129 |
amazon.aws.iam_role_info: |
| 130 |
name: "{{ test_role }}" |
| 131 |
register: role_info |
| 132 |
- ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- role_info is succeeded |
| 135 |
- role_info.iam_roles | length == 1 |
| 136 |
- role_info.iam_roles[0].arn.startswith("arn") |
| 137 |
- role_info.iam_roles[0].arn.endswith("role/" + test_role ) |
| 138 |
- '"assume_role_policy_document" in role_info.iam_roles[0]' |
| 139 |
- '"assume_role_policy_document_raw" in role_info.iam_roles[0]' |
| 140 |
- '"create_date" in role_info.iam_roles[0]' |
| 141 |
- '"description" not in role_info.iam_roles[0]' |
| 142 |
- role_info.iam_roles[0].assume_role_policy_document_raw == assume_deny_policy |
| 143 |
- role_info.iam_roles[0].inline_policies | length == 0 |
| 144 |
- role_info.iam_roles[0].instance_profiles | length == 0 |
| 145 |
- role_info.iam_roles[0].managed_policies | length == 0 |
| 146 |
- role_info.iam_roles[0].max_session_duration == 3600 |
| 147 |
- role_info.iam_roles[0].path == '/' |
| 148 |
- '"permissions_boundary" not in role_info.iam_roles[0]' |
| 149 |
- role_info.iam_roles[0].role_id == iam_role.iam_role.role_id |
| 150 |
- role_info.iam_roles[0].role_name == test_role |
| 151 |
- role_info.iam_roles[0].tags | length == 0 |
| 152 |
|
| 153 |
- name: Remove IAM Role |
| 154 |
amazon.aws.iam_role: |
| 155 |
state: absent |
| 156 |
name: "{{ test_role }}" |
| 157 |
delete_instance_profile: true |
| 158 |
register: iam_role |
| 159 |
- ansible.builtin.assert: |
| 160 |
that: |
| 161 |
- iam_role is changed |
| 162 |
|
| 163 |
- name: Iam_role_info after Role deletion |
| 164 |
amazon.aws.iam_role_info: |
| 165 |
name: "{{ test_role }}" |
| 166 |
register: role_info |
| 167 |
- ansible.builtin.assert: |
| 168 |
that: |
| 169 |
- role_info is succeeded |
| 170 |
- role_info.iam_roles | length == 0 |
| 171 |
|
| 172 |
# ------------------------------------------------------------------------------------------ |
| 173 |
|
| 174 |
# (with path) |
| 175 |
- name: Minimal IAM Role with path (CHECK MODE) |
| 176 |
amazon.aws.iam_role: |
| 177 |
name: "{{ test_role }}" |
| 178 |
path: "{{ test_path }}" |
| 179 |
register: iam_role |
| 180 |
check_mode: true |
| 181 |
- ansible.builtin.assert: |
| 182 |
that: |
| 183 |
- iam_role is changed |
| 184 |
|
| 185 |
- name: Minimal IAM Role with path |
| 186 |
amazon.aws.iam_role: |
| 187 |
name: "{{ test_role }}" |
| 188 |
path: "{{ test_path }}" |
| 189 |
register: iam_role |
| 190 |
- ansible.builtin.assert: |
| 191 |
that: |
| 192 |
- iam_role is changed |
| 193 |
- iam_role.iam_role.role_name == test_role |
| 194 |
- iam_role.iam_role.arn.startswith("arn") |
| 195 |
- iam_role.iam_role.arn.endswith("role" + test_path + test_role ) |
| 196 |
# Would be nice to test the contents... |
| 197 |
- '"assume_role_policy_document" in iam_role.iam_role' |
| 198 |
- iam_role.iam_role.attached_policies | length == 0 |
| 199 |
- iam_role.iam_role.max_session_duration == 3600 |
| 200 |
- iam_role.iam_role.path == test_path |
| 201 |
- iam_role.iam_role.role_name == test_role |
| 202 |
- '"create_date" in iam_role.iam_role' |
| 203 |
- '"role_id" in iam_role.iam_role' |
| 204 |
|
| 205 |
- name: Minimal IAM Role with path (no change) - check mode |
| 206 |
amazon.aws.iam_role: |
| 207 |
name: "{{ test_role }}" |
| 208 |
path: "{{ test_path }}" |
| 209 |
register: iam_role |
| 210 |
check_mode: true |
| 211 |
- ansible.builtin.assert: |
| 212 |
that: |
| 213 |
- iam_role is not changed |
| 214 |
|
| 215 |
- name: Minimal IAM Role with path (no change) |
| 216 |
amazon.aws.iam_role: |
| 217 |
name: "{{ test_role }}" |
| 218 |
path: "{{ test_path }}" |
| 219 |
register: iam_role |
| 220 |
- ansible.builtin.assert: |
| 221 |
that: |
| 222 |
- iam_role is not changed |
| 223 |
- iam_role.iam_role.role_name == test_role |
| 224 |
|
| 225 |
- name: Minimal IAM Role with updated path (no change) |
| 226 |
amazon.aws.iam_role: |
| 227 |
name: "{{ test_role }}" |
| 228 |
path: "{{ test_path }}subpath/" |
| 229 |
register: iam_role |
| 230 |
|
| 231 |
- ansible.builtin.assert: |
| 232 |
that: |
| 233 |
- iam_role is not changed |
| 234 |
- iam_role.iam_role.role_name == test_role |
| 235 |
|
| 236 |
- name: Iam_role_info after Role creation |
| 237 |
amazon.aws.iam_role_info: |
| 238 |
name: "{{ test_role }}" |
| 239 |
register: role_info |
| 240 |
- ansible.builtin.assert: |
| 241 |
that: |
| 242 |
- role_info is succeeded |
| 243 |
- role_info.iam_roles | length == 1 |
| 244 |
- role_info.iam_roles[0].arn.startswith("arn") |
| 245 |
- role_info.iam_roles[0].arn.endswith("role" + test_path + test_role ) |
| 246 |
- '"assume_role_policy_document" in role_info.iam_roles[0]' |
| 247 |
- '"create_date" in role_info.iam_roles[0]' |
| 248 |
- '"description" not in role_info.iam_roles[0]' |
| 249 |
- role_info.iam_roles[0].inline_policies | length == 0 |
| 250 |
- role_info.iam_roles[0].instance_profiles | length == 1 |
| 251 |
- role_info.iam_roles[0].instance_profiles[0].instance_profile_name == test_role |
| 252 |
- role_info.iam_roles[0].instance_profiles[0].arn.startswith("arn") |
| 253 |
- role_info.iam_roles[0].instance_profiles[0].arn.endswith("instance-profile" + test_path + test_role) |
| 254 |
- role_info.iam_roles[0].managed_policies | length == 0 |
| 255 |
- role_info.iam_roles[0].max_session_duration == 3600 |
| 256 |
- role_info.iam_roles[0].path == test_path |
| 257 |
- '"permissions_boundary" not in role_info.iam_roles[0]' |
| 258 |
- role_info.iam_roles[0].role_id == iam_role.iam_role.role_id |
| 259 |
- role_info.iam_roles[0].role_name == test_role |
| 260 |
- role_info.iam_roles[0].tags | length == 0 |
| 261 |
|
| 262 |
- name: Iam_role_info after Role creation (searching a path) |
| 263 |
amazon.aws.iam_role_info: |
| 264 |
path_prefix: "{{ test_path }}" |
| 265 |
register: role_info |
| 266 |
- ansible.builtin.assert: |
| 267 |
that: |
| 268 |
- role_info is succeeded |
| 269 |
- role_info.iam_roles | length == 1 |
| 270 |
- role_info.iam_roles[0].arn.startswith("arn") |
| 271 |
- role_info.iam_roles[0].arn.endswith("role" + test_path + test_role ) |
| 272 |
- '"assume_role_policy_document" in role_info.iam_roles[0]' |
| 273 |
- '"create_date" in role_info.iam_roles[0]' |
| 274 |
- '"description" not in role_info.iam_roles[0]' |
| 275 |
- role_info.iam_roles[0].inline_policies | length == 0 |
| 276 |
- role_info.iam_roles[0].instance_profiles | length == 1 |
| 277 |
- role_info.iam_roles[0].instance_profiles[0].instance_profile_name == test_role |
| 278 |
- role_info.iam_roles[0].instance_profiles[0].arn.startswith("arn") |
| 279 |
- role_info.iam_roles[0].instance_profiles[0].arn.endswith("instance-profile" + test_path + test_role) |
| 280 |
- role_info.iam_roles[0].managed_policies | length == 0 |
| 281 |
- role_info.iam_roles[0].max_session_duration == 3600 |
| 282 |
- '"permissions_boundary" not in role_info.iam_roles[0]' |
| 283 |
- role_info.iam_roles[0].path == test_path |
| 284 |
- role_info.iam_roles[0].role_id == iam_role.iam_role.role_id |
| 285 |
- role_info.iam_roles[0].role_name == test_role |
| 286 |
- role_info.iam_roles[0].tags | length == 0 |
| 287 |
|
| 288 |
- name: Iam_role_info after Role creation (searching a path without / prefix and suffix) |
| 289 |
amazon.aws.iam_role_info: |
| 290 |
path_prefix: "{{ bad_test_path }}" |
| 291 |
register: role_info |
| 292 |
- ansible.builtin.assert: |
| 293 |
that: |
| 294 |
- role_info is succeeded |
| 295 |
- role_info.iam_roles | length == 1 |
| 296 |
- role_info.iam_roles[0].arn.startswith("arn") |
| 297 |
- role_info.iam_roles[0].arn.endswith("role" + test_path + test_role ) |
| 298 |
- '"assume_role_policy_document" in role_info.iam_roles[0]' |
| 299 |
- '"create_date" in role_info.iam_roles[0]' |
| 300 |
- '"description" not in role_info.iam_roles[0]' |
| 301 |
- role_info.iam_roles[0].inline_policies | length == 0 |
| 302 |
- role_info.iam_roles[0].instance_profiles | length == 1 |
| 303 |
- role_info.iam_roles[0].instance_profiles[0].instance_profile_name == test_role |
| 304 |
- role_info.iam_roles[0].instance_profiles[0].arn.startswith("arn") |
| 305 |
- role_info.iam_roles[0].instance_profiles[0].arn.endswith("instance-profile" + test_path + test_role) |
| 306 |
- role_info.iam_roles[0].managed_policies | length == 0 |
| 307 |
- role_info.iam_roles[0].max_session_duration == 3600 |
| 308 |
- '"permissions_boundary" not in role_info.iam_roles[0]' |
| 309 |
- role_info.iam_roles[0].path == test_path |
| 310 |
- role_info.iam_roles[0].role_id == iam_role.iam_role.role_id |
| 311 |
- role_info.iam_roles[0].role_name == test_role |
| 312 |
- role_info.iam_roles[0].tags | length == 0 |
| 313 |
|
| 314 |
- name: Remove IAM Role |
| 315 |
amazon.aws.iam_role: |
| 316 |
state: absent |
| 317 |
name: "{{ test_role }}" |
| 318 |
path: "{{ test_path }}" |
| 319 |
delete_instance_profile: true |
| 320 |
register: iam_role |
| 321 |
- ansible.builtin.assert: |
| 322 |
that: |
| 323 |
- iam_role is changed |
| 324 |
|
| 325 |
- name: Iam_role_info after Role deletion |
| 326 |
amazon.aws.iam_role_info: |
| 327 |
name: "{{ test_role }}" |
| 328 |
register: role_info |
| 329 |
- ansible.builtin.assert: |
| 330 |
that: |
| 331 |
- role_info is succeeded |
| 332 |
- role_info.iam_roles | length == 0 |
| 333 |
|
| 334 |
# ------------------------------------------------------------------------------------------ |
| 335 |
|
| 336 |
# (with Instance profile) |
| 337 |
- name: Minimal IAM Role with instance profile - check mode |
| 338 |
amazon.aws.iam_role: |
| 339 |
name: "{{ test_role }}" |
| 340 |
create_instance_profile: true |
| 341 |
register: iam_role |
| 342 |
check_mode: true |
| 343 |
- ansible.builtin.assert: |
| 344 |
that: |
| 345 |
- iam_role is changed |
| 346 |
|
| 347 |
- name: Minimal IAM Role with instance profile |
| 348 |
amazon.aws.iam_role: |
| 349 |
name: "{{ test_role }}" |
| 350 |
create_instance_profile: true |
| 351 |
register: iam_role |
| 352 |
- ansible.builtin.assert: |
| 353 |
that: |
| 354 |
- iam_role is changed |
| 355 |
- iam_role.iam_role.role_name == test_role |
| 356 |
- iam_role.iam_role.arn.startswith("arn") |
| 357 |
- iam_role.iam_role.arn.endswith("role/" + test_role ) |
| 358 |
# Would be nice to test the contents... |
| 359 |
- '"assume_role_policy_document" in iam_role.iam_role' |
| 360 |
- iam_role.iam_role.attached_policies | length == 0 |
| 361 |
- iam_role.iam_role.max_session_duration == 3600 |
| 362 |
- iam_role.iam_role.path == '/' |
| 363 |
- iam_role.iam_role.role_name == test_role |
| 364 |
- '"create_date" in iam_role.iam_role' |
| 365 |
- '"role_id" in iam_role.iam_role' |
| 366 |
|
| 367 |
- name: Minimal IAM Role wth instance profile (no change) - check mode |
| 368 |
amazon.aws.iam_role: |
| 369 |
name: "{{ test_role }}" |
| 370 |
create_instance_profile: true |
| 371 |
register: iam_role |
| 372 |
check_mode: true |
| 373 |
- ansible.builtin.assert: |
| 374 |
that: |
| 375 |
- iam_role is not changed |
| 376 |
|
| 377 |
- name: Minimal IAM Role wth instance profile (no change) |
| 378 |
amazon.aws.iam_role: |
| 379 |
name: "{{ test_role }}" |
| 380 |
create_instance_profile: true |
| 381 |
register: iam_role |
| 382 |
- ansible.builtin.assert: |
| 383 |
that: |
| 384 |
- iam_role is not changed |
| 385 |
- iam_role.iam_role.role_name == test_role |
| 386 |
|
| 387 |
- name: Iam_role_info after Role creation |
| 388 |
amazon.aws.iam_role_info: |
| 389 |
name: "{{ test_role }}" |
| 390 |
register: role_info |
| 391 |
- ansible.builtin.assert: |
| 392 |
that: |
| 393 |
- role_info is succeeded |
| 394 |
- role_info.iam_roles | length == 1 |
| 395 |
- role_info.iam_roles[0].arn.startswith("arn") |
| 396 |
- role_info.iam_roles[0].arn.endswith("role/" + test_role ) |
| 397 |
- '"assume_role_policy_document" in role_info.iam_roles[0]' |
| 398 |
- '"create_date" in role_info.iam_roles[0]' |
| 399 |
- '"description" not in role_info.iam_roles[0]' |
| 400 |
- role_info.iam_roles[0].inline_policies | length == 0 |
| 401 |
- role_info.iam_roles[0].instance_profiles | length == 1 |
| 402 |
- role_info.iam_roles[0].instance_profiles[0].instance_profile_name == test_role |
| 403 |
- role_info.iam_roles[0].instance_profiles[0].arn.startswith("arn") |
| 404 |
- role_info.iam_roles[0].instance_profiles[0].arn.endswith("instance-profile/" + test_role) |
| 405 |
- role_info.iam_roles[0].managed_policies | length == 0 |
| 406 |
- role_info.iam_roles[0].max_session_duration == 3600 |
| 407 |
- role_info.iam_roles[0].path == '/' |
| 408 |
- '"permissions_boundary" not in role_info.iam_roles[0]' |
| 409 |
- role_info.iam_roles[0].role_id == iam_role.iam_role.role_id |
| 410 |
- role_info.iam_roles[0].role_name == test_role |
| 411 |
- role_info.iam_roles[0].tags | length == 0 |