diff --git a/changelogs/fragments/instance_vpc2.yml b/changelogs/fragments/instance_vpc2.yml new file mode 100644 index 0000000..2522f21 --- /dev/null +++ b/changelogs/fragments/instance_vpc2.yml @@ -0,0 +1,2 @@ +minor_changes: + - instance - Implemented ``vpc2`` support (https://github.com/vultr/ansible-collection-vultr/pull/118). diff --git a/plugins/modules/instance.py b/plugins/modules/instance.py index 7eca359..4eab9ac 100644 --- a/plugins/modules/instance.py +++ b/plugins/modules/instance.py @@ -117,9 +117,17 @@ vpcs: description: - A list of VPCs identified by their description to be assigned to the instance. + - Mutually exclusive with I(vpc2s). type: list elements: str version_added: "1.5.0" + vpc2s: + description: + - A list of VPCs (VPC 2.0) identified by their description to be assigned to the bare metal machine. + - Mutually exclusive with I(vpcs). + type: list + elements: str + version_added: "1.13.0" state: description: - State of the instance. @@ -420,6 +428,37 @@ returned: success type: str sample: "5a:01:04:3d:5e:72" + vpc2s: + description: List of VPC2s attached. + returned: success + type: list + version_added: "1.13.0" + contains: + id: + description: ID of the VPC. + returned: success + type: str + sample: 5536d2a4-66fd-4dfb-b839-7672fd5bc116 + description: + description: Description of the VPC. + returned: success + type: str + sample: my vpc + ip_address: + description: IP assigned from the VPC. + returned: success + type: str + sample: "192.168.23.3" + mac_address: + description: MAC address of the network interface. + returned: success + type: str + sample: "5a:01:04:3d:5e:72" + node_status: + description: Node status network interface. + returned: success + type: str + sample: "active" """ @@ -498,6 +537,7 @@ def main(): enable_ipv6=dict(type="bool"), tags=dict(type="list", elements="str"), vpcs=dict(type="list", elements="str"), + vpc2s=dict(type="list", elements="str"), reserved_ipv4=dict(type="str"), firewall_group=dict(type="str"), startup_script=dict(type="str"), @@ -522,7 +562,10 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, required_if=(("state", "present", ("plan",)),), - mutually_exclusive=(("os", "app", "image", "snapshot"),), + mutually_exclusive=( + ("os", "app", "image", "snapshot"), + ("vpcs", "vpc2s"), + ), supports_check_mode=True, ) @@ -552,6 +595,7 @@ def main(): "sshkey_id", "backups", "attach_vpc", + "attach_vpc2", "user_scheme", ], resource_update_param_keys=[ @@ -564,6 +608,8 @@ def main(): "user_data", "attach_vpc", "detach_vpc", + "attach_vpc2", + "detach_vpc2", ], resource_key_name="label", ) diff --git a/tests/integration/targets/instance/defaults/main.yml b/tests/integration/targets/instance/defaults/main.yml index d280132..86448f2 100644 --- a/tests/integration/targets/instance/defaults/main.yml +++ b/tests/integration/targets/instance/defaults/main.yml @@ -5,6 +5,16 @@ vultr_instance_firewall_group: "{{ vultr_resource_prefix }}_instance_fw_group" vultr_instance_ssh_key_name: "{{ vultr_resource_prefix }}_instance_sshkey" vultr_instance_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= ansible@example.com" +vutr_instance_vpc2s: + - description: "{{ vultr_resource_prefix }}_instance_vpc2_1" + ip_block: 192.168.22.0 + prefix_length: 24 + region: ams + - description: "{{ vultr_resource_prefix }}_instance_vpc2_2" + ip_block: 192.168.99.0 + prefix_length: 24 + region: ams + vutr_instance_vpcs: - description: "{{ vultr_resource_prefix }}_instance_vpc_1" v4_subnet: 192.168.24.0 @@ -91,9 +101,8 @@ vultr_instances: enable_ipv6: true # API does not disable IPv6 once enabled. enable_ipv6_update: true - vpcs: - - "{{ vultr_resource_prefix }}_instance_vpc_1" - - "{{ vultr_resource_prefix }}_instance_vpc_2" - vpcs_update: - - "{{ vultr_resource_prefix }}_instance_vpc_1" - - "{{ vultr_resource_prefix }}_instance_vpc_3" + vpc2s: + - "{{ vultr_resource_prefix }}_instance_vpc2_1" + vpc2s_update: + - "{{ vultr_resource_prefix }}_instance_vpc2_1" + - "{{ vultr_resource_prefix }}_instance_vpc2_2" diff --git a/tests/integration/targets/instance/tasks/main.yml b/tests/integration/targets/instance/tasks/main.yml index 3a1fba6..d4a37c5 100644 --- a/tests/integration/targets/instance/tasks/main.yml +++ b/tests/integration/targets/instance/tasks/main.yml @@ -14,3 +14,6 @@ - ansible.builtin.import_role: name: cleanup tasks_from: cleanup_vpc + - ansible.builtin.import_role: + name: cleanup + tasks_from: cleanup_vpc2 diff --git a/tests/integration/targets/instance/tasks/present.yml b/tests/integration/targets/instance/tasks/present.yml index b82e122..2618a9f 100644 --- a/tests/integration/targets/instance/tasks/present.yml +++ b/tests/integration/targets/instance/tasks/present.yml @@ -21,6 +21,7 @@ image: "{{ instance.image | default(omit) }}" snapshot: "{{ instance.snapshot | default(omit) }}" vpcs: "{{ instance.vpcs | default(omit) }}" + vpc2s: "{{ instance.vpc2s | default(omit) }}" register: result check_mode: true - name: verify test create instance in check mode @@ -46,6 +47,7 @@ image: "{{ instance.image | default(omit) }}" snapshot: "{{ instance.snapshot | default(omit) }}" vpcs: "{{ instance.vpcs | default(omit) }}" + vpc2s: "{{ instance.vpc2s | default(omit) }}" user_scheme: "{{ instance.user_scheme | default(omit) }}" register: result - name: verify test create instance @@ -57,9 +59,8 @@ # - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'" - result.vultr_instance.ddos_protection == instance.ddos_protection - result.vultr_instance.enable_ipv6 == instance.enable_ipv6 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_1') | list | count == 1 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_2') | list | count == 1 - - result.vultr_instance.vpcs | list | count == 2 + - result.vultr_instance.vpcs | list | count == (instance.vpcs | default([])) | list | count + - result.vultr_instance.vpc2s | list | count == (instance.vpc2s | default([])) | list | count - result.vultr_instance.user_scheme == instance.user_scheme | default('root') - name: test create instance idempotence @@ -80,6 +81,7 @@ image: "{{ instance.image | default(omit) }}" snapshot: "{{ instance.snapshot | default(omit) }}" vpcs: "{{ instance.vpcs | default(omit) }}" + vpc2s: "{{ instance.vpc2s | default(omit) }}" user_scheme: "{{ instance.user_scheme | default(omit) }}" register: result - name: verify test create instance idempotence @@ -91,9 +93,8 @@ # - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'" - result.vultr_instance.ddos_protection == instance.ddos_protection - result.vultr_instance.enable_ipv6 == instance.enable_ipv6 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_1') | list | count == 1 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_2') | list | count == 1 - - result.vultr_instance.vpcs | list | count == 2 + - result.vultr_instance.vpcs | list | count == (instance.vpcs | default([])) | list | count + - result.vultr_instance.vpc2s | list | count == (instance.vpc2s | default([])) | list | count - result.vultr_instance.user_scheme == instance.user_scheme | default('root') - name: test update instance in check mode @@ -114,6 +115,7 @@ image: "{{ instance.image | default(omit) }}" snapshot: "{{ instance.snapshot | default(omit) }}" vpcs: "{{ instance.vpcs_update | default(omit) }}" + vpc2s: "{{ instance.vpc2s_update | default(omit) }}" user_scheme: "{{ instance.user_scheme | default(omit) }}" register: result check_mode: true @@ -126,9 +128,8 @@ # - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'" - result.vultr_instance.ddos_protection == instance.ddos_protection - result.vultr_instance.enable_ipv6 == instance.enable_ipv6 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_1') | list | count == 1 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_2') | list | count == 1 - - result.vultr_instance.vpcs | list | count == 2 + - result.vultr_instance.vpcs | list | count == (instance.vpcs | default([])) | list | count + - result.vultr_instance.vpc2s | list | count == (instance.vpc2s | default([])) | list | count - result.vultr_instance.user_scheme == instance.user_scheme | default('root') - name: test update instance @@ -149,6 +150,7 @@ image: "{{ instance.image | default(omit) }}" snapshot: "{{ instance.snapshot | default(omit) }}" vpcs: "{{ instance.vpcs_update | default(omit) }}" + vpc2s: "{{ instance.vpc2s_update | default(omit) }}" user_scheme: "{{ instance.user_scheme | default(omit) }}" register: result - name: verify test update instance @@ -160,9 +162,8 @@ # - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'" - result.vultr_instance.ddos_protection == instance.ddos_protection_update - result.vultr_instance.enable_ipv6 == instance.enable_ipv6_update - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_1') | list | count == 1 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_3') | list | count == 1 - - result.vultr_instance.vpcs | list | count == 2 + - result.vultr_instance.vpcs | list | count == (instance.vpcs_update | default([])) | list | count + - result.vultr_instance.vpc2s | list | count == (instance.vpc2s_update | default([])) | list | count - result.vultr_instance.user_scheme == instance.user_scheme | default('root') - name: test update instance idempotence @@ -183,6 +184,7 @@ image: "{{ instance.image | default(omit) }}" snapshot: "{{ instance.snapshot | default(omit) }}" vpcs: "{{ instance.vpcs_update | default(omit) }}" + vpc2s: "{{ instance.vpc2s_update | default(omit) }}" user_scheme: "{{ instance.user_scheme | default(omit) }}" register: result - name: verify test update instance idempotence @@ -194,7 +196,6 @@ # - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'" - result.vultr_instance.ddos_protection == instance.ddos_protection_update - result.vultr_instance.enable_ipv6 == instance.enable_ipv6_update - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_1') | list | count == 1 - - result.vultr_instance.vpcs | selectattr('description','equalto',vultr_resource_prefix ~ '_instance_vpc_3') | list | count == 1 - - result.vultr_instance.vpcs | list | count == 2 + - result.vultr_instance.vpcs | list | count == (instance.vpcs_update | default([])) | list | count + - result.vultr_instance.vpc2s | list | count == (instance.vpc2s_update | default([])) | list | count - result.vultr_instance.user_scheme == instance.user_scheme | default('root') diff --git a/tests/integration/targets/instance/tasks/tests.yml b/tests/integration/targets/instance/tasks/tests.yml index 877ca3d..d4cab22 100644 --- a/tests/integration/targets/instance/tasks/tests.yml +++ b/tests/integration/targets/instance/tasks/tests.yml @@ -29,6 +29,14 @@ region: "{{ item.region }}" with_items: "{{ vutr_instance_vpcs }}" +- name: setup vpc2s + vultr.cloud.vpc2: + description: "{{ item.description }}" + ip_block: "{{ item.ip_block }}" + prefix_length: "{{ item.prefix_length }}" + region: "{{ item.region }}" + with_items: "{{ vutr_instance_vpc2s }}" + - ansible.builtin.include_tasks: present.yml with_items: "{{ vultr_instances }}" loop_control: @@ -68,3 +76,14 @@ delay: 3 register: result until: result is not failed + +- name: cleanup vpc2s + vultr.cloud.vpc2: + description: "{{ item.description }}" + region: "{{ item.region }}" + state: absent + with_items: "{{ vutr_instance_vpc2s }}" + retries: 20 + delay: 3 + register: result + until: result is not failed