| 1 |
--- |
| 2 |
- module_defaults: |
| 3 |
group/aws: |
| 4 |
access_key: "{{ aws_access_key }}" |
| 5 |
secret_key: "{{ aws_secret_key }}" |
| 6 |
session_token: "{{ security_token | default(omit) }}" |
| 7 |
region: "{{ aws_region }}" |
| 8 |
|
| 9 |
block: |
| 10 |
- name: Run tests for testing json input_template |
| 11 |
ansible.builtin.import_tasks: test_json_input_template.yml |
| 12 |
|
| 13 |
- name: Create SNS topic |
| 14 |
community.aws.sns_topic: |
| 15 |
name: TestSNSTopic |
| 16 |
state: present |
| 17 |
display_name: Test SNS Topic |
| 18 |
register: sns_topic_output |
| 19 |
|
| 20 |
- name: Create classic cloudwatch event rules |
| 21 |
amazon.aws.cloudwatchevent_rule: |
| 22 |
name: "{{ item }}" |
| 23 |
description: Rule for {{ item }} |
| 24 |
state: present |
| 25 |
schedule_expression: cron(0 20 * * ? *) |
| 26 |
targets: |
| 27 |
- id: "{{ sns_topic_output.sns_topic.name }}" |
| 28 |
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" |
| 29 |
register: event_rules_classic_output |
| 30 |
loop: "{{ test_event_names }}" |
| 31 |
|
| 32 |
- name: Assert that classic event rules were created |
| 33 |
ansible.builtin.assert: |
| 34 |
that: |
| 35 |
- event_rules_classic_output.changed |
| 36 |
- event_rules_classic_output.msg == "All items completed" |
| 37 |
|
| 38 |
- name: Create cloudwatch event rule with input transformer |
| 39 |
amazon.aws.cloudwatchevent_rule: |
| 40 |
name: "{{ input_transformer_event_name }}" |
| 41 |
description: Event rule with input transformer configuration |
| 42 |
state: present |
| 43 |
event_pattern: '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["pending"]}}' |
| 44 |
targets: |
| 45 |
- id: "{{ sns_topic_output.sns_topic.name }}" |
| 46 |
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" |
| 47 |
input_transformer: |
| 48 |
input_paths_map: |
| 49 |
instance: $.detail.instance-id |
| 50 |
state: $.detail.state |
| 51 |
input_template: <instance> is in state <state> |
| 52 |
register: event_rule_input_transformer_output |
| 53 |
|
| 54 |
- name: Assert that input transformer event rule was created |
| 55 |
ansible.builtin.assert: |
| 56 |
that: |
| 57 |
- event_rule_input_transformer_output.changed |
| 58 |
|
| 59 |
- name: Create cloudwatch event rule with input transformer (idempotent) |
| 60 |
amazon.aws.cloudwatchevent_rule: |
| 61 |
name: "{{ input_transformer_event_name }}" |
| 62 |
description: Event rule with input transformer configuration |
| 63 |
state: present |
| 64 |
event_pattern: '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["pending"]}}' |
| 65 |
targets: |
| 66 |
- id: "{{ sns_topic_output.sns_topic.name }}" |
| 67 |
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" |
| 68 |
input_transformer: |
| 69 |
input_paths_map: |
| 70 |
instance: $.detail.instance-id |
| 71 |
state: $.detail.state |
| 72 |
input_template: <instance> is in state <state> |
| 73 |
register: event_rule_input_transformer_output |
| 74 |
|
| 75 |
- name: Assert that no changes were made to the rule |
| 76 |
ansible.builtin.assert: |
| 77 |
that: |
| 78 |
- event_rule_input_transformer_output is not changed |
| 79 |
|
| 80 |
- name: Create cloudwatch event rule with inputs |
| 81 |
amazon.aws.cloudwatchevent_rule: |
| 82 |
name: "{{ input_event_name }}" |
| 83 |
description: Event rule with input configuration |
| 84 |
state: present |
| 85 |
event_pattern: '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["pending"]}}' |
| 86 |
targets: |
| 87 |
- id: "{{ sns_topic_output.sns_topic.name }}" |
| 88 |
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" |
| 89 |
input: Hello World |
| 90 |
- id: "{{ sns_topic_output.sns_topic.name }}2" |
| 91 |
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" |
| 92 |
input: |
| 93 |
start: Hello World |
| 94 |
end: Goodbye oh cruel World |
| 95 |
register: event_rule_input_transformer_output |
| 96 |
|
| 97 |
- name: Assert that input transformer event rule was created |
| 98 |
ansible.builtin.assert: |
| 99 |
that: |
| 100 |
- event_rule_input_transformer_output.changed |
| 101 |
|
| 102 |
always: |
| 103 |
- name: Delete classic CloudWatch event rules |
| 104 |
amazon.aws.cloudwatchevent_rule: |
| 105 |
name: "{{ item }}" |
| 106 |
state: absent |
| 107 |
loop: "{{ test_event_names }}" |
| 108 |
|
| 109 |
- name: Delete input transformer CloudWatch event rules |
| 110 |
amazon.aws.cloudwatchevent_rule: |
| 111 |
name: "{{ item }}" |
| 112 |
state: absent |
| 113 |
loop: |
| 114 |
- "{{ input_transformer_event_name }}" |
| 115 |
- "{{ input_event_name }}" |
| 116 |
|
| 117 |
- name: Delete SNS topic |
| 118 |
community.aws.sns_topic: |
| 119 |
name: TestSNSTopic |
| 120 |
state: absent |