Skip to content

Commit

Permalink
Move tests to using module_defaults (ansible-collections#368)
Browse files Browse the repository at this point in the history
* Bulk migration to module_defaults
* Tests for missing creds/region
* Move dms_identifier and dms_sg_identifier into defaults

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@365b6ef
  • Loading branch information
tremble authored and goneri committed Sep 21, 2022
1 parent 7842232 commit b8f4c35
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 208 deletions.
10 changes: 10 additions & 0 deletions tests/integration/targets/rds_instance/tasks/credential_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
- name: test without credentials
rds_instance:
db_instance_identifier: test-rds-instance
region: '{{ omit }}'
aws_access_key: '{{ omit }}'
aws_secret_key: '{{ omit }}'
security_token: '{{ omit }}'
register: result
ignore_errors: yes

Expand All @@ -14,6 +18,9 @@
rds_instance:
db_instance_identifier: test-rds-instance
region: us-east-1
aws_access_key: '{{ omit }}'
aws_secret_key: '{{ omit }}'
security_token: '{{ omit }}'
register: result
ignore_errors: yes

Expand All @@ -27,6 +34,9 @@
db_instance_identifier: test-rds-instance
region: us-east-1
profile: doesnotexist
aws_access_key: '{{ omit }}'
aws_secret_key: '{{ omit }}'
security_token: '{{ omit }}'
register: result
ignore_errors: yes

Expand Down
12 changes: 10 additions & 2 deletions tests/integration/targets/rds_instance/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
---
- block:

- name: 'rds_instance integration tests'
collections:
- amazon.aws
module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:
- include: ./credential_tests.yml
tags: credentials
- include: ./test_states.yml
Expand Down
18 changes: 0 additions & 18 deletions tests/integration/targets/rds_instance/tasks/test_aurora.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
---
- block:
- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes

- name: Ensure the resource doesn't exist
rds_instance:
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -29,7 +20,6 @@
cluster_id: "{{ cluster_id }}"
username: "{{ username }}"
password: "{{ password }}"
<<: *aws_connection_info

- name: Create an Aurora instance
rds_instance:
Expand All @@ -40,7 +30,6 @@
db_instance_class: "{{ aurora_db_instance_class }}"
tags:
CreatedBy: rds_instance integration tests
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -55,7 +44,6 @@
state: present
tags:
Test: rds_instance
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -68,7 +56,6 @@
rds_instance:
id: "{{ instance_id }}"
state: present
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -82,7 +69,6 @@
password: "{{ password }}"
force_update_password: True
apply_immediately: True
<<: *aws_connection_info
register: result
ignore_errors: yes

Expand All @@ -97,7 +83,6 @@
id: "{{ instance_id }}"
state: present
port: 1150
<<: *aws_connection_info
register: result
ignore_errors: yes

Expand All @@ -114,7 +99,6 @@
purge_tags: False
new_id: "{{ modified_instance_id }}"
apply_immediately: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -129,7 +113,6 @@
id: "{{ item }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
loop:
- "{{ instance_id }}"
- "{{ modified_instance_id }}"
Expand All @@ -140,5 +123,4 @@
cluster_id: "{{ cluster_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
ignore_errors: yes
10 changes: 0 additions & 10 deletions tests/integration/targets/rds_instance/tasks/test_bad_options.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
---
- block:
- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes

- name: Ensure the resource doesn't exist
rds_instance:
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -31,7 +22,6 @@
password: "{{ password }}"
db_instance_class: "{{ db_instance_class }}"
allocated_storage: "{{ allocated_storage }}"
<<: *aws_connection_info
register: result
ignore_errors: True

Expand Down
11 changes: 0 additions & 11 deletions tests/integration/targets/rds_instance/tasks/test_encryption.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
---
- block:
- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes

- name: Ensure the resource doesn't exist
rds_instance:
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -32,7 +23,6 @@
db_instance_class: "{{ storage_encrypted_db_instance_class }}"
allocated_storage: "{{ allocated_storage }}"
storage_encrypted: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -49,5 +39,4 @@
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
---
- block:
- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes

- name: Ensure the resource doesn't exist
rds_instance:
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -31,15 +22,13 @@
password: "{{ password }}"
db_instance_class: "{{ db_instance_class }}"
allocated_storage: "{{ allocated_storage }}"
<<: *aws_connection_info
register: result

- name: Delete the DB instance
rds_instance:
id: "{{ instance_id }}"
state: absent
final_snapshot_identifier: "{{ instance_id }}"
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -50,7 +39,6 @@
- name: Check that snapshot exists
rds_snapshot_info:
db_snapshot_identifier: "{{ instance_id }}"
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -63,13 +51,11 @@
rds_snapshot:
db_snapshot_identifier: "{{ instance_id }}"
state: absent
<<: *aws_connection_info
ignore_errors: yes

- name: Remove the DB instance
rds_instance:
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
ignore_errors: yes
19 changes: 0 additions & 19 deletions tests/integration/targets/rds_instance/tasks/test_modification.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
---
- block:
- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes

- name: Ensure the resource doesn't exist
rds_instance:
id: "{{ instance_id }}"
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -32,7 +23,6 @@
password: "{{ password }}"
db_instance_class: "{{ db_instance_class }}"
allocated_storage: "{{ allocated_storage }}"
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -46,7 +36,6 @@
state: present
new_id: "{{ modified_instance_id }}"
apply_immediately: False
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -60,7 +49,6 @@
state: present
new_id: "{{ modified_instance_id }}"
apply_immediately: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -74,7 +62,6 @@
state: present
new_id: '{{ instance_id }}'
apply_immediately: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -89,7 +76,6 @@
password: '{{ password }}'
force_update_password: True
apply_immediately: True
<<: *aws_connection_info
register: result
check_mode: True

Expand All @@ -104,7 +90,6 @@
password: '{{ password }}'
force_update_password: True
apply_immediately: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -129,7 +114,6 @@
port: 1150
max_allocated_storage: 100
apply_immediately: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -155,7 +139,6 @@
auto_minor_version_upgrade: false
port: 1150
max_allocated_storage: 100
<<: *aws_connection_info
register: result
retries: 30
delay: 10
Expand All @@ -175,7 +158,6 @@
id: '{{ instance_id }}'
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
register: result

- assert:
Expand All @@ -190,6 +172,5 @@
id: '{{ item }}'
state: absent
skip_final_snapshot: True
<<: *aws_connection_info
loop: ['{{ instance_id }}', '{{ modified_instance_id }}']
ignore_errors: yes
Loading

0 comments on commit b8f4c35

Please sign in to comment.