| 1 |
--- |
| 2 |
# General Tests: |
| 3 |
# - s3_bucket_name required when state is 'present' |
| 4 |
# - Creation / Deletion |
| 5 |
# - Enable/Disable logging |
| 6 |
# - Enable/Disable log file validation option |
| 7 |
# - Manipulation of Global Event logging option |
| 8 |
# - Manipulation of Multi-Region logging option |
| 9 |
# - Manipulation of S3 bucket option |
| 10 |
# - Manipulation of Encryption option |
| 11 |
# - Manipulation of SNS options |
| 12 |
# - Manipulation of CloudWatch Log group options |
| 13 |
# - Manipulation of Tags |
| 14 |
# |
| 15 |
# Notes: |
| 16 |
# - results include the updates, even when check_mode is true |
| 17 |
# - Poor handling of disable global + enable multi-region |
| 18 |
# botocore.errorfactory.InvalidParameterCombinationException: An error |
| 19 |
# occurred (InvalidParameterCombinationException) when calling the |
| 20 |
# UpdateTrail operation: Multi-Region trail must include global service |
| 21 |
# events. |
| 22 |
# - Using blank string for KMS ID doesn't remove encryption |
| 23 |
# - Using blank string for SNS Topic doesn't remove it |
| 24 |
# - Using blank string for CloudWatch Log Group / Role doesn't remove them |
| 25 |
# |
| 26 |
# Possible Bugs: |
| 27 |
|
| 28 |
- module_defaults: |
| 29 |
# Add this as a default because we (almost) always need it |
| 30 |
amazon.aws.cloudtrail: |
| 31 |
s3_bucket_name: "{{ s3_bucket_name }}" |
| 32 |
region: "{{ aws_region }}" |
| 33 |
block: |
| 34 |
# ============================================================ |
| 35 |
# Argument Tests |
| 36 |
# ============================================================ |
| 37 |
- name: S3 Bucket required when state is "present" |
| 38 |
module_defaults: { amazon.aws.cloudtrail: {}} |
| 39 |
amazon.aws.cloudtrail: |
| 40 |
state: present |
| 41 |
name: "{{ cloudtrail_name }}" |
| 42 |
register: output |
| 43 |
ignore_errors: true |
| 44 |
- ansible.builtin.assert: |
| 45 |
that: |
| 46 |
- output is failed |
| 47 |
|
| 48 |
- name: CloudWatch cloudwatch_logs_log_group_arn required when cloudwatch_logs_role_arn passed |
| 49 |
amazon.aws.cloudtrail: |
| 50 |
state: present |
| 51 |
name: "{{ cloudtrail_name }}" |
| 52 |
cloudwatch_logs_role_arn: SomeValue |
| 53 |
register: output |
| 54 |
ignore_errors: true |
| 55 |
- ansible.builtin.assert: |
| 56 |
that: |
| 57 |
- output is failed |
| 58 |
- '"parameters are required together" in output.msg' |
| 59 |
- '"cloudwatch_logs_log_group_arn" in output.msg' |
| 60 |
|
| 61 |
- name: CloudWatch cloudwatch_logs_role_arn required when cloudwatch_logs_log_group_arn passed |
| 62 |
amazon.aws.cloudtrail: |
| 63 |
state: present |
| 64 |
name: "{{ cloudtrail_name }}" |
| 65 |
cloudwatch_logs_log_group_arn: SomeValue |
| 66 |
register: output |
| 67 |
ignore_errors: true |
| 68 |
- ansible.builtin.assert: |
| 69 |
that: |
| 70 |
- output is failed |
| 71 |
- '"parameters are required together" in output.msg' |
| 72 |
- '"cloudwatch_logs_role_arn" in output.msg' |
| 73 |
|
| 74 |
# - name: 'Global Logging must be enabled when enabling Multi-region' |
| 75 |
# amazon.aws.cloudtrail: |
| 76 |
# state: present |
| 77 |
# name: '{{ cloudtrail_name }}' |
| 78 |
# include_global_events: no |
| 79 |
# is_multi_region_trail: yes |
| 80 |
# register: output |
| 81 |
# ignore_errors: yes |
| 82 |
# - assert: |
| 83 |
# that: |
| 84 |
# - output is failed |
| 85 |
|
| 86 |
# ============================================================ |
| 87 |
# Preparation |
| 88 |
# ============================================================ |
| 89 |
- name: Retrieve caller facts |
| 90 |
amazon.aws.aws_caller_info: {} |
| 91 |
register: aws_caller_info |
| 92 |
|
| 93 |
- name: Create S3 bucket |
| 94 |
vars: |
| 95 |
bucket_name: "{{ s3_bucket_name }}" |
| 96 |
amazon.aws.s3_bucket: |
| 97 |
state: present |
| 98 |
name: "{{ bucket_name }}" |
| 99 |
policy: '{{ lookup("template", "s3-policy.j2") }}' |
| 100 |
- name: Create second S3 bucket |
| 101 |
vars: |
| 102 |
bucket_name: "{{ s3_bucket_name }}-2" |
| 103 |
amazon.aws.s3_bucket: |
| 104 |
state: present |
| 105 |
name: "{{ bucket_name }}" |
| 106 |
policy: '{{ lookup("template", "s3-policy.j2") }}' |
| 107 |
|
| 108 |
- name: Create SNS Topic |
| 109 |
vars: |
| 110 |
sns_topic_name: "{{ sns_topic }}" |
| 111 |
community.aws.sns_topic: |
| 112 |
state: present |
| 113 |
name: "{{ sns_topic_name }}" |
| 114 |
display_name: Used for testing SNS/CloudWatch integration |
| 115 |
policy: "{{ lookup('template', 'sns-policy.j2') | to_json }}" |
| 116 |
register: output_sns_topic |
| 117 |
- name: Create second SNS Topic |
| 118 |
vars: |
| 119 |
sns_topic_name: "{{ sns_topic }}-2" |
| 120 |
community.aws.sns_topic: |
| 121 |
state: present |
| 122 |
name: "{{ sns_topic_name }}" |
| 123 |
display_name: Used for testing SNS/CloudWatch integration |
| 124 |
policy: "{{ lookup('template', 'sns-policy.j2') | to_json }}" |
| 125 |
|
| 126 |
- name: Create KMS Key |
| 127 |
amazon.aws.kms_key: |
| 128 |
state: present |
| 129 |
alias: "{{ kms_alias }}" |
| 130 |
enabled: true |
| 131 |
policy: "{{ lookup('template', 'kms-policy.j2') | to_json }}" |
| 132 |
register: kms_key |
| 133 |
- name: Create second KMS Key |
| 134 |
amazon.aws.kms_key: |
| 135 |
state: present |
| 136 |
alias: "{{ kms_alias }}-2" |
| 137 |
enabled: true |
| 138 |
policy: "{{ lookup('template', 'kms-policy.j2') | to_json }}" |
| 139 |
register: kms_key2 |
| 140 |
|
| 141 |
- name: Create CloudWatch IAM Role |
| 142 |
amazon.aws.iam_role: |
| 143 |
state: present |
| 144 |
name: "{{ cloudwatch_role }}" |
| 145 |
assume_role_policy_document: "{{ lookup('template', 'cloudwatch-assume-policy.j2') }}" |
| 146 |
register: output_cloudwatch_role |
| 147 |
- name: Create CloudWatch Log Group |
| 148 |
amazon.aws.cloudwatchlogs_log_group: |
| 149 |
state: present |
| 150 |
log_group_name: "{{ cloudwatch_log_group }}" |
| 151 |
retention: 1 |
| 152 |
register: output_cloudwatch_log_group |
| 153 |
- name: Create second CloudWatch Log Group |
| 154 |
amazon.aws.cloudwatchlogs_log_group: |
| 155 |
state: present |
| 156 |
log_group_name: "{{ cloudwatch_log_group }}-2" |
| 157 |
retention: 1 |
| 158 |
register: output_cloudwatch_log_group2 |
| 159 |
- name: Add inline policy to CloudWatch Role |
| 160 |
amazon.aws.iam_policy: |
| 161 |
state: present |
| 162 |
iam_type: role |
| 163 |
iam_name: "{{ cloudwatch_role }}" |
| 164 |
policy_name: CloudWatch |
| 165 |
policy_json: "{{ lookup('template', 'cloudwatch-policy.j2') | to_json }}" |
| 166 |
|
| 167 |
- name: Create CloudWatch IAM Role with no kms permissions |
| 168 |
amazon.aws.iam_role: |
| 169 |
state: present |
| 170 |
name: "{{ cloudwatch_no_kms_role }}" |
| 171 |
assume_role_policy_document: "{{ lookup('template', 'cloudtrail-no-kms-assume-policy.j2') }}" |
| 172 |
managed_policies: |
| 173 |
- arn:aws:iam::aws:policy/AWSCloudTrail_FullAccess |
| 174 |
register: output_cloudwatch_no_kms_role |
| 175 |
|
| 176 |
- name: Pause to ensure role exists before attaching policy |
| 177 |
ansible.builtin.pause: |
| 178 |
seconds: 15 |
| 179 |
|
| 180 |
- name: Add inline policy to CloudWatch Role |
| 181 |
amazon.aws.iam_policy: |
| 182 |
state: present |
| 183 |
iam_type: role |
| 184 |
iam_name: "{{ cloudwatch_no_kms_role }}" |
| 185 |
policy_name: CloudWatchNokms |
| 186 |
policy_json: "{{ lookup('template', 'cloudtrail-no-kms-policy.j2') }}" |
| 187 |
|
| 188 |
# ============================================================ |
| 189 |
# Tests |
| 190 |
# ============================================================ |
| 191 |
|
| 192 |
- name: Create a trail (CHECK MODE) |
| 193 |
amazon.aws.cloudtrail: |
| 194 |
state: present |
| 195 |
name: "{{ cloudtrail_name }}" |
| 196 |
register: output |
| 197 |
check_mode: true |
| 198 |
- ansible.builtin.assert: |
| 199 |
that: |
| 200 |
- output is changed |
| 201 |
|
| 202 |
- name: Create a trail |
| 203 |
amazon.aws.cloudtrail: |
| 204 |
state: present |
| 205 |
name: "{{ cloudtrail_name }}" |
| 206 |
register: output |
| 207 |
- ansible.builtin.assert: |
| 208 |
that: |
| 209 |
- output is changed |
| 210 |
- output.exists == True |
| 211 |
- output.trail.name == cloudtrail_name |
| 212 |
|
| 213 |
- name: No-op update to trail |
| 214 |
amazon.aws.cloudtrail: |
| 215 |
state: present |
| 216 |
name: "{{ cloudtrail_name }}" |
| 217 |
register: output |
| 218 |
- ansible.builtin.assert: |
| 219 |
that: |
| 220 |
- output is not changed |
| 221 |
- output.exists == True |
| 222 |
# Check everything is what we expect before we start making changes |
| 223 |
- output.trail.name == cloudtrail_name |
| 224 |
- output.trail.home_region == aws_region |
| 225 |
- output.trail.include_global_service_events == True |
| 226 |
- output.trail.is_multi_region_trail == False |
| 227 |
- output.trail.is_logging == True |
| 228 |
- output.trail.log_file_validation_enabled == False |
| 229 |
- output.trail.s3_bucket_name == s3_bucket_name |
| 230 |
- output.trail.s3_key_prefix is none |
| 231 |
- output.trail.kms_key_id is none |
| 232 |
- output.trail.sns_topic_arn is none |
| 233 |
- output.trail.sns_topic_name is none |
| 234 |
- output.trail.tags | length == 0 |
| 235 |
|
| 236 |
- name: Get the trail info |
| 237 |
amazon.aws.cloudtrail_info: |
| 238 |
register: info |
| 239 |
|
| 240 |
- name: Get the trail name from the cloud trail info |
| 241 |
ansible.builtin.set_fact: |
| 242 |
trail_present: true |
| 243 |
trail_arn: "{{ item.resource_id }}" |
| 244 |
when: item.name == cloudtrail_name |
| 245 |
loop: "{{ info.trail_list }}" |
| 246 |
|
| 247 |
- name: Assert that the trail name is present in the info |
| 248 |
ansible.builtin.assert: |
| 249 |
that: |
| 250 |
- trail_present is defined |
| 251 |
- trail_present == True |
| 252 |
|
| 253 |
# ============================================================ |
| 254 |
|
| 255 |
- name: Set S3 prefix (CHECK MODE) |
| 256 |
amazon.aws.cloudtrail: |
| 257 |
state: present |
| 258 |
name: "{{ cloudtrail_name }}" |
| 259 |
s3_key_prefix: "{{ cloudtrail_prefix }}" |
| 260 |
register: output |
| 261 |
check_mode: true |
| 262 |
- ansible.builtin.assert: |
| 263 |
that: |
| 264 |
- output is changed |
| 265 |
|
| 266 |
- name: Set S3 prefix |
| 267 |
amazon.aws.cloudtrail: |
| 268 |
state: present |
| 269 |
name: "{{ cloudtrail_name }}" |
| 270 |
s3_key_prefix: "{{ cloudtrail_prefix }}" |
| 271 |
register: output |
| 272 |
- ansible.builtin.assert: |
| 273 |
that: |
| 274 |
- output is changed |
| 275 |
- output.trail.name == cloudtrail_name |
| 276 |
- output.trail.s3_key_prefix == cloudtrail_prefix |
| 277 |
|
| 278 |
- name: Set S3 prefix (no change) |
| 279 |
amazon.aws.cloudtrail: |
| 280 |
state: present |
| 281 |
name: "{{ cloudtrail_name }}" |
| 282 |
s3_key_prefix: "{{ cloudtrail_prefix }}" |
| 283 |
register: output |
| 284 |
- ansible.builtin.assert: |
| 285 |
that: |
| 286 |
- output is not changed |
| 287 |
- output.trail.name == cloudtrail_name |
| 288 |
- output.trail.s3_key_prefix == cloudtrail_prefix |
| 289 |
|
| 290 |
- name: No-op update to trail |
| 291 |
amazon.aws.cloudtrail: |
| 292 |
state: present |
| 293 |
name: "{{ cloudtrail_name }}" |
| 294 |
register: output |
| 295 |
- ansible.builtin.assert: |
| 296 |
that: |
| 297 |
- output is not changed |
| 298 |
- output.trail.name == cloudtrail_name |
| 299 |
- output.trail.s3_key_prefix == cloudtrail_prefix |
| 300 |
|
| 301 |
- name: Get the trail info |
| 302 |
amazon.aws.cloudtrail_info: |
| 303 |
trail_names: |
| 304 |
- "{{ trail_arn }}" |
| 305 |
register: info |
| 306 |
|
| 307 |
- name: Assert that the s3_key_prefix is correct |
| 308 |
ansible.builtin.assert: |
| 309 |
that: |
| 310 |
- info.trail_list[0].s3_key_prefix == cloudtrail_prefix |
| 311 |
|
| 312 |
- name: Update S3 prefix (CHECK MODE) |
| 313 |
amazon.aws.cloudtrail: |
| 314 |
state: present |
| 315 |
name: "{{ cloudtrail_name }}" |
| 316 |
s3_key_prefix: "{{ cloudtrail_prefix }}-2" |
| 317 |
register: output |
| 318 |
check_mode: true |
| 319 |
- ansible.builtin.assert: |
| 320 |
that: |
| 321 |
- output is changed |
| 322 |
|
| 323 |
- name: Update S3 prefix |
| 324 |
amazon.aws.cloudtrail: |
| 325 |
state: present |
| 326 |
name: "{{ cloudtrail_name }}" |
| 327 |
s3_key_prefix: "{{ cloudtrail_prefix }}-2" |
| 328 |
register: output |
| 329 |
- ansible.builtin.assert: |
| 330 |
that: |
| 331 |
- output is changed |
| 332 |
- output.trail.name == cloudtrail_name |
| 333 |
- output.trail.s3_key_prefix == cloudtrail_prefix+"-2" |
| 334 |
|
| 335 |
- name: Update S3 prefix (no change) |
| 336 |
amazon.aws.cloudtrail: |
| 337 |
state: present |
| 338 |
name: "{{ cloudtrail_name }}" |
| 339 |
s3_key_prefix: "{{ cloudtrail_prefix }}-2" |
| 340 |
register: output |
| 341 |
- ansible.builtin.assert: |
| 342 |
that: |
| 343 |
- output is not changed |
| 344 |
- output.trail.name == cloudtrail_name |
| 345 |
- output.trail.s3_key_prefix == cloudtrail_prefix+"-2" |
| 346 |
|
| 347 |
- name: Get the trail info after updating S3 prefix |
| 348 |
amazon.aws.cloudtrail_info: |
| 349 |
trail_names: |
| 350 |
- "{{ trail_arn }}" |
| 351 |
register: info |
| 352 |
|
| 353 |
- name: Assert that the s3_key_prefix is correct |
| 354 |
ansible.builtin.assert: |
| 355 |
that: |
| 356 |
- info.trail_list[0].s3_key_prefix == cloudtrail_prefix+"-2" |
| 357 |
|
| 358 |
- name: Remove S3 prefix (CHECK MODE) |
| 359 |
amazon.aws.cloudtrail: |
| 360 |
state: present |
| 361 |
name: "{{ cloudtrail_name }}" |
| 362 |
s3_key_prefix: / |
| 363 |
register: output |
| 364 |
check_mode: true |
| 365 |
- ansible.builtin.assert: |
| 366 |
that: |
| 367 |
- output is changed |
| 368 |
|
| 369 |
- name: Remove S3 prefix |
| 370 |
amazon.aws.cloudtrail: |
| 371 |
state: present |
| 372 |
name: "{{ cloudtrail_name }}" |
| 373 |
s3_key_prefix: / |
| 374 |
register: output |
| 375 |
- ansible.builtin.assert: |
| 376 |
that: |
| 377 |
- output is changed |
| 378 |
- output.trail.name == cloudtrail_name |
| 379 |
- output.trail.s3_key_prefix is none |
| 380 |
|
| 381 |
- name: Remove S3 prefix (no change) |
| 382 |
amazon.aws.cloudtrail: |
| 383 |
state: present |
| 384 |
name: "{{ cloudtrail_name }}" |
| 385 |
s3_key_prefix: / |
| 386 |
register: output |
| 387 |
- ansible.builtin.assert: |
| 388 |
that: |
| 389 |
- output is not changed |
| 390 |
- output.trail.name == cloudtrail_name |
| 391 |
- output.trail.s3_key_prefix is none |
| 392 |
|
| 393 |
- name: Get the trail info after removing S3 prefix |
| 394 |
amazon.aws.cloudtrail_info: |
| 395 |
trail_names: |
| 396 |
- "{{ trail_arn }}" |
| 397 |
register: info |
| 398 |
|
| 399 |
- name: Assert that the s3_key_prefix is None |
| 400 |
ansible.builtin.assert: |
| 401 |
that: |
| 402 |
- info.trail_list[0].s3_key_prefix is not defined |
| 403 |
|
| 404 |
# ============================================================ |
| 405 |
|
| 406 |
- ansible.builtin.include_tasks: tagging.yml |
| 407 |
- name: Set SNS Topic (CHECK MODE) |
| 408 |
amazon.aws.cloudtrail: |
| 409 |
state: present |
| 410 |
name: "{{ cloudtrail_name }}" |
| 411 |
sns_topic_name: "{{ sns_topic }}" |
| 412 |
register: output |
| 413 |
check_mode: true |
| 414 |
- ansible.builtin.assert: |
| 415 |
that: |
| 416 |
- output is changed |
| 417 |
|
| 418 |
- name: Set SNS Topic |
| 419 |
amazon.aws.cloudtrail: |
| 420 |
state: present |
| 421 |
name: "{{ cloudtrail_name }}" |
| 422 |
sns_topic_name: "{{ sns_topic }}" |
| 423 |
register: output |
| 424 |
- ansible.builtin.assert: |
| 425 |
that: |
| 426 |
- output is changed |
| 427 |
- output.trail.name == cloudtrail_name |
| 428 |
- output.trail.sns_topic_name == sns_topic |
| 429 |
|
| 430 |
- name: Set SNS Topic (no change) |
| 431 |
amazon.aws.cloudtrail: |
| 432 |
state: present |
| 433 |
name: "{{ cloudtrail_name }}" |
| 434 |
sns_topic_name: "{{ sns_topic }}" |
| 435 |
register: output |
| 436 |
- ansible.builtin.assert: |
| 437 |
that: |
| 438 |
- output is not changed |
| 439 |
- output.trail.name == cloudtrail_name |
| 440 |
- output.trail.sns_topic_name == sns_topic |
| 441 |
|
| 442 |
- name: No-op update to trail |
| 443 |
amazon.aws.cloudtrail: |
| 444 |
state: present |
| 445 |
name: "{{ cloudtrail_name }}" |
| 446 |
register: output |
| 447 |
- ansible.builtin.assert: |
| 448 |
that: |
| 449 |
- output is not changed |
| 450 |
- output.trail.name == cloudtrail_name |
| 451 |
- output.trail.sns_topic_name == sns_topic |
| 452 |
|
| 453 |
- name: Get the trail info with SNS topic |
| 454 |
amazon.aws.cloudtrail_info: |
| 455 |
trail_names: |
| 456 |
- "{{ trail_arn }}" |
| 457 |
register: info |
| 458 |
|
| 459 |
- name: Assert that the sns_topic is correctly set |
| 460 |
ansible.builtin.assert: |
| 461 |
that: |
| 462 |
- info.trail_list[0].sns_topic_name == sns_topic |
| 463 |
|
| 464 |
- name: Update SNS Topic (CHECK MODE) |
| 465 |
amazon.aws.cloudtrail: |
| 466 |
state: present |
| 467 |
name: "{{ cloudtrail_name }}" |
| 468 |
sns_topic_name: "{{ sns_topic }}-2" |
| 469 |
register: output |
| 470 |
check_mode: true |
| 471 |
- ansible.builtin.assert: |
| 472 |
that: |
| 473 |
- output is changed |
| 474 |
|
| 475 |
- name: Update SNS Topic |
| 476 |
amazon.aws.cloudtrail: |
| 477 |
state: present |
| 478 |
name: "{{ cloudtrail_name }}" |
| 479 |
sns_topic_name: "{{ sns_topic }}-2" |
| 480 |
register: output |
| 481 |
- ansible.builtin.assert: |
| 482 |
that: |
| 483 |
- output is changed |
| 484 |
- output.trail.name == cloudtrail_name |
| 485 |
- output.trail.sns_topic_name == sns_topic+"-2" |
| 486 |
|
| 487 |
- name: Update SNS Topic (no change) |
| 488 |
amazon.aws.cloudtrail: |
| 489 |
state: present |
| 490 |
name: "{{ cloudtrail_name }}" |
| 491 |
sns_topic_name: "{{ sns_topic }}-2" |
| 492 |
register: output |
| 493 |
- ansible.builtin.assert: |
| 494 |
that: |
| 495 |
- output is not changed |
| 496 |
- output.trail.name == cloudtrail_name |
| 497 |
- output.trail.sns_topic_name == sns_topic+"-2" |
| 498 |
|
| 499 |
- name: Get the trail info with SNS topic after update |
| 500 |
amazon.aws.cloudtrail_info: |
| 501 |
trail_names: |
| 502 |
- "{{ trail_arn }}" |
| 503 |
register: info |
| 504 |
|
| 505 |
- name: Assert that the sns_topic is correctly set |
| 506 |
ansible.builtin.assert: |
| 507 |
that: |
| 508 |
- info.trail_list[0].sns_topic_name == sns_topic+"-2" |
| 509 |
|
| 510 |
# - name: 'Remove SNS Topic (CHECK MODE)' |
| 511 |
# amazon.aws.cloudtrail: |
| 512 |
# state: present |
| 513 |
# name: '{{ cloudtrail_name }}' |
| 514 |
# sns_topic_name: '' |
| 515 |
# register: output |
| 516 |
# check_mode: yes |
| 517 |
# - assert: |
| 518 |
# that: |
| 519 |
# - output is changed |
| 520 |
|
| 521 |
# - name: 'Remove SNS Topic' |
| 522 |
# amazon.aws.cloudtrail: |
| 523 |
# state: present |
| 524 |
# name: '{{ cloudtrail_name }}' |
| 525 |
# sns_topic_name: '' |
| 526 |
# register: output |
| 527 |
# - assert: |
| 528 |
# that: |
| 529 |
# - output is changed |
| 530 |
# - output.trail.name == cloudtrail_name |
| 531 |
# - output.trail.sns_topic_name is none |
| 532 |
|
| 533 |
# - name: 'Remove SNS Topic (no change)' |
| 534 |
# amazon.aws.cloudtrail: |
| 535 |
# state: present |
| 536 |
# name: '{{ cloudtrail_name }}' |
| 537 |
# sns_topic_name: '' |
| 538 |
# register: output |
| 539 |
# - assert: |
| 540 |
# that: |
| 541 |
# - output is not changed |
| 542 |
# - output.trail.name == cloudtrail_name |
| 543 |
# - output.trail.sns_topic_name is none |
| 544 |
|
| 545 |
# ============================================================ |
| 546 |
|
| 547 |
- name: Set CloudWatch Log Group (CHECK MODE) |
| 548 |
amazon.aws.cloudtrail: |
| 549 |
state: present |
| 550 |
name: "{{ cloudtrail_name }}" |
| 551 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group.arn }}" |
| 552 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 553 |
register: output |
| 554 |
check_mode: true |
| 555 |
- ansible.builtin.assert: |
| 556 |
that: |
| 557 |
- output is changed |
| 558 |
|
| 559 |
- name: Set CloudWatch Log Group |
| 560 |
amazon.aws.cloudtrail: |
| 561 |
state: present |
| 562 |
name: "{{ cloudtrail_name }}" |
| 563 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group.arn }}" |
| 564 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 565 |
register: output |
| 566 |
- ansible.builtin.assert: |
| 567 |
that: |
| 568 |
- output is changed |
| 569 |
- output.trail.name == cloudtrail_name |
| 570 |
- output.trail.cloud_watch_logs_log_group_arn == output_cloudwatch_log_group.arn |
| 571 |
- output.trail.cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 572 |
|
| 573 |
- name: Set CloudWatch Log Group (no change) |
| 574 |
amazon.aws.cloudtrail: |
| 575 |
state: present |
| 576 |
name: "{{ cloudtrail_name }}" |
| 577 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group.arn }}" |
| 578 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 579 |
register: output |
| 580 |
- ansible.builtin.assert: |
| 581 |
that: |
| 582 |
- output is not changed |
| 583 |
- output.trail.name == cloudtrail_name |
| 584 |
- output.trail.cloud_watch_logs_log_group_arn == output_cloudwatch_log_group.arn |
| 585 |
- output.trail.cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 586 |
|
| 587 |
- name: No-op update to trail |
| 588 |
amazon.aws.cloudtrail: |
| 589 |
state: present |
| 590 |
name: "{{ cloudtrail_name }}" |
| 591 |
register: output |
| 592 |
- ansible.builtin.assert: |
| 593 |
that: |
| 594 |
- output is not changed |
| 595 |
- output.trail.name == cloudtrail_name |
| 596 |
- output.trail.cloud_watch_logs_log_group_arn == output_cloudwatch_log_group.arn |
| 597 |
- output.trail.cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 598 |
|
| 599 |
- name: Get the trail info with CloudWatch Log Group |
| 600 |
amazon.aws.cloudtrail_info: |
| 601 |
trail_names: |
| 602 |
- "{{ trail_arn }}" |
| 603 |
register: info |
| 604 |
|
| 605 |
- name: Assert that the cloud watch log group is correctly set |
| 606 |
ansible.builtin.assert: |
| 607 |
that: |
| 608 |
- info.trail_list[0].cloud_watch_logs_log_group_arn == output_cloudwatch_log_group.arn |
| 609 |
- info.trail_list[0].cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 610 |
|
| 611 |
- name: Update CloudWatch Log Group (CHECK MODE) |
| 612 |
amazon.aws.cloudtrail: |
| 613 |
state: present |
| 614 |
name: "{{ cloudtrail_name }}" |
| 615 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group2.arn }}" |
| 616 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 617 |
register: output |
| 618 |
check_mode: true |
| 619 |
- ansible.builtin.assert: |
| 620 |
that: |
| 621 |
- output is changed |
| 622 |
- output.trail.cloud_watch_logs_log_group_arn == output_cloudwatch_log_group2.arn |
| 623 |
- output.trail.cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 624 |
|
| 625 |
- name: Update CloudWatch Log Group |
| 626 |
amazon.aws.cloudtrail: |
| 627 |
state: present |
| 628 |
name: "{{ cloudtrail_name }}" |
| 629 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group2.arn }}" |
| 630 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 631 |
register: output |
| 632 |
- ansible.builtin.assert: |
| 633 |
that: |
| 634 |
- output is changed |
| 635 |
- output.trail.name == cloudtrail_name |
| 636 |
- output.trail.cloud_watch_logs_log_group_arn == output_cloudwatch_log_group2.arn |
| 637 |
- output.trail.cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 638 |
|
| 639 |
- name: Update CloudWatch Log Group (no change) |
| 640 |
amazon.aws.cloudtrail: |
| 641 |
state: present |
| 642 |
name: "{{ cloudtrail_name }}" |
| 643 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group2.arn }}" |
| 644 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 645 |
register: output |
| 646 |
- ansible.builtin.assert: |
| 647 |
that: |
| 648 |
- output is not changed |
| 649 |
- output.trail.name == cloudtrail_name |
| 650 |
- output.trail.cloud_watch_logs_log_group_arn == output_cloudwatch_log_group2.arn |
| 651 |
- output.trail.cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 652 |
|
| 653 |
- name: Get the trail info with CloudWatch Log Group after update |
| 654 |
amazon.aws.cloudtrail_info: |
| 655 |
trail_names: |
| 656 |
- "{{ trail_arn }}" |
| 657 |
register: info |
| 658 |
|
| 659 |
- name: Assert that the cloud watch log group is correctly set after update |
| 660 |
ansible.builtin.assert: |
| 661 |
that: |
| 662 |
- info.trail_list[0].cloud_watch_logs_log_group_arn == output_cloudwatch_log_group2.arn |
| 663 |
- info.trail_list[0].cloud_watch_logs_role_arn == output_cloudwatch_role.iam_role.arn |
| 664 |
|
| 665 |
# - name: 'Remove CloudWatch Log Group (CHECK MODE)' |
| 666 |
# amazon.aws.cloudtrail: |
| 667 |
# state: present |
| 668 |
# name: '{{ cloudtrail_name }}' |
| 669 |
# cloudwatch_logs_log_group_arn: '' |
| 670 |
# cloudwatch_logs_role_arn: '' |
| 671 |
# register: output |
| 672 |
# check_mode: yes |
| 673 |
# - assert: |
| 674 |
# that: |
| 675 |
# - output is changed |
| 676 |
# - output.trail.name == cloudtrail_name |
| 677 |
# - output.trail.cloud_watch_logs_log_group_arn is none |
| 678 |
# - output.trail.cloud_watch_logs_role_arn is none |
| 679 |
|
| 680 |
# - name: 'Remove CloudWatch Log Group' |
| 681 |
# amazon.aws.cloudtrail: |
| 682 |
# state: present |
| 683 |
# name: '{{ cloudtrail_name }}' |
| 684 |
# cloudwatch_logs_log_group_arn: '' |
| 685 |
# cloudwatch_logs_role_arn: '' |
| 686 |
# register: output |
| 687 |
# - assert: |
| 688 |
# that: |
| 689 |
# - output is changed |
| 690 |
# - output.trail.name == cloudtrail_name |
| 691 |
# - output.trail.cloud_watch_logs_log_group_arn is none |
| 692 |
# - output.trail.cloud_watch_logs_role_arn is none |
| 693 |
|
| 694 |
# - name: 'Remove CloudWatch Log Group (no change)' |
| 695 |
# amazon.aws.cloudtrail: |
| 696 |
# state: present |
| 697 |
# name: '{{ cloudtrail_name }}' |
| 698 |
# cloudwatch_logs_log_group_arn: '' |
| 699 |
# cloudwatch_logs_role_arn: '' |
| 700 |
# register: output |
| 701 |
# - assert: |
| 702 |
# that: |
| 703 |
# - output is not changed |
| 704 |
# - output.trail.name == cloudtrail_name |
| 705 |
# - output.trail.cloud_watch_logs_log_group_arn is none |
| 706 |
# - output.trail.cloud_watch_logs_role_arn is none |
| 707 |
|
| 708 |
# ============================================================ |
| 709 |
|
| 710 |
- name: Update S3 bucket (CHECK MODE) |
| 711 |
amazon.aws.cloudtrail: |
| 712 |
state: present |
| 713 |
name: "{{ cloudtrail_name }}" |
| 714 |
s3_bucket_name: "{{ s3_bucket_name }}-2" |
| 715 |
register: output |
| 716 |
check_mode: true |
| 717 |
- ansible.builtin.assert: |
| 718 |
that: |
| 719 |
- output is changed |
| 720 |
|
| 721 |
- name: Update S3 bucket |
| 722 |
amazon.aws.cloudtrail: |
| 723 |
state: present |
| 724 |
name: "{{ cloudtrail_name }}" |
| 725 |
s3_bucket_name: "{{ s3_bucket_name }}-2" |
| 726 |
register: output |
| 727 |
- ansible.builtin.assert: |
| 728 |
that: |
| 729 |
- output is changed |
| 730 |
- output.trail.name == cloudtrail_name |
| 731 |
- output.trail.s3_bucket_name == s3_bucket_name+"-2" |
| 732 |
|
| 733 |
- name: Update S3 bucket (no change) |
| 734 |
amazon.aws.cloudtrail: |
| 735 |
state: present |
| 736 |
name: "{{ cloudtrail_name }}" |
| 737 |
s3_bucket_name: "{{ s3_bucket_name }}-2" |
| 738 |
register: output |
| 739 |
- ansible.builtin.assert: |
| 740 |
that: |
| 741 |
- output is not changed |
| 742 |
- output.trail.name == cloudtrail_name |
| 743 |
- output.trail.s3_bucket_name == s3_bucket_name+"-2" |
| 744 |
|
| 745 |
- name: Get the trail info with S3 bucket name |
| 746 |
amazon.aws.cloudtrail_info: |
| 747 |
trail_names: |
| 748 |
- "{{ trail_arn }}" |
| 749 |
register: info |
| 750 |
|
| 751 |
- name: Assert that the S3 Bucket name is correctly set |
| 752 |
ansible.builtin.assert: |
| 753 |
that: |
| 754 |
- info.trail_list[0].s3_bucket_name == s3_bucket_name+"-2" |
| 755 |
|
| 756 |
- name: Reset S3 bucket |
| 757 |
amazon.aws.cloudtrail: |
| 758 |
state: present |
| 759 |
name: "{{ cloudtrail_name }}" |
| 760 |
register: output |
| 761 |
- ansible.builtin.assert: |
| 762 |
that: |
| 763 |
- output.trail.name == cloudtrail_name |
| 764 |
- output.trail.s3_bucket_name == s3_bucket_name |
| 765 |
|
| 766 |
# ============================================================ |
| 767 |
|
| 768 |
- name: Disable logging (CHECK MODE) |
| 769 |
amazon.aws.cloudtrail: |
| 770 |
state: present |
| 771 |
name: "{{ cloudtrail_name }}" |
| 772 |
enable_logging: false |
| 773 |
register: output |
| 774 |
check_mode: true |
| 775 |
- ansible.builtin.assert: |
| 776 |
that: |
| 777 |
- output is changed |
| 778 |
|
| 779 |
- name: Disable logging |
| 780 |
amazon.aws.cloudtrail: |
| 781 |
state: present |
| 782 |
name: "{{ cloudtrail_name }}" |
| 783 |
enable_logging: false |
| 784 |
register: output |
| 785 |
- ansible.builtin.assert: |
| 786 |
that: |
| 787 |
- output is changed |
| 788 |
- output.trail.name == cloudtrail_name |
| 789 |
- output.trail.is_logging == False |
| 790 |
|
| 791 |
- name: Disable logging (no change) |
| 792 |
amazon.aws.cloudtrail: |
| 793 |
state: present |
| 794 |
name: "{{ cloudtrail_name }}" |
| 795 |
enable_logging: false |
| 796 |
register: output |
| 797 |
- ansible.builtin.assert: |
| 798 |
that: |
| 799 |
- output is not changed |
| 800 |
- output.trail.name == cloudtrail_name |
| 801 |
- output.trail.is_logging == False |
| 802 |
|
| 803 |
- name: Get the trail info to check the logging state |
| 804 |
amazon.aws.cloudtrail_info: |
| 805 |
trail_names: |
| 806 |
- "{{ trail_arn }}" |
| 807 |
register: info |
| 808 |
|
| 809 |
- name: Assert that the logging state is correctly set |
| 810 |
ansible.builtin.assert: |
| 811 |
that: |
| 812 |
- info.trail_list[0].is_logging == False |
| 813 |
|
| 814 |
# Ansible Documentation lists logging as explicitly defaulting to enabled |
| 815 |
|
| 816 |
- name: Enable logging (CHECK MODE) |
| 817 |
amazon.aws.cloudtrail: |
| 818 |
state: present |
| 819 |
name: "{{ cloudtrail_name }}" |
| 820 |
enable_logging: true |
| 821 |
register: output |
| 822 |
check_mode: true |
| 823 |
- ansible.builtin.assert: |
| 824 |
that: |
| 825 |
- output is changed |
| 826 |
|
| 827 |
- name: Enable logging |
| 828 |
amazon.aws.cloudtrail: |
| 829 |
state: present |
| 830 |
name: "{{ cloudtrail_name }}" |
| 831 |
enable_logging: true |
| 832 |
register: output |
| 833 |
- ansible.builtin.assert: |
| 834 |
that: |
| 835 |
- output is changed |
| 836 |
- output.trail.name == cloudtrail_name |
| 837 |
- output.trail.is_logging == True |
| 838 |
|
| 839 |
- name: Enable logging (no change) |
| 840 |
amazon.aws.cloudtrail: |
| 841 |
state: present |
| 842 |
name: "{{ cloudtrail_name }}" |
| 843 |
enable_logging: true |
| 844 |
register: output |
| 845 |
- ansible.builtin.assert: |
| 846 |
that: |
| 847 |
- output is not changed |
| 848 |
- output.trail.name == cloudtrail_name |
| 849 |
- output.trail.is_logging == True |
| 850 |
|
| 851 |
- name: Get the trail info to check the logging state |
| 852 |
amazon.aws.cloudtrail_info: |
| 853 |
trail_names: |
| 854 |
- "{{ trail_arn }}" |
| 855 |
register: info |
| 856 |
|
| 857 |
- name: Assert that the logging state is correctly set |
| 858 |
ansible.builtin.assert: |
| 859 |
that: |
| 860 |
- info.trail_list[0].is_logging == True |
| 861 |
|
| 862 |
# ============================================================ |
| 863 |
|
| 864 |
- name: Disable global logging (CHECK MODE) |
| 865 |
amazon.aws.cloudtrail: |
| 866 |
state: present |
| 867 |
name: "{{ cloudtrail_name }}" |
| 868 |
include_global_events: false |
| 869 |
register: output |
| 870 |
check_mode: true |
| 871 |
- ansible.builtin.assert: |
| 872 |
that: |
| 873 |
- output is changed |
| 874 |
|
| 875 |
- name: Disable global logging |
| 876 |
amazon.aws.cloudtrail: |
| 877 |
state: present |
| 878 |
name: "{{ cloudtrail_name }}" |
| 879 |
include_global_events: false |
| 880 |
register: output |
| 881 |
- ansible.builtin.assert: |
| 882 |
that: |
| 883 |
- output is changed |
| 884 |
- output.trail.name == cloudtrail_name |
| 885 |
- output.trail.include_global_service_events == False |
| 886 |
|
| 887 |
- name: Disable global logging (no change) |
| 888 |
amazon.aws.cloudtrail: |
| 889 |
state: present |
| 890 |
name: "{{ cloudtrail_name }}" |
| 891 |
include_global_events: false |
| 892 |
register: output |
| 893 |
- ansible.builtin.assert: |
| 894 |
that: |
| 895 |
- output is not changed |
| 896 |
- output.trail.name == cloudtrail_name |
| 897 |
- output.trail.include_global_service_events == False |
| 898 |
|
| 899 |
- name: Get the trail info to check the global logging state |
| 900 |
amazon.aws.cloudtrail_info: |
| 901 |
trail_names: |
| 902 |
- "{{ trail_arn }}" |
| 903 |
register: info |
| 904 |
|
| 905 |
- name: Assert that the global logging state is correctly set |
| 906 |
ansible.builtin.assert: |
| 907 |
that: |
| 908 |
- info.trail_list[0].include_global_service_events == False |
| 909 |
|
| 910 |
# Ansible Documentation lists Global-logging as explicitly defaulting to enabled |
| 911 |
|
| 912 |
- name: Enable global logging (CHECK MODE) |
| 913 |
amazon.aws.cloudtrail: |
| 914 |
state: present |
| 915 |
name: "{{ cloudtrail_name }}" |
| 916 |
include_global_events: true |
| 917 |
register: output |
| 918 |
check_mode: true |
| 919 |
- ansible.builtin.assert: |
| 920 |
that: |
| 921 |
- output is changed |
| 922 |
|
| 923 |
- name: Enable global logging |
| 924 |
amazon.aws.cloudtrail: |
| 925 |
state: present |
| 926 |
name: "{{ cloudtrail_name }}" |
| 927 |
include_global_events: true |
| 928 |
register: output |
| 929 |
- ansible.builtin.assert: |
| 930 |
that: |
| 931 |
- output is changed |
| 932 |
- output.trail.name == cloudtrail_name |
| 933 |
- output.trail.include_global_service_events == True |
| 934 |
|
| 935 |
- name: Enable global logging (no change) |
| 936 |
amazon.aws.cloudtrail: |
| 937 |
state: present |
| 938 |
name: "{{ cloudtrail_name }}" |
| 939 |
include_global_events: true |
| 940 |
register: output |
| 941 |
- ansible.builtin.assert: |
| 942 |
that: |
| 943 |
- output is not changed |
| 944 |
- output.trail.name == cloudtrail_name |
| 945 |
- output.trail.include_global_service_events == True |
| 946 |
|
| 947 |
- name: Get the trail info to check the global logging state (default) |
| 948 |
amazon.aws.cloudtrail_info: |
| 949 |
trail_names: |
| 950 |
- "{{ trail_arn }}" |
| 951 |
register: info |
| 952 |
|
| 953 |
- name: Assert that the global logging state is correctly set (default) |
| 954 |
ansible.builtin.assert: |
| 955 |
that: |
| 956 |
- info.trail_list[0].include_global_service_events == True |
| 957 |
|
| 958 |
# ============================================================ |
| 959 |
|
| 960 |
- name: Enable multi-region logging (CHECK MODE) |
| 961 |
amazon.aws.cloudtrail: |
| 962 |
state: present |
| 963 |
name: "{{ cloudtrail_name }}" |
| 964 |
is_multi_region_trail: true |
| 965 |
register: output |
| 966 |
check_mode: true |
| 967 |
- ansible.builtin.assert: |
| 968 |
that: |
| 969 |
- output is changed |
| 970 |
|
| 971 |
- name: Enable multi-region logging |
| 972 |
amazon.aws.cloudtrail: |
| 973 |
state: present |
| 974 |
name: "{{ cloudtrail_name }}" |
| 975 |
is_multi_region_trail: true |
| 976 |
register: output |
| 977 |
- ansible.builtin.assert: |
| 978 |
that: |
| 979 |
- output is changed |
| 980 |
- output.trail.name == cloudtrail_name |
| 981 |
- output.trail.is_multi_region_trail == True |
| 982 |
|
| 983 |
- name: Enable multi-region logging (no change) |
| 984 |
amazon.aws.cloudtrail: |
| 985 |
state: present |
| 986 |
name: "{{ cloudtrail_name }}" |
| 987 |
is_multi_region_trail: true |
| 988 |
register: output |
| 989 |
- ansible.builtin.assert: |
| 990 |
that: |
| 991 |
- output is not changed |
| 992 |
- output.trail.name == cloudtrail_name |
| 993 |
- output.trail.is_multi_region_trail == True |
| 994 |
|
| 995 |
- name: Get the trail info to check the multi-region logging state (default) |
| 996 |
amazon.aws.cloudtrail_info: |
| 997 |
trail_names: |
| 998 |
- "{{ trail_arn }}" |
| 999 |
register: info |
| 1000 |
|
| 1001 |
- name: Assert that the global logging state is correctly set (default) |
| 1002 |
ansible.builtin.assert: |
| 1003 |
that: |
| 1004 |
- info.trail_list[0].is_multi_region_trail == True |
| 1005 |
|
| 1006 |
# Ansible Documentation lists Multi-Region-logging as explicitly defaulting to disabled |
| 1007 |
|
| 1008 |
- name: Disable multi-region logging (CHECK MODE) |
| 1009 |
amazon.aws.cloudtrail: |
| 1010 |
state: present |
| 1011 |
name: "{{ cloudtrail_name }}" |
| 1012 |
is_multi_region_trail: false |
| 1013 |
register: output |
| 1014 |
check_mode: true |
| 1015 |
- ansible.builtin.assert: |
| 1016 |
that: |
| 1017 |
- output is changed |
| 1018 |
|
| 1019 |
- name: Disable multi-region logging |
| 1020 |
amazon.aws.cloudtrail: |
| 1021 |
state: present |
| 1022 |
name: "{{ cloudtrail_name }}" |
| 1023 |
is_multi_region_trail: false |
| 1024 |
register: output |
| 1025 |
- ansible.builtin.assert: |
| 1026 |
that: |
| 1027 |
- output is changed |
| 1028 |
- output.trail.name == cloudtrail_name |
| 1029 |
- output.trail.is_multi_region_trail == False |
| 1030 |
|
| 1031 |
- name: Disable multi-region logging (no change) |
| 1032 |
amazon.aws.cloudtrail: |
| 1033 |
state: present |
| 1034 |
name: "{{ cloudtrail_name }}" |
| 1035 |
is_multi_region_trail: false |
| 1036 |
register: output |
| 1037 |
- ansible.builtin.assert: |
| 1038 |
that: |
| 1039 |
- output is not changed |
| 1040 |
- output.trail.name == cloudtrail_name |
| 1041 |
- output.trail.is_multi_region_trail == False |
| 1042 |
|
| 1043 |
- name: Get the trail info to check the multi-region logging state (default) |
| 1044 |
amazon.aws.cloudtrail_info: |
| 1045 |
trail_names: |
| 1046 |
- "{{ trail_arn }}" |
| 1047 |
register: info |
| 1048 |
|
| 1049 |
- name: Assert that the global logging state is correctly set (default) |
| 1050 |
ansible.builtin.assert: |
| 1051 |
that: |
| 1052 |
- info.trail_list[0].is_multi_region_trail == False |
| 1053 |
|
| 1054 |
# ============================================================ |
| 1055 |
|
| 1056 |
- name: Enable logfile validation (CHECK MODE) |
| 1057 |
amazon.aws.cloudtrail: |
| 1058 |
state: present |
| 1059 |
name: "{{ cloudtrail_name }}" |
| 1060 |
enable_log_file_validation: true |
| 1061 |
register: output |
| 1062 |
check_mode: true |
| 1063 |
- ansible.builtin.assert: |
| 1064 |
that: |
| 1065 |
- output is changed |
| 1066 |
|
| 1067 |
- name: Enable logfile validation |
| 1068 |
amazon.aws.cloudtrail: |
| 1069 |
state: present |
| 1070 |
name: "{{ cloudtrail_name }}" |
| 1071 |
enable_log_file_validation: true |
| 1072 |
register: output |
| 1073 |
- ansible.builtin.assert: |
| 1074 |
that: |
| 1075 |
- output is changed |
| 1076 |
- output.trail.name == cloudtrail_name |
| 1077 |
- output.trail.log_file_validation_enabled == True |
| 1078 |
|
| 1079 |
- name: Enable logfile validation (no change) |
| 1080 |
amazon.aws.cloudtrail: |
| 1081 |
state: present |
| 1082 |
name: "{{ cloudtrail_name }}" |
| 1083 |
enable_log_file_validation: true |
| 1084 |
register: output |
| 1085 |
- ansible.builtin.assert: |
| 1086 |
that: |
| 1087 |
- output is not changed |
| 1088 |
- output.trail.name == cloudtrail_name |
| 1089 |
- output.trail.log_file_validation_enabled == True |
| 1090 |
|
| 1091 |
- name: No-op update to trail |
| 1092 |
amazon.aws.cloudtrail: |
| 1093 |
state: present |
| 1094 |
name: "{{ cloudtrail_name }}" |
| 1095 |
register: output |
| 1096 |
- ansible.builtin.assert: |
| 1097 |
that: |
| 1098 |
- output is not changed |
| 1099 |
- output.trail.name == cloudtrail_name |
| 1100 |
- output.trail.log_file_validation_enabled == True |
| 1101 |
|
| 1102 |
- name: Get the trail info to check the log file validation |
| 1103 |
amazon.aws.cloudtrail_info: |
| 1104 |
trail_names: |
| 1105 |
- "{{ trail_arn }}" |
| 1106 |
register: info |
| 1107 |
|
| 1108 |
- name: Assert that the log file validation is correctly set |
| 1109 |
ansible.builtin.assert: |
| 1110 |
that: |
| 1111 |
- info.trail_list[0].log_file_validation_enabled == True |
| 1112 |
|
| 1113 |
- name: Disable logfile validation (CHECK MODE) |
| 1114 |
amazon.aws.cloudtrail: |
| 1115 |
state: present |
| 1116 |
name: "{{ cloudtrail_name }}" |
| 1117 |
enable_log_file_validation: false |
| 1118 |
register: output |
| 1119 |
check_mode: true |
| 1120 |
- ansible.builtin.assert: |
| 1121 |
that: |
| 1122 |
- output is changed |
| 1123 |
|
| 1124 |
- name: Disable logfile validation |
| 1125 |
amazon.aws.cloudtrail: |
| 1126 |
state: present |
| 1127 |
name: "{{ cloudtrail_name }}" |
| 1128 |
enable_log_file_validation: false |
| 1129 |
register: output |
| 1130 |
- ansible.builtin.assert: |
| 1131 |
that: |
| 1132 |
- output is changed |
| 1133 |
- output.trail.name == cloudtrail_name |
| 1134 |
- output.trail.log_file_validation_enabled == False |
| 1135 |
|
| 1136 |
- name: Disable logfile validation (no change) |
| 1137 |
amazon.aws.cloudtrail: |
| 1138 |
state: present |
| 1139 |
name: "{{ cloudtrail_name }}" |
| 1140 |
enable_log_file_validation: false |
| 1141 |
register: output |
| 1142 |
- ansible.builtin.assert: |
| 1143 |
that: |
| 1144 |
- output is not changed |
| 1145 |
- output.trail.name == cloudtrail_name |
| 1146 |
- output.trail.log_file_validation_enabled == False |
| 1147 |
|
| 1148 |
- name: Get the trail info to check the log file validation |
| 1149 |
amazon.aws.cloudtrail_info: |
| 1150 |
trail_names: |
| 1151 |
- "{{ trail_arn }}" |
| 1152 |
register: info |
| 1153 |
|
| 1154 |
- name: Assert that the log file validation is disabled |
| 1155 |
ansible.builtin.assert: |
| 1156 |
that: |
| 1157 |
- info.trail_list[0].log_file_validation_enabled == False |
| 1158 |
|
| 1159 |
# ============================================================ |
| 1160 |
|
| 1161 |
- name: Enable logging encryption (CHECK MODE) |
| 1162 |
amazon.aws.cloudtrail: |
| 1163 |
state: present |
| 1164 |
name: "{{ cloudtrail_name }}" |
| 1165 |
kms_key_id: "{{ kms_key.key_arn }}" |
| 1166 |
register: output |
| 1167 |
check_mode: true |
| 1168 |
- ansible.builtin.assert: |
| 1169 |
that: |
| 1170 |
- output is changed |
| 1171 |
|
| 1172 |
- name: Enable logging encryption |
| 1173 |
amazon.aws.cloudtrail: |
| 1174 |
state: present |
| 1175 |
name: "{{ cloudtrail_name }}" |
| 1176 |
kms_key_id: "{{ kms_key.key_arn }}" |
| 1177 |
register: output |
| 1178 |
- ansible.builtin.assert: |
| 1179 |
that: |
| 1180 |
- output is changed |
| 1181 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1182 |
|
| 1183 |
- name: Enable logging encryption (no change) |
| 1184 |
amazon.aws.cloudtrail: |
| 1185 |
state: present |
| 1186 |
name: "{{ cloudtrail_name }}" |
| 1187 |
kms_key_id: "{{ kms_key.key_arn }}" |
| 1188 |
register: output |
| 1189 |
- ansible.builtin.assert: |
| 1190 |
that: |
| 1191 |
- output is not changed |
| 1192 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1193 |
|
| 1194 |
- name: Enable logging encryption (no change, check mode) |
| 1195 |
amazon.aws.cloudtrail: |
| 1196 |
state: present |
| 1197 |
name: "{{ cloudtrail_name }}" |
| 1198 |
kms_key_id: "{{ kms_key.key_arn }}" |
| 1199 |
check_mode: true |
| 1200 |
register: output |
| 1201 |
- ansible.builtin.assert: |
| 1202 |
that: |
| 1203 |
- output is not changed |
| 1204 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1205 |
|
| 1206 |
- name: No-op update to trail |
| 1207 |
amazon.aws.cloudtrail: |
| 1208 |
state: present |
| 1209 |
name: "{{ cloudtrail_name }}" |
| 1210 |
register: output |
| 1211 |
- ansible.builtin.assert: |
| 1212 |
that: |
| 1213 |
- output is not changed |
| 1214 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1215 |
|
| 1216 |
- name: Get the trail info to check the logging encryption |
| 1217 |
amazon.aws.cloudtrail_info: |
| 1218 |
trail_names: |
| 1219 |
- "{{ trail_arn }}" |
| 1220 |
register: info |
| 1221 |
|
| 1222 |
- name: Assert that the logging encryption is correctly set |
| 1223 |
ansible.builtin.assert: |
| 1224 |
that: |
| 1225 |
- info.trail_list[0].kms_key_id == kms_key.key_arn |
| 1226 |
|
| 1227 |
- name: Update logging encryption key (CHECK MODE) |
| 1228 |
amazon.aws.cloudtrail: |
| 1229 |
state: present |
| 1230 |
name: "{{ cloudtrail_name }}" |
| 1231 |
kms_key_id: "{{ kms_key2.key_arn }}" |
| 1232 |
register: output |
| 1233 |
check_mode: true |
| 1234 |
- ansible.builtin.assert: |
| 1235 |
that: |
| 1236 |
- output is changed |
| 1237 |
|
| 1238 |
- name: Update logging encryption key |
| 1239 |
amazon.aws.cloudtrail: |
| 1240 |
state: present |
| 1241 |
name: "{{ cloudtrail_name }}" |
| 1242 |
kms_key_id: "{{ kms_key2.key_arn }}" |
| 1243 |
register: output |
| 1244 |
- ansible.builtin.assert: |
| 1245 |
that: |
| 1246 |
- output is changed |
| 1247 |
- output.trail.kms_key_id == kms_key2.key_arn |
| 1248 |
|
| 1249 |
- name: Update logging encryption key (no change) |
| 1250 |
amazon.aws.cloudtrail: |
| 1251 |
state: present |
| 1252 |
name: "{{ cloudtrail_name }}" |
| 1253 |
kms_key_id: "{{ kms_key2.key_arn }}" |
| 1254 |
register: output |
| 1255 |
- ansible.builtin.assert: |
| 1256 |
that: |
| 1257 |
- output is not changed |
| 1258 |
- output.trail.kms_key_id == kms_key2.key_arn |
| 1259 |
|
| 1260 |
- name: Get the trail info to check the logging key encryption |
| 1261 |
amazon.aws.cloudtrail_info: |
| 1262 |
trail_names: |
| 1263 |
- "{{ trail_arn }}" |
| 1264 |
register: info |
| 1265 |
|
| 1266 |
- name: Assert that the logging key encryption is correctly set |
| 1267 |
ansible.builtin.assert: |
| 1268 |
that: |
| 1269 |
- info.trail_list[0].kms_key_id == kms_key2.key_arn |
| 1270 |
|
| 1271 |
- name: Update logging encryption to alias (CHECK MODE) |
| 1272 |
amazon.aws.cloudtrail: |
| 1273 |
state: present |
| 1274 |
name: "{{ cloudtrail_name }}" |
| 1275 |
kms_key_id: alias/{{ kms_alias }} |
| 1276 |
register: output |
| 1277 |
check_mode: true |
| 1278 |
- ansible.builtin.assert: |
| 1279 |
that: |
| 1280 |
- output is changed |
| 1281 |
|
| 1282 |
- name: Update logging encryption to alias |
| 1283 |
amazon.aws.cloudtrail: |
| 1284 |
state: present |
| 1285 |
name: "{{ cloudtrail_name }}" |
| 1286 |
kms_key_id: alias/{{ kms_alias }} |
| 1287 |
register: output |
| 1288 |
- ansible.builtin.assert: |
| 1289 |
that: |
| 1290 |
- output is changed |
| 1291 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1292 |
|
| 1293 |
- name: Update logging encryption to alias (no change) |
| 1294 |
amazon.aws.cloudtrail: |
| 1295 |
state: present |
| 1296 |
name: "{{ cloudtrail_name }}" |
| 1297 |
kms_key_id: alias/{{ kms_alias }} |
| 1298 |
register: output |
| 1299 |
- ansible.builtin.assert: |
| 1300 |
that: |
| 1301 |
- output is not changed |
| 1302 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1303 |
|
| 1304 |
- name: Update logging encryption to alias (CHECK MODE, no change) |
| 1305 |
amazon.aws.cloudtrail: |
| 1306 |
state: present |
| 1307 |
name: "{{ cloudtrail_name }}" |
| 1308 |
kms_key_id: "{{ kms_key.key_id }}" # Test when using key id |
| 1309 |
register: output |
| 1310 |
check_mode: true |
| 1311 |
- ansible.builtin.assert: |
| 1312 |
that: |
| 1313 |
- output is not changed |
| 1314 |
- output.trail.kms_key_id == kms_key.key_id |
| 1315 |
|
| 1316 |
- ansible.builtin.debug: |
| 1317 |
msg: "{{ output }}" |
| 1318 |
|
| 1319 |
- name: Get the trail info to check the logging key encryption after update |
| 1320 |
amazon.aws.cloudtrail_info: |
| 1321 |
trail_names: |
| 1322 |
- "{{ trail_arn }}" |
| 1323 |
register: info |
| 1324 |
|
| 1325 |
- name: Assert that the logging key encryption is correctly updated |
| 1326 |
ansible.builtin.assert: |
| 1327 |
that: |
| 1328 |
- kms_key.key_id in info.trail_list[0].kms_key_id |
| 1329 |
|
| 1330 |
# Assume role to a role with Denied access to KMS |
| 1331 |
|
| 1332 |
- amazon.aws.sts_assume_role: |
| 1333 |
role_arn: "{{ output_cloudwatch_no_kms_role.iam_role.arn }}" |
| 1334 |
role_session_name: cloudtrailNoKms |
| 1335 |
region: "{{ aws_region }}" |
| 1336 |
register: no_kms_assumed_role |
| 1337 |
|
| 1338 |
- name: Enable logging encryption w/ alias (no change, no kms permmissions, check mode) |
| 1339 |
amazon.aws.cloudtrail: |
| 1340 |
state: present |
| 1341 |
name: "{{ cloudtrail_name }}" |
| 1342 |
kms_key_id: alias/{{ kms_alias }} |
| 1343 |
access_key: "{{ no_kms_assumed_role.sts_creds.access_key }}" |
| 1344 |
secret_key: "{{ no_kms_assumed_role.sts_creds.secret_key }}" |
| 1345 |
session_token: "{{ no_kms_assumed_role.sts_creds.session_token }}" |
| 1346 |
check_mode: true |
| 1347 |
register: output |
| 1348 |
- ansible.builtin.assert: |
| 1349 |
that: |
| 1350 |
- output is changed |
| 1351 |
# when using check_mode, with no kms permissions, and not giving kms_key_id as a key arn |
| 1352 |
# output will always be marked as changed. |
| 1353 |
|
| 1354 |
- name: Disable logging encryption (CHECK MODE) |
| 1355 |
amazon.aws.cloudtrail: |
| 1356 |
state: present |
| 1357 |
name: "{{ cloudtrail_name }}" |
| 1358 |
kms_key_id: "" |
| 1359 |
register: output |
| 1360 |
check_mode: true |
| 1361 |
- ansible.builtin.assert: |
| 1362 |
that: |
| 1363 |
- output is changed |
| 1364 |
|
| 1365 |
- name: Disable logging encryption |
| 1366 |
amazon.aws.cloudtrail: |
| 1367 |
state: present |
| 1368 |
name: "{{ cloudtrail_name }}" |
| 1369 |
kms_key_id: "" |
| 1370 |
register: output |
| 1371 |
- ansible.builtin.assert: |
| 1372 |
that: |
| 1373 |
- output.trail.kms_key_id == "" |
| 1374 |
- output is changed |
| 1375 |
|
| 1376 |
- name: Disable logging encryption (no change) |
| 1377 |
amazon.aws.cloudtrail: |
| 1378 |
state: present |
| 1379 |
name: "{{ cloudtrail_name }}" |
| 1380 |
kms_key_id: "" |
| 1381 |
register: output |
| 1382 |
- ansible.builtin.assert: |
| 1383 |
that: |
| 1384 |
- output.kms_key_id == "" |
| 1385 |
- output is not changed |
| 1386 |
|
| 1387 |
# ============================================================ |
| 1388 |
|
| 1389 |
- name: Delete a trail without providing bucket_name (CHECK MODE) |
| 1390 |
module_defaults: { amazon.aws.cloudtrail: {}} |
| 1391 |
amazon.aws.cloudtrail: |
| 1392 |
state: absent |
| 1393 |
name: "{{ cloudtrail_name }}" |
| 1394 |
register: output |
| 1395 |
check_mode: true |
| 1396 |
- ansible.builtin.assert: |
| 1397 |
that: |
| 1398 |
- output is changed |
| 1399 |
|
| 1400 |
- name: Delete a trail while providing bucket_name (CHECK MODE) |
| 1401 |
amazon.aws.cloudtrail: |
| 1402 |
state: absent |
| 1403 |
name: "{{ cloudtrail_name }}" |
| 1404 |
register: output |
| 1405 |
check_mode: true |
| 1406 |
- ansible.builtin.assert: |
| 1407 |
that: |
| 1408 |
- output is changed |
| 1409 |
|
| 1410 |
- name: Delete a trail |
| 1411 |
amazon.aws.cloudtrail: |
| 1412 |
state: absent |
| 1413 |
name: "{{ cloudtrail_name }}" |
| 1414 |
register: output |
| 1415 |
- ansible.builtin.assert: |
| 1416 |
that: |
| 1417 |
- output is changed |
| 1418 |
- output.exists == False |
| 1419 |
|
| 1420 |
- name: Delete a non-existent trail |
| 1421 |
amazon.aws.cloudtrail: |
| 1422 |
state: absent |
| 1423 |
name: "{{ cloudtrail_name }}" |
| 1424 |
register: output |
| 1425 |
- ansible.builtin.assert: |
| 1426 |
that: |
| 1427 |
- output is not changed |
| 1428 |
- output.exists == False |
| 1429 |
|
| 1430 |
# ============================================================ |
| 1431 |
|
| 1432 |
- name: Test creation of a complex Trail (all features) |
| 1433 |
amazon.aws.cloudtrail: |
| 1434 |
state: present |
| 1435 |
name: "{{ cloudtrail_name }}" |
| 1436 |
s3_key_prefix: "{{ cloudtrail_prefix }}" |
| 1437 |
sns_topic_name: "{{ sns_topic }}" |
| 1438 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group.arn }}" |
| 1439 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 1440 |
is_multi_region_trail: true |
| 1441 |
include_global_events: true |
| 1442 |
enable_log_file_validation: true |
| 1443 |
kms_key_id: "{{ kms_key.key_arn }}" |
| 1444 |
register: output |
| 1445 |
- ansible.builtin.assert: |
| 1446 |
that: |
| 1447 |
- output is changed |
| 1448 |
# - output.exists == True |
| 1449 |
- output.trail.name == cloudtrail_name |
| 1450 |
- output.trail.home_region == aws_region |
| 1451 |
- output.trail.include_global_service_events == True |
| 1452 |
- output.trail.is_multi_region_trail == True |
| 1453 |
- output.trail.is_logging == True |
| 1454 |
- output.trail.log_file_validation_enabled == True |
| 1455 |
- output.trail.s3_bucket_name == s3_bucket_name |
| 1456 |
- output.trail.s3_key_prefix == cloudtrail_prefix |
| 1457 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1458 |
- output.trail.sns_topic_arn == output_sns_topic.sns_arn |
| 1459 |
- output.trail.sns_topic_name == sns_topic |
| 1460 |
- output.trail.tags | length == 0 |
| 1461 |
|
| 1462 |
- name: Test creation of a complex Trail (no change) |
| 1463 |
amazon.aws.cloudtrail: |
| 1464 |
state: present |
| 1465 |
name: "{{ cloudtrail_name }}" |
| 1466 |
s3_key_prefix: "{{ cloudtrail_prefix }}" |
| 1467 |
sns_topic_name: "{{ sns_topic }}" |
| 1468 |
cloudwatch_logs_log_group_arn: "{{ output_cloudwatch_log_group.arn }}" |
| 1469 |
cloudwatch_logs_role_arn: "{{ output_cloudwatch_role.iam_role.arn }}" |
| 1470 |
is_multi_region_trail: true |
| 1471 |
include_global_events: true |
| 1472 |
enable_log_file_validation: true |
| 1473 |
kms_key_id: "{{ kms_key.key_arn }}" |
| 1474 |
register: output |
| 1475 |
- ansible.builtin.assert: |
| 1476 |
that: |
| 1477 |
- output is not changed |
| 1478 |
- output.exists == True |
| 1479 |
- output.trail.name == cloudtrail_name |
| 1480 |
- output.trail.home_region == aws_region |
| 1481 |
- output.trail.include_global_service_events == True |
| 1482 |
- output.trail.is_multi_region_trail == True |
| 1483 |
- output.trail.is_logging == True |
| 1484 |
- output.trail.log_file_validation_enabled == True |
| 1485 |
- output.trail.s3_bucket_name == s3_bucket_name |
| 1486 |
- output.trail.s3_key_prefix == cloudtrail_prefix |
| 1487 |
- output.trail.kms_key_id == kms_key.key_arn |
| 1488 |
- output.trail.sns_topic_arn == output_sns_topic.sns_arn |
| 1489 |
- output.trail.sns_topic_name == sns_topic |
| 1490 |
- output.trail.tags | length == 0 |
| 1491 |
|
| 1492 |
- name: Get the trail info of the created trail |
| 1493 |
amazon.aws.cloudtrail_info: |
| 1494 |
trail_names: |
| 1495 |
- "{{ trail_arn }}" |
| 1496 |
register: info |
| 1497 |
|
| 1498 |
- name: Assert that the logging key encryption is correctly updated |
| 1499 |
ansible.builtin.assert: |
| 1500 |
that: |
| 1501 |
- info.trail_list[0].name == cloudtrail_name |
| 1502 |
- info.trail_list[0].home_region == aws_region |
| 1503 |
- info.trail_list[0].include_global_service_events == True |
| 1504 |
- info.trail_list[0].is_multi_region_trail == True |
| 1505 |
- info.trail_list[0].is_logging == True |
| 1506 |
- info.trail_list[0].log_file_validation_enabled == True |
| 1507 |
- info.trail_list[0].s3_bucket_name == s3_bucket_name |
| 1508 |
- info.trail_list[0].s3_key_prefix == cloudtrail_prefix |
| 1509 |
- info.trail_list[0].kms_key_id == kms_key.key_arn |
| 1510 |
- info.trail_list[0].sns_topic_arn == output_sns_topic.sns_arn |
| 1511 |
- info.trail_list[0].sns_topic_name == sns_topic |
| 1512 |
- info.trail_list[0].tags | length == 0 |
| 1513 |
|
| 1514 |
always: |
| 1515 |
# ============================================================ |
| 1516 |
# Cleanup |
| 1517 |
# ============================================================ |
| 1518 |
- name: Delete test trail |
| 1519 |
amazon.aws.cloudtrail: |
| 1520 |
state: absent |
| 1521 |
name: "{{ cloudtrail_name }}" |
| 1522 |
ignore_errors: true |
| 1523 |
- name: Delete S3 bucket |
| 1524 |
amazon.aws.s3_bucket: |
| 1525 |
state: absent |
| 1526 |
name: "{{ s3_bucket_name }}" |
| 1527 |
force: true |
| 1528 |
ignore_errors: true |
| 1529 |
- name: Delete second S3 bucket |
| 1530 |
amazon.aws.s3_bucket: |
| 1531 |
state: absent |
| 1532 |
name: "{{ s3_bucket_name }}-2" |
| 1533 |
force: true |
| 1534 |
ignore_errors: true |
| 1535 |
- name: Delete KMS Key |
| 1536 |
amazon.aws.kms_key: |
| 1537 |
state: absent |
| 1538 |
alias: "{{ kms_alias }}" |
| 1539 |
ignore_errors: true |
| 1540 |
- name: Delete second KMS Key |
| 1541 |
amazon.aws.kms_key: |
| 1542 |
state: absent |
| 1543 |
alias: "{{ kms_alias }}-2" |
| 1544 |
ignore_errors: true |
| 1545 |
- name: Delete SNS Topic |
| 1546 |
community.aws.sns_topic: |
| 1547 |
state: absent |
| 1548 |
name: "{{ sns_topic }}" |
| 1549 |
ignore_errors: true |
| 1550 |
- name: Delete second SNS Topic |
| 1551 |
community.aws.sns_topic: |
| 1552 |
state: absent |
| 1553 |
name: "{{ sns_topic }}-2" |
| 1554 |
ignore_errors: true |
| 1555 |
- name: Delete CloudWatch Log Group |
| 1556 |
amazon.aws.cloudwatchlogs_log_group: |
| 1557 |
state: absent |
| 1558 |
log_group_name: "{{ cloudwatch_log_group }}" |
| 1559 |
ignore_errors: true |
| 1560 |
- name: Delete second CloudWatch Log Group |
| 1561 |
amazon.aws.cloudwatchlogs_log_group: |
| 1562 |
state: absent |
| 1563 |
log_group_name: "{{ cloudwatch_log_group }}-2" |
| 1564 |
ignore_errors: true |
| 1565 |
- name: Remove inline policy to CloudWatch Role |
| 1566 |
amazon.aws.iam_policy: |
| 1567 |
state: absent |
| 1568 |
iam_type: role |
| 1569 |
iam_name: "{{ cloudwatch_role }}" |
| 1570 |
policy_name: CloudWatch |
| 1571 |
ignore_errors: true |
| 1572 |
- name: Delete CloudWatch IAM Role |
| 1573 |
amazon.aws.iam_role: |
| 1574 |
state: absent |
| 1575 |
name: "{{ cloudwatch_role }}" |
| 1576 |
ignore_errors: true |
| 1577 |
- name: Remove inline policy to CloudWatch Role |
| 1578 |
amazon.aws.iam_policy: |
| 1579 |
state: absent |
| 1580 |
iam_type: role |
| 1581 |
iam_name: "{{ cloudwatch_no_kms_role }}" |
| 1582 |
policy_name: CloudWatchNokms |
| 1583 |
ignore_errors: true |
| 1584 |
- name: Delete CloudWatch No KMS IAM Role |
| 1585 |
amazon.aws.iam_role: |
| 1586 |
state: absent |
| 1587 |
name: "{{ cloudwatch_no_kms_role }}" |
| 1588 |
ignore_errors: true |