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 abikouo committed Oct 14, 2024
1 parent 8c3d2f5 commit d3cdb9f
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions tests/integration/targets/ec2_vpc_egress_igw/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
- name: ec2_vpc_egress_igw tests
- name: 'ec2_vpc_egress_igw 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:

# ============================================================
Expand All @@ -17,22 +22,11 @@
- 'result.failed'
- 'result.msg == "missing required arguments: vpc_id"'

# ============================================================
- 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: test failure with non-existent VPC ID
ec2_vpc_egress_igw:
state: present
vpc_id: vpc-012345678
<<: *aws_connection_info
register: result
ignore_errors: true

Expand All @@ -49,7 +43,6 @@
name: "{{ resource_prefix }}-vpc"
state: present
cidr_block: "10.232.232.128/26"
<<: *aws_connection_info
tags:
Name: "{{ resource_prefix }}-vpc"
Description: "Created by ansible-test"
Expand All @@ -60,7 +53,6 @@
ec2_vpc_egress_igw:
state: present
vpc_id: "{{ vpc_result.vpc.id }}"
<<: *aws_connection_info
register: vpc_eigw_create

- name: assert creation happened (expected changed=true)
Expand All @@ -75,7 +67,6 @@
ec2_vpc_egress_igw:
state: present
vpc_id: "{{ vpc_result.vpc.id }}"
<<: *aws_connection_info
register: vpc_eigw_recreate

- name: assert recreation did nothing (expected changed=false)
Expand All @@ -90,7 +81,6 @@
ec2_vpc_egress_igw:
state: absent
vpc_id: "{{ vpc_result.vpc.id }}"
<<: *aws_connection_info
register: vpc_eigw_delete

- name: assert state=absent (expected changed=true)
Expand All @@ -104,13 +94,11 @@
ec2_vpc_egress_igw:
state: absent
vpc_id: "{{ vpc_result.vpc.id }}"
<<: *aws_connection_info
ignore_errors: true

- name: tidy up VPC
ec2_vpc_net:
name: "{{ resource_prefix }}-vpc"
state: absent
cidr_block: "10.232.232.128/26"
<<: *aws_connection_info
ignore_errors: true

0 comments on commit d3cdb9f

Please sign in to comment.