- 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
- name: Make instance in a default subnet of the VPC
  ec2_instance:
    name: "{{ resource_prefix }}-test-default-vpc"
    image_id: "{{ ec2_ami_image[aws_region] }}"
    tags:
      TestId: "{{ resource_prefix }}"
    security_groups: "{{ sg.group_id }}"
    instance_type: t2.micro
    <<: *aws_connection_info
  register: in_default_vpc
- name: Terminate instance
  ec2:
    instance_ids: "{{ in_default_vpc.instance_ids }}"
    state: absent
    <<: *aws_connection_info