e71c6d8e17
New module: ec2_instance Integration tests for ec2_instance
78 lines
2 KiB
YAML
78 lines
2 KiB
YAML
- name: set connection information for all tasks
|
|
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: true
|
|
# Make custom ENIs and attach via the `network` parameter
|
|
- ec2_eni:
|
|
delete_on_termination: true
|
|
subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
|
security_groups:
|
|
- "{{ sg.group_id }}"
|
|
<<: *aws_connection_info
|
|
register: eni_a
|
|
- ec2_eni:
|
|
delete_on_termination: true
|
|
subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
|
security_groups:
|
|
- "{{ sg.group_id }}"
|
|
<<: *aws_connection_info
|
|
register: eni_b
|
|
|
|
- name: Make instance in the testing subnet created in the test VPC
|
|
ec2_instance:
|
|
name: "{{ resource_prefix }}-test-eni-vpc"
|
|
network:
|
|
interfaces:
|
|
- id: "{{ eni_a.interface.id }}"
|
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
|
availability_zone: '{{ aws_region }}b'
|
|
tags:
|
|
TestId: "{{ resource_prefix }}"
|
|
instance_type: t2.micro
|
|
<<: *aws_connection_info
|
|
register: in_test_vpc
|
|
|
|
- name: Add a second interface
|
|
ec2_instance:
|
|
name: "{{ resource_prefix }}-test-eni-vpc"
|
|
network:
|
|
interfaces:
|
|
- id: "{{ eni_a.interface.id }}"
|
|
- id: "{{ eni_b.interface.id }}"
|
|
image_id: "{{ ec2_ami_image[aws_region] }}"
|
|
tags:
|
|
TestId: "{{ resource_prefix }}"
|
|
instance_type: t2.micro
|
|
<<: *aws_connection_info
|
|
|
|
- name: Terminate instance
|
|
ec2_instance:
|
|
filters:
|
|
tag:TestId: "{{ resource_prefix }}"
|
|
state: absent
|
|
<<: *aws_connection_info
|
|
register: result
|
|
- assert:
|
|
that: result.changed
|
|
|
|
- name: Terminate instance
|
|
ec2_instance:
|
|
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
|
state: absent
|
|
<<: *aws_connection_info
|
|
register: result
|
|
- assert:
|
|
that: not result.changed
|
|
|
|
|
|
- ec2_eni:
|
|
eni_id: "{{ item }}"
|
|
state: absent
|
|
<<: *aws_connection_info
|
|
with_items:
|
|
- "{{ eni_a.interface.id }}"
|
|
- "{{ eni_b.interface.id }}"
|