2017-11-16 19:09:42 +01:00
|
|
|
---
|
2019-09-06 00:56:54 +02:00
|
|
|
- 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:
|
|
|
|
|
|
|
|
- name: list available AZs
|
|
|
|
aws_az_info:
|
|
|
|
register: region_azs
|
|
|
|
|
|
|
|
- name: pick an AZ for testing
|
2018-04-03 21:25:00 +02:00
|
|
|
set_fact:
|
2019-09-06 00:56:54 +02:00
|
|
|
subnet_az: "{{ region_azs.availability_zones[0].zone_name }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
# ============================================================
|
|
|
|
- name: create a VPC
|
|
|
|
ec2_vpc_net:
|
|
|
|
name: "{{ resource_prefix }}-vpc"
|
|
|
|
state: present
|
|
|
|
cidr_block: "10.232.232.128/26"
|
2019-09-11 01:25:36 +02:00
|
|
|
ipv6_cidr: True
|
2017-11-16 19:09:42 +01:00
|
|
|
tags:
|
|
|
|
Name: "{{ resource_prefix }}-vpc"
|
|
|
|
Description: "Created by ansible-test"
|
|
|
|
register: vpc_result
|
|
|
|
|
2019-09-11 01:25:36 +02:00
|
|
|
- set_fact:
|
|
|
|
vpc_ipv6_cidr: "{{ vpc_result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}"
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: create subnet (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_create
|
|
|
|
|
|
|
|
- name: assert creation would happen
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_create is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
- name: create subnet (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2017-11-16 19:09:42 +01:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
register: vpc_subnet_create
|
|
|
|
|
|
|
|
- name: assert creation happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'vpc_subnet_create'
|
|
|
|
- 'vpc_subnet_create.subnet.id.startswith("subnet-")'
|
|
|
|
- '"Name" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
|
|
|
|
- '"Description" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: recreate subnet (expected changed=false) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_recreate
|
|
|
|
|
|
|
|
- name: assert recreation changed nothing (expected changed=false)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_recreate is not changed
|
2017-11-16 19:09:42 +01:00
|
|
|
|
|
|
|
- name: recreate subnet (expected changed=false)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2017-11-16 19:09:42 +01:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
register: vpc_subnet_recreate
|
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: assert recreation changed nothing (expected changed=false)
|
2017-11-16 19:09:42 +01:00
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_recreate is not changed
|
2017-11-16 20:58:12 +01:00
|
|
|
- 'vpc_subnet_recreate.subnet == vpc_subnet_create.subnet'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: update subnet so instances launched in it are assigned an IP (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
map_public: true
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_modify
|
|
|
|
|
|
|
|
- name: assert subnet changed
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_modify is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
|
|
|
- name: update subnet so instances launched in it are assigned an IP
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
map_public: true
|
|
|
|
register: vpc_subnet_modify
|
|
|
|
|
|
|
|
- name: assert subnet changed
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_modify is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
- vpc_subnet_modify.subnet.map_public_ip_on_launch
|
|
|
|
|
|
|
|
# ============================================================
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: add invalid ipv6 block to subnet (expected failed)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2017-11-16 20:58:12 +01:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: 2001:db8::/64
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
register: vpc_subnet_ipv6_failed
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: assert failure happened (expected failed)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_ipv6_failed is failed
|
2017-11-16 20:58:12 +01:00
|
|
|
- "'Couldn\\'t associate ipv6 cidr' in vpc_subnet_ipv6_failed.msg"
|
2017-11-16 19:09:42 +01:00
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: add a tag (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
AnotherTag: SomeValue
|
|
|
|
state: present
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_add_a_tag
|
|
|
|
|
|
|
|
- name: assert tag addition happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_add_a_tag is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
- name: add a tag (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2017-11-16 19:09:42 +01:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
AnotherTag: SomeValue
|
|
|
|
state: present
|
|
|
|
register: vpc_subnet_add_a_tag
|
|
|
|
|
|
|
|
- name: assert tag addition happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_add_a_tag is changed
|
2017-11-16 19:09:42 +01:00
|
|
|
- '"Name" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Name"] == ec2_vpc_subnet_name'
|
|
|
|
- '"Description" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Description"] == ec2_vpc_subnet_description'
|
|
|
|
- '"AnotherTag" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["AnotherTag"] == "SomeValue"'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: remove tags with default purge_tags=true (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
AnotherTag: SomeValue
|
|
|
|
state: present
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_remove_tags
|
|
|
|
|
|
|
|
- name: assert tag removal happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_remove_tags is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: remove tags with default purge_tags=true (expected changed=true)
|
2017-11-16 19:09:42 +01:00
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2017-11-16 19:09:42 +01:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
AnotherTag: SomeValue
|
|
|
|
state: present
|
|
|
|
register: vpc_subnet_remove_tags
|
|
|
|
|
|
|
|
- name: assert tag removal happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_remove_tags is changed
|
2017-11-16 19:09:42 +01:00
|
|
|
- '"Name" not in vpc_subnet_remove_tags.subnet.tags'
|
|
|
|
- '"Description" not in vpc_subnet_remove_tags.subnet.tags'
|
|
|
|
- '"AnotherTag" in vpc_subnet_remove_tags.subnet.tags and vpc_subnet_remove_tags.subnet.tags["AnotherTag"] == "SomeValue"'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: change tags with purge_tags=false (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2018-04-03 21:25:00 +02:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_change_tags
|
|
|
|
|
|
|
|
- name: assert tag addition happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_change_tags is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: change tags with purge_tags=false (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
2019-09-06 00:56:54 +02:00
|
|
|
az: "{{ subnet_az }}"
|
2017-11-16 20:58:12 +01:00
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
register: vpc_subnet_change_tags
|
|
|
|
|
|
|
|
- name: assert tag addition happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_change_tags is changed
|
2017-11-16 20:58:12 +01:00
|
|
|
- '"Name" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Name"] == ec2_vpc_subnet_name'
|
|
|
|
- '"Description" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Description"] == ec2_vpc_subnet_description'
|
|
|
|
- '"AnotherTag" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["AnotherTag"] == "SomeValue"'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test state=absent (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
check_mode: true
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- result is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
- name: test state=absent (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- result is changed
|
2017-11-16 19:09:42 +01:00
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test state=absent (expected changed=false) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
check_mode: true
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent (expected changed=false)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- result is not changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
|
|
|
- name: test state=absent (expected changed=false)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent (expected changed=false)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- result is not changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: create subnet without AZ (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
check_mode: true
|
|
|
|
register: subnet_without_az
|
|
|
|
|
|
|
|
- name: check that subnet without AZ works fine
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- subnet_without_az is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
- name: create subnet without AZ
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
register: subnet_without_az
|
|
|
|
|
|
|
|
- name: check that subnet without AZ works fine
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- subnet_without_az is changed
|
2017-11-16 19:09:42 +01:00
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: remove subnet without AZ (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
check_mode: true
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- result is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
- name: remove subnet without AZ
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- result is changed
|
2017-11-16 20:58:12 +01:00
|
|
|
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: create subnet with IPv6 (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
assign_instances_ipv6: true
|
|
|
|
state: present
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_ipv6_create
|
|
|
|
|
|
|
|
- name: assert creation with IPv6 happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_ipv6_create is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: create subnet with IPv6 (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
assign_instances_ipv6: true
|
|
|
|
state: present
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
register: vpc_subnet_ipv6_create
|
|
|
|
|
|
|
|
- name: assert creation with IPv6 happened (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_ipv6_create is changed
|
2017-11-16 20:58:12 +01:00
|
|
|
- 'vpc_subnet_ipv6_create.subnet.id.startswith("subnet-")'
|
|
|
|
- "vpc_subnet_ipv6_create.subnet.ipv6_cidr_block == '{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}'"
|
|
|
|
- '"Name" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
|
|
|
|
- '"Description" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
|
|
|
|
- 'vpc_subnet_ipv6_create.subnet.assign_ipv6_address_on_creation'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: recreate subnet (expected changed=false) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
assign_instances_ipv6: true
|
|
|
|
state: present
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_ipv6_recreate
|
|
|
|
|
|
|
|
- name: assert recreation changed nothing (expected changed=false)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_ipv6_recreate is not changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: recreate subnet (expected changed=false)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
assign_instances_ipv6: true
|
|
|
|
state: present
|
|
|
|
tags:
|
|
|
|
Name: '{{ec2_vpc_subnet_name}}'
|
|
|
|
Description: '{{ec2_vpc_subnet_description}}'
|
|
|
|
register: vpc_subnet_ipv6_recreate
|
|
|
|
|
|
|
|
- name: assert recreation changed nothing (expected changed=false)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_ipv6_recreate is not changed
|
2017-11-16 20:58:12 +01:00
|
|
|
- 'vpc_subnet_ipv6_recreate.subnet == vpc_subnet_ipv6_create.subnet'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: change subnet ipv6 attribute (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
assign_instances_ipv6: false
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_change_attribute
|
|
|
|
|
|
|
|
- name: assert assign_instances_ipv6 attribute changed (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_change_attribute is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: change subnet ipv6 attribute (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
assign_instances_ipv6: false
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
register: vpc_change_attribute
|
|
|
|
|
|
|
|
- name: assert assign_instances_ipv6 attribute changed (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_change_attribute is changed
|
2017-11-16 20:58:12 +01:00
|
|
|
- 'not vpc_change_attribute.subnet.assign_ipv6_address_on_creation'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: add second subnet with duplicate ipv6 cidr (expected failure)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.144/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
register: vpc_add_duplicate_ipv6
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert graceful failure (expected failed)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_add_duplicate_ipv6 is failed
|
2017-11-16 20:58:12 +01:00
|
|
|
- "'The IPv6 CIDR \\'{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}\\' conflicts with another subnet' in vpc_add_duplicate_ipv6.msg"
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: remove subnet ipv6 cidr (expected changed=true) (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_remove_ipv6_cidr
|
|
|
|
|
|
|
|
- name: assert subnet ipv6 cidr removed (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_remove_ipv6_cidr is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 20:58:12 +01:00
|
|
|
- name: remove subnet ipv6 cidr (expected changed=true)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
register: vpc_remove_ipv6_cidr
|
|
|
|
|
|
|
|
- name: assert subnet ipv6 cidr removed (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_remove_ipv6_cidr is changed
|
2017-11-16 20:58:12 +01:00
|
|
|
- "vpc_remove_ipv6_cidr.subnet.ipv6_cidr_block == ''"
|
|
|
|
- 'not vpc_remove_ipv6_cidr.subnet.assign_ipv6_address_on_creation'
|
|
|
|
|
2018-04-03 21:25:00 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test adding a tag that looks like a boolean to the subnet (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
tags:
|
|
|
|
looks_like_boolean: true
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_info
|
|
|
|
|
|
|
|
- name: assert a tag was added
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_info is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
|
|
|
- name: test adding a tag that looks like a boolean to the subnet
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
tags:
|
|
|
|
looks_like_boolean: true
|
|
|
|
register: vpc_subnet_info
|
|
|
|
|
|
|
|
- name: assert a tag was added
|
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_info is changed
|
2018-04-03 21:25:00 +02:00
|
|
|
- 'vpc_subnet_info.subnet.tags.looks_like_boolean == "True"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test idempotence adding a tag that looks like a boolean (CHECK MODE)
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
tags:
|
|
|
|
looks_like_boolean: true
|
|
|
|
check_mode: true
|
|
|
|
register: vpc_subnet_info
|
|
|
|
|
2019-09-06 00:56:54 +02:00
|
|
|
- name: assert tags haven't changed
|
2018-04-03 21:25:00 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_info is not changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
|
|
|
- name: test idempotence adding a tag that looks like a boolean
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
purge_tags: false
|
|
|
|
tags:
|
|
|
|
looks_like_boolean: true
|
|
|
|
register: vpc_subnet_info
|
|
|
|
|
2019-09-06 00:56:54 +02:00
|
|
|
- name: assert tags haven't changed
|
2018-04-03 21:25:00 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2019-09-06 00:56:54 +02:00
|
|
|
- vpc_subnet_info is not changed
|
2018-04-03 21:25:00 +02:00
|
|
|
|
2017-11-16 19:09:42 +01:00
|
|
|
always:
|
|
|
|
|
|
|
|
################################################
|
|
|
|
# TEARDOWN STARTS HERE
|
|
|
|
################################################
|
|
|
|
|
|
|
|
- name: tidy up subnet
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
cidr: "10.232.232.128/28"
|
|
|
|
vpc_id: "{{ vpc_result.vpc.id }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: tidy up VPC
|
|
|
|
ec2_vpc_net:
|
|
|
|
name: "{{ resource_prefix }}-vpc"
|
|
|
|
state: absent
|
|
|
|
cidr_block: "10.232.232.128/26"
|