| 1 |
--- |
| 2 |
- name: Set connection information for AWS modules and run tests |
| 3 |
module_defaults: |
| 4 |
group/aws: |
| 5 |
access_key: "{{ aws_access_key }}" |
| 6 |
secret_key: "{{ aws_secret_key }}" |
| 7 |
session_token: "{{ security_token | default(omit) }}" |
| 8 |
region: "{{ aws_region }}" |
| 9 |
block: |
| 10 |
# ============================================================== |
| 11 |
# Preparation |
| 12 |
- name: Create minimal lambda role |
| 13 |
amazon.aws.iam_role: |
| 14 |
name: "{{ lambda_role_name }}" |
| 15 |
assume_role_policy_document: '{{ lookup("file", "minimal_trust_policy.json") }}' |
| 16 |
create_instance_profile: false |
| 17 |
managed_policies: |
| 18 |
- arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess |
| 19 |
register: iam_role |
| 20 |
- name: Wait 10 seconds for role to become available |
| 21 |
ansible.builtin.pause: |
| 22 |
seconds: 10 |
| 23 |
- name: Move lambda into place for archive module |
| 24 |
ansible.builtin.copy: |
| 25 |
src: mini_lambda.py |
| 26 |
dest: "{{ output_dir }}/mini_lambda.py" |
| 27 |
mode: preserve |
| 28 |
- name: Bundle lambda into a zip |
| 29 |
register: zip_res |
| 30 |
community.general.archive: |
| 31 |
format: zip |
| 32 |
path: "{{ output_dir }}/mini_lambda.py" |
| 33 |
dest: "{{ output_dir }}/mini_lambda.zip" |
| 34 |
mode: "0644" |
| 35 |
|
| 36 |
- name: Upload test lambda (version 1) |
| 37 |
amazon.aws.lambda: |
| 38 |
name: "{{ lambda_function_name }}" |
| 39 |
runtime: python3.12 |
| 40 |
handler: mini_lambda.handler |
| 41 |
role: "{{ lambda_role_name }}" |
| 42 |
zip_file: "{{ zip_res.dest }}" |
| 43 |
register: lambda_a |
| 44 |
- name: Assert lambda upload succeeded |
| 45 |
ansible.builtin.assert: |
| 46 |
that: |
| 47 |
- lambda_a is changed |
| 48 |
|
| 49 |
- name: Update lambda (version 2) |
| 50 |
amazon.aws.lambda: |
| 51 |
name: "{{ lambda_function_name }}" |
| 52 |
runtime: python3.8 |
| 53 |
handler: mini_lambda.handler |
| 54 |
role: "{{ lambda_role_name }}" |
| 55 |
register: lambda_b |
| 56 |
- name: Assert that update succeeded |
| 57 |
ansible.builtin.assert: |
| 58 |
that: |
| 59 |
- lambda_b is changed |
| 60 |
|
| 61 |
- name: Update lambda (version 3 / LATEST) |
| 62 |
amazon.aws.lambda: |
| 63 |
name: "{{ lambda_function_name }}" |
| 64 |
runtime: python3.9 |
| 65 |
handler: mini_lambda.handler |
| 66 |
role: "{{ lambda_role_name }}" |
| 67 |
register: lambda_c |
| 68 |
- name: Assert that update succeeded |
| 69 |
ansible.builtin.assert: |
| 70 |
that: |
| 71 |
- lambda_c is changed |
| 72 |
|
| 73 |
- name: Store Lambda info |
| 74 |
vars: |
| 75 |
_full_arn: "{{ lambda_a.configuration.function_arn }}" |
| 76 |
ansible.builtin.set_fact: |
| 77 |
lambda_arn: '{{ ":".join(_full_arn.split(":")[:-1]) }}' |
| 78 |
|
| 79 |
# ============================================================== |
| 80 |
# Creation of an alias |
| 81 |
- name: Create an alias (check mode) |
| 82 |
amazon.aws.lambda_alias: |
| 83 |
state: present |
| 84 |
function_name: "{{ lambda_function_name }}" |
| 85 |
name: Testing |
| 86 |
check_mode: true |
| 87 |
register: create_alias |
| 88 |
- name: Check changed |
| 89 |
ansible.builtin.assert: |
| 90 |
that: |
| 91 |
- create_alias is changed |
| 92 |
|
| 93 |
- name: Create an alias |
| 94 |
amazon.aws.lambda_alias: |
| 95 |
state: present |
| 96 |
function_name: "{{ lambda_function_name }}" |
| 97 |
name: Testing |
| 98 |
register: create_alias |
| 99 |
- name: Check changed and returned values |
| 100 |
ansible.builtin.assert: |
| 101 |
that: |
| 102 |
- create_alias is changed |
| 103 |
- '"alias_arn" in create_alias' |
| 104 |
- create_alias.alias_arn.startswith(lambda_arn) |
| 105 |
- create_alias.alias_arn.endswith("Testing") |
| 106 |
- '"description" in create_alias' |
| 107 |
- create_alias.description == "" |
| 108 |
- '"function_version" in create_alias' |
| 109 |
- create_alias.function_version == "$LATEST" |
| 110 |
- '"name" in create_alias' |
| 111 |
- create_alias.name == "Testing" |
| 112 |
- '"revision_id" in create_alias' |
| 113 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 114 |
# It will change any time the alias is updated |
| 115 |
|
| 116 |
- name: Create an alias - idempotency (check mode) |
| 117 |
amazon.aws.lambda_alias: |
| 118 |
state: present |
| 119 |
function_name: "{{ lambda_function_name }}" |
| 120 |
name: Testing |
| 121 |
check_mode: true |
| 122 |
register: create_alias |
| 123 |
- name: Check not changed |
| 124 |
ansible.builtin.assert: |
| 125 |
that: |
| 126 |
- create_alias is not changed |
| 127 |
|
| 128 |
- name: Create an alias - idempotecy |
| 129 |
amazon.aws.lambda_alias: |
| 130 |
state: present |
| 131 |
function_name: "{{ lambda_function_name }}" |
| 132 |
name: Testing |
| 133 |
register: create_alias |
| 134 |
- name: Check not changed |
| 135 |
ansible.builtin.assert: |
| 136 |
that: |
| 137 |
- create_alias is not changed |
| 138 |
- '"alias_arn" in create_alias' |
| 139 |
- create_alias.alias_arn.startswith(lambda_arn) |
| 140 |
- create_alias.alias_arn.endswith("Testing") |
| 141 |
- '"description" in create_alias' |
| 142 |
- create_alias.description == "" |
| 143 |
- '"function_version" in create_alias' |
| 144 |
- create_alias.function_version == "$LATEST" |
| 145 |
- '"name" in create_alias' |
| 146 |
- create_alias.name == "Testing" |
| 147 |
- '"revision_id" in create_alias' |
| 148 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 149 |
# It will change any time the alias is updated |
| 150 |
|
| 151 |
# ============================================================== |
| 152 |
# Update description of an alias when none set to start |
| 153 |
- name: Update an alias description (check mode) |
| 154 |
amazon.aws.lambda_alias: |
| 155 |
state: present |
| 156 |
function_name: "{{ lambda_function_name }}" |
| 157 |
name: Testing |
| 158 |
description: Description 1 |
| 159 |
check_mode: true |
| 160 |
register: update_alias_description |
| 161 |
- name: Check changed |
| 162 |
ansible.builtin.assert: |
| 163 |
that: |
| 164 |
- update_alias_description is changed |
| 165 |
|
| 166 |
- name: Update an alias description |
| 167 |
amazon.aws.lambda_alias: |
| 168 |
state: present |
| 169 |
function_name: "{{ lambda_function_name }}" |
| 170 |
name: Testing |
| 171 |
description: Description 1 |
| 172 |
register: update_alias_description |
| 173 |
- name: Check changed and returned values |
| 174 |
ansible.builtin.assert: |
| 175 |
that: |
| 176 |
- update_alias_description is changed |
| 177 |
- '"alias_arn" in update_alias_description' |
| 178 |
- update_alias_description.alias_arn.startswith(lambda_arn) |
| 179 |
- update_alias_description.alias_arn.endswith("Testing") |
| 180 |
- '"description" in update_alias_description' |
| 181 |
- update_alias_description.description == "Description 1" |
| 182 |
- '"function_version" in update_alias_description' |
| 183 |
- update_alias_description.function_version == "$LATEST" |
| 184 |
- '"name" in update_alias_description' |
| 185 |
- update_alias_description.name == "Testing" |
| 186 |
- '"revision_id" in update_alias_description' |
| 187 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 188 |
# It will change any time the alias is updated |
| 189 |
|
| 190 |
- name: Update an alias description - idempotency (check mode) |
| 191 |
amazon.aws.lambda_alias: |
| 192 |
state: present |
| 193 |
function_name: "{{ lambda_function_name }}" |
| 194 |
name: Testing |
| 195 |
description: Description 1 |
| 196 |
check_mode: true |
| 197 |
register: update_alias_description |
| 198 |
- name: Check not changed |
| 199 |
ansible.builtin.assert: |
| 200 |
that: |
| 201 |
- update_alias_description is not changed |
| 202 |
|
| 203 |
- name: Update an alias description - idempotecy |
| 204 |
amazon.aws.lambda_alias: |
| 205 |
state: present |
| 206 |
function_name: "{{ lambda_function_name }}" |
| 207 |
name: Testing |
| 208 |
description: Description 1 |
| 209 |
register: update_alias_description |
| 210 |
- name: Check not changed |
| 211 |
ansible.builtin.assert: |
| 212 |
that: |
| 213 |
- update_alias_description is not changed |
| 214 |
- '"alias_arn" in update_alias_description' |
| 215 |
- update_alias_description.alias_arn.startswith(lambda_arn) |
| 216 |
- update_alias_description.alias_arn.endswith("Testing") |
| 217 |
- '"description" in update_alias_description' |
| 218 |
- update_alias_description.description == "Description 1" |
| 219 |
- '"function_version" in update_alias_description' |
| 220 |
- update_alias_description.function_version == "$LATEST" |
| 221 |
- '"name" in update_alias_description' |
| 222 |
- update_alias_description.name == "Testing" |
| 223 |
- '"revision_id" in update_alias_description' |
| 224 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 225 |
# It will change any time the alias is updated |
| 226 |
|
| 227 |
# ============================================================== |
| 228 |
# Update description of an alias when one set to start |
| 229 |
- name: Update an alias description again (check mode) |
| 230 |
amazon.aws.lambda_alias: |
| 231 |
state: present |
| 232 |
function_name: "{{ lambda_function_name }}" |
| 233 |
name: Testing |
| 234 |
description: description 2 |
| 235 |
check_mode: true |
| 236 |
register: update_alias_description |
| 237 |
- name: Check changed |
| 238 |
ansible.builtin.assert: |
| 239 |
that: |
| 240 |
- update_alias_description is changed |
| 241 |
|
| 242 |
- name: Update an alias description again |
| 243 |
amazon.aws.lambda_alias: |
| 244 |
state: present |
| 245 |
function_name: "{{ lambda_function_name }}" |
| 246 |
name: Testing |
| 247 |
description: description 2 |
| 248 |
register: update_alias_description |
| 249 |
- name: Check changed and returned values |
| 250 |
ansible.builtin.assert: |
| 251 |
that: |
| 252 |
- update_alias_description is changed |
| 253 |
- '"alias_arn" in update_alias_description' |
| 254 |
- update_alias_description.alias_arn.startswith(lambda_arn) |
| 255 |
- update_alias_description.alias_arn.endswith("Testing") |
| 256 |
- '"description" in update_alias_description' |
| 257 |
- update_alias_description.description == "description 2" |
| 258 |
- '"function_version" in update_alias_description' |
| 259 |
- update_alias_description.function_version == "$LATEST" |
| 260 |
- '"name" in update_alias_description' |
| 261 |
- update_alias_description.name == "Testing" |
| 262 |
- '"revision_id" in update_alias_description' |
| 263 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 264 |
# It will change any time the alias is updated |
| 265 |
|
| 266 |
# ============================================================== |
| 267 |
# Update version of an alias |
| 268 |
- name: Update an alias version (check mode) |
| 269 |
amazon.aws.lambda_alias: |
| 270 |
state: present |
| 271 |
function_name: "{{ lambda_function_name }}" |
| 272 |
name: Testing |
| 273 |
function_version: 1 |
| 274 |
check_mode: true |
| 275 |
register: update_alias_version |
| 276 |
- name: Check changed |
| 277 |
ansible.builtin.assert: |
| 278 |
that: |
| 279 |
- update_alias_version is changed |
| 280 |
|
| 281 |
- name: Update an alias version |
| 282 |
amazon.aws.lambda_alias: |
| 283 |
state: present |
| 284 |
function_name: "{{ lambda_function_name }}" |
| 285 |
name: Testing |
| 286 |
function_version: 1 |
| 287 |
register: update_alias_version |
| 288 |
- name: Check changed and returned values |
| 289 |
ansible.builtin.assert: |
| 290 |
that: |
| 291 |
- update_alias_version is changed |
| 292 |
- '"alias_arn" in update_alias_version' |
| 293 |
- update_alias_version.alias_arn.startswith(lambda_arn) |
| 294 |
- update_alias_version.alias_arn.endswith("Testing") |
| 295 |
- '"description" in update_alias_version' |
| 296 |
- update_alias_version.description == "description 2" |
| 297 |
- '"function_version" in update_alias_version' |
| 298 |
- update_alias_version.function_version == "1" |
| 299 |
- '"name" in update_alias_version' |
| 300 |
- update_alias_version.name == "Testing" |
| 301 |
- '"revision_id" in update_alias_version' |
| 302 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 303 |
# It will change any time the alias is updated |
| 304 |
|
| 305 |
- name: Update an alias version - idempotency (check mode) |
| 306 |
amazon.aws.lambda_alias: |
| 307 |
state: present |
| 308 |
function_name: "{{ lambda_function_name }}" |
| 309 |
name: Testing |
| 310 |
function_version: 1 |
| 311 |
check_mode: true |
| 312 |
register: update_alias_version |
| 313 |
- name: Check not changed |
| 314 |
ansible.builtin.assert: |
| 315 |
that: |
| 316 |
- update_alias_version is not changed |
| 317 |
|
| 318 |
- name: Update an alias version - idempotecy |
| 319 |
amazon.aws.lambda_alias: |
| 320 |
state: present |
| 321 |
function_name: "{{ lambda_function_name }}" |
| 322 |
name: Testing |
| 323 |
function_version: 1 |
| 324 |
register: update_alias_version |
| 325 |
- name: Check not changed |
| 326 |
ansible.builtin.assert: |
| 327 |
that: |
| 328 |
- update_alias_version is not changed |
| 329 |
- '"alias_arn" in update_alias_version' |
| 330 |
- update_alias_version.alias_arn.startswith(lambda_arn) |
| 331 |
- update_alias_version.alias_arn.endswith("Testing") |
| 332 |
- '"description" in update_alias_version' |
| 333 |
- update_alias_version.description == "description 2" |
| 334 |
- '"function_version" in update_alias_version' |
| 335 |
- update_alias_version.function_version == "1" |
| 336 |
- '"name" in update_alias_version' |
| 337 |
- update_alias_version.name == "Testing" |
| 338 |
- '"revision_id" in update_alias_version' |
| 339 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 340 |
# It will change any time the alias is updated |
| 341 |
|
| 342 |
- name: Update an alias version to implied LATEST (check mode) |
| 343 |
amazon.aws.lambda_alias: |
| 344 |
state: present |
| 345 |
function_name: "{{ lambda_function_name }}" |
| 346 |
name: Testing |
| 347 |
# # docs state that when not defined defaults to LATEST |
| 348 |
# function_version: 1 |
| 349 |
check_mode: true |
| 350 |
register: update_alias_version |
| 351 |
- name: Check changed |
| 352 |
ansible.builtin.assert: |
| 353 |
that: |
| 354 |
- update_alias_version is changed |
| 355 |
|
| 356 |
- name: Update an alias version to implied LATEST |
| 357 |
amazon.aws.lambda_alias: |
| 358 |
state: present |
| 359 |
function_name: "{{ lambda_function_name }}" |
| 360 |
name: Testing |
| 361 |
# # docs state that when not defined defaults to LATEST |
| 362 |
# function_version: 1 |
| 363 |
register: update_alias_version |
| 364 |
- name: Check changed and returned values |
| 365 |
ansible.builtin.assert: |
| 366 |
that: |
| 367 |
- update_alias_version is changed |
| 368 |
- '"alias_arn" in update_alias_version' |
| 369 |
- update_alias_version.alias_arn.startswith(lambda_arn) |
| 370 |
- update_alias_version.alias_arn.endswith("Testing") |
| 371 |
- '"description" in update_alias_version' |
| 372 |
- update_alias_version.description == "description 2" |
| 373 |
- '"function_version" in update_alias_version' |
| 374 |
- update_alias_version.function_version == "$LATEST" |
| 375 |
- '"name" in update_alias_version' |
| 376 |
- update_alias_version.name == "Testing" |
| 377 |
- '"revision_id" in update_alias_version' |
| 378 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 379 |
# It will change any time the alias is updated |
| 380 |
|
| 381 |
# Make sure that 0 also causes a change |
| 382 |
- name: Update an alias version |
| 383 |
amazon.aws.lambda_alias: |
| 384 |
state: present |
| 385 |
function_name: "{{ lambda_function_name }}" |
| 386 |
name: Testing |
| 387 |
function_version: 1 |
| 388 |
register: update_alias_version |
| 389 |
- name: Check not changed |
| 390 |
ansible.builtin.assert: |
| 391 |
that: |
| 392 |
- update_alias_version is changed |
| 393 |
- '"alias_arn" in update_alias_version' |
| 394 |
- update_alias_version.alias_arn.startswith(lambda_arn) |
| 395 |
- update_alias_version.alias_arn.endswith("Testing") |
| 396 |
- '"description" in update_alias_version' |
| 397 |
- update_alias_version.description == "description 2" |
| 398 |
- '"function_version" in update_alias_version' |
| 399 |
- update_alias_version.function_version == "1" |
| 400 |
- '"name" in update_alias_version' |
| 401 |
- update_alias_version.name == "Testing" |
| 402 |
- '"revision_id" in update_alias_version' |
| 403 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 404 |
# It will change any time the alias is updated |
| 405 |
|
| 406 |
- name: Update an alias version to explicit LATEST with 0 (check mode) |
| 407 |
amazon.aws.lambda_alias: |
| 408 |
state: present |
| 409 |
function_name: "{{ lambda_function_name }}" |
| 410 |
name: Testing |
| 411 |
function_version: 0 |
| 412 |
check_mode: true |
| 413 |
register: update_alias_version |
| 414 |
- name: Check changed |
| 415 |
ansible.builtin.assert: |
| 416 |
that: |
| 417 |
- update_alias_version is changed |
| 418 |
|
| 419 |
- name: Update an alias version to explicit LATEST with 0 |
| 420 |
amazon.aws.lambda_alias: |
| 421 |
state: present |
| 422 |
function_name: "{{ lambda_function_name }}" |
| 423 |
name: Testing |
| 424 |
function_version: 0 |
| 425 |
register: update_alias_version |
| 426 |
- name: Check changed and returned values |
| 427 |
ansible.builtin.assert: |
| 428 |
that: |
| 429 |
- update_alias_version is changed |
| 430 |
- '"alias_arn" in update_alias_version' |
| 431 |
- update_alias_version.alias_arn.startswith(lambda_arn) |
| 432 |
- update_alias_version.alias_arn.endswith("Testing") |
| 433 |
- '"description" in update_alias_version' |
| 434 |
- update_alias_version.description == "description 2" |
| 435 |
- '"function_version" in update_alias_version' |
| 436 |
- update_alias_version.function_version == "$LATEST" |
| 437 |
- '"name" in update_alias_version' |
| 438 |
- update_alias_version.name == "Testing" |
| 439 |
- '"revision_id" in update_alias_version' |
| 440 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 441 |
# It will change any time the alias is updated |
| 442 |
|
| 443 |
- name: Update an alias version to explicit LATEST with 0 - idempotency (check mode) |
| 444 |
amazon.aws.lambda_alias: |
| 445 |
state: present |
| 446 |
function_name: "{{ lambda_function_name }}" |
| 447 |
name: Testing |
| 448 |
function_version: 0 |
| 449 |
check_mode: true |
| 450 |
register: update_alias_version |
| 451 |
- name: Check changed |
| 452 |
ansible.builtin.assert: |
| 453 |
that: |
| 454 |
- update_alias_version is not changed |
| 455 |
|
| 456 |
- name: Update an alias version to explicit LATEST with 0 - idempotecy |
| 457 |
amazon.aws.lambda_alias: |
| 458 |
state: present |
| 459 |
function_name: "{{ lambda_function_name }}" |
| 460 |
name: Testing |
| 461 |
function_version: 0 |
| 462 |
register: update_alias_version |
| 463 |
- name: Check changed and returned values |
| 464 |
ansible.builtin.assert: |
| 465 |
that: |
| 466 |
- update_alias_version is not changed |
| 467 |
- '"alias_arn" in update_alias_version' |
| 468 |
- update_alias_version.alias_arn.startswith(lambda_arn) |
| 469 |
- update_alias_version.alias_arn.endswith("Testing") |
| 470 |
- '"description" in update_alias_version' |
| 471 |
- update_alias_version.description == "description 2" |
| 472 |
- '"function_version" in update_alias_version' |
| 473 |
- update_alias_version.function_version == "$LATEST" |
| 474 |
- '"name" in update_alias_version' |
| 475 |
- update_alias_version.name == "Testing" |
| 476 |
- '"revision_id" in update_alias_version' |
| 477 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 478 |
# It will change any time the alias is updated |
| 479 |
|
| 480 |
# ============================================================== |
| 481 |
# Creation of an alias with all options |
| 482 |
- name: Create an alias with all options (check mode) |
| 483 |
amazon.aws.lambda_alias: |
| 484 |
state: present |
| 485 |
function_name: "{{ lambda_function_name }}" |
| 486 |
description: Hello world |
| 487 |
name: stable |
| 488 |
function_version: 1 |
| 489 |
check_mode: true |
| 490 |
register: create_alias |
| 491 |
- name: Check changed |
| 492 |
ansible.builtin.assert: |
| 493 |
that: |
| 494 |
- create_alias is changed |
| 495 |
|
| 496 |
- name: Create an alias with all options |
| 497 |
amazon.aws.lambda_alias: |
| 498 |
state: present |
| 499 |
function_name: "{{ lambda_function_name }}" |
| 500 |
description: Hello world |
| 501 |
name: stable |
| 502 |
function_version: 1 |
| 503 |
register: create_alias |
| 504 |
- name: Check changed and returned values |
| 505 |
ansible.builtin.assert: |
| 506 |
that: |
| 507 |
- create_alias is changed |
| 508 |
- '"alias_arn" in create_alias' |
| 509 |
- create_alias.alias_arn.startswith(lambda_arn) |
| 510 |
- create_alias.alias_arn.endswith("stable") |
| 511 |
- '"description" in create_alias' |
| 512 |
- create_alias.description == "Hello world" |
| 513 |
- '"function_version" in create_alias' |
| 514 |
- create_alias.function_version == "1" |
| 515 |
- '"name" in create_alias' |
| 516 |
- create_alias.name == "stable" |
| 517 |
- '"revision_id" in create_alias' |
| 518 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 519 |
# It will change any time the alias is updated |
| 520 |
|
| 521 |
- name: Create an alias with all options - idempotency (check mode) |
| 522 |
amazon.aws.lambda_alias: |
| 523 |
state: present |
| 524 |
function_name: "{{ lambda_function_name }}" |
| 525 |
description: Hello world |
| 526 |
name: stable |
| 527 |
function_version: 1 |
| 528 |
check_mode: true |
| 529 |
register: create_alias |
| 530 |
- name: Check not changed |
| 531 |
ansible.builtin.assert: |
| 532 |
that: |
| 533 |
- create_alias is not changed |
| 534 |
|
| 535 |
- name: Create an alias wth all options - idempotecy |
| 536 |
amazon.aws.lambda_alias: |
| 537 |
state: present |
| 538 |
function_name: "{{ lambda_function_name }}" |
| 539 |
description: Hello world |
| 540 |
name: stable |
| 541 |
function_version: 1 |
| 542 |
register: create_alias |
| 543 |
- name: Check not changed |
| 544 |
ansible.builtin.assert: |
| 545 |
that: |
| 546 |
- create_alias is not changed |
| 547 |
- '"alias_arn" in create_alias' |
| 548 |
- create_alias.alias_arn.startswith(lambda_arn) |
| 549 |
- create_alias.alias_arn.endswith("stable") |
| 550 |
- '"description" in create_alias' |
| 551 |
- create_alias.description == "Hello world" |
| 552 |
- '"function_version" in create_alias' |
| 553 |
- create_alias.function_version == "1" |
| 554 |
- '"name" in create_alias' |
| 555 |
- create_alias.name == "stable" |
| 556 |
- '"revision_id" in create_alias' |
| 557 |
# The revision_id doesn't line up with the revision IDs of the versions |
| 558 |
# It will change any time the alias is updated |
| 559 |
|
| 560 |
# ============================================================== |
| 561 |
# Deletion of an alias |
| 562 |
- name: Delete an alias (check mode) |
| 563 |
amazon.aws.lambda_alias: |
| 564 |
state: absent |
| 565 |
function_name: "{{ lambda_function_name }}" |
| 566 |
name: Testing |
| 567 |
check_mode: true |
| 568 |
register: delete_alias |
| 569 |
- name: Check changed |
| 570 |
ansible.builtin.assert: |
| 571 |
that: |
| 572 |
- delete_alias is changed |
| 573 |
|
| 574 |
- name: Delete an alias |
| 575 |
amazon.aws.lambda_alias: |
| 576 |
state: absent |
| 577 |
function_name: "{{ lambda_function_name }}" |
| 578 |
name: Testing |
| 579 |
register: delete_alias |
| 580 |
- name: Check changed |
| 581 |
ansible.builtin.assert: |
| 582 |
that: |
| 583 |
- delete_alias is changed |
| 584 |
|
| 585 |
- name: Delete an alias - idempotency (check mode) |
| 586 |
amazon.aws.lambda_alias: |
| 587 |
state: absent |
| 588 |
function_name: "{{ lambda_function_name }}" |
| 589 |
name: Testing |
| 590 |
check_mode: true |
| 591 |
register: delete_alias |
| 592 |
- name: Check not changed |
| 593 |
ansible.builtin.assert: |
| 594 |
that: |
| 595 |
- delete_alias is not changed |
| 596 |
|
| 597 |
- name: Delete an alias - idempotecy |
| 598 |
amazon.aws.lambda_alias: |
| 599 |
state: absent |
| 600 |
function_name: "{{ lambda_function_name }}" |
| 601 |
name: Testing |
| 602 |
register: delete_alias |
| 603 |
- name: Check not changed |
| 604 |
ansible.builtin.assert: |
| 605 |
that: |
| 606 |
- delete_alias is not changed |
| 607 |
|
| 608 |
# ============================================================== |
| 609 |
# Cleanup |
| 610 |
always: |
| 611 |
- name: Ensure function is absent at end of test |
| 612 |
amazon.aws.lambda: |
| 613 |
name: "{{ lambda_function_name }}" |
| 614 |
state: absent |
| 615 |
ignore_errors: true |
| 616 |
- name: Ensure role has been removed at end of test |
| 617 |
amazon.aws.iam_role: |
| 618 |
name: "{{ lambda_role_name }}" |
| 619 |
state: absent |
| 620 |
delete_instance_profile: true |
| 621 |
ignore_errors: true |