1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/ec2_vpc_egress_igw/tasks/main.yml
Daniel Shepherd 892fc41190 [cloud] New module: Amazon Egress-Only Internet Gateway (ec2_vpc_egress_igw) (#23941)
* New module: ec2_vpc_egress_igw

* minor pep8 fix and doc update

* add test dir and files

* add tests for gateway module

* fix up return documentation per review

* remove HAS_BOTO3 stuff as it is handled in AnsibleAWSModule per review

* fix an error with failure message and add custom handler for non-existent vpc ID

* add additional tests and update tests per review

* ignore errors on clean up tasks

* update module copyright to newer format

* fix exception handling since BotoCoreError doesnt have response attribute

* actually fix exception handling this time so it works with Py3 as well
2018-01-26 09:22:30 -05:00

112 lines
3.4 KiB
YAML

---
- block:
# ============================================================
- name: test failure with no parameters
ec2_vpc_egress_igw:
register: result
ignore_errors: true
- name: assert failure with no parameters
assert:
that:
- '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
- name: assert failure with non-existent VPC ID
assert:
that:
- 'result.failed'
- 'result.error.code == "InvalidVpcID.NotFound"'
- '"invalid vpc ID" in result.msg'
# ============================================================
- name: create a VPC
ec2_vpc_net:
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"
register: vpc_result
# ============================================================
- name: create egress-only internet gateway (expected changed=true)
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)
assert:
that:
- 'vpc_eigw_create'
- 'vpc_eigw_create.gateway_id.startswith("eigw-")'
- 'vpc_eigw_create.vpc_id == vpc_result.vpc.id'
# ============================================================
- name: attempt to recreate egress-only internet gateway on VPC (expected changed=false)
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)
assert:
that:
- 'vpc_eigw_recreate.changed == False'
- 'vpc_eigw_recreate.gateway_id == vpc_eigw_create.gateway_id'
- 'vpc_eigw_recreate.vpc_id == vpc_eigw_create.vpc_id'
# ============================================================
- name: test state=absent (expected changed=true)
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)
assert:
that:
- 'vpc_eigw_delete.changed'
always:
# ============================================================
- name: tidy up EIGW
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