From e953813f85ed8777a64ed3720b822f46f7233a39 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sat, 9 Mar 2024 22:47:29 +0100 Subject: [PATCH] instance: add vpc2 support --- plugins/modules/instance.py | 17 +++++++++++++- .../targets/instance/defaults/main.yml | 22 ++++++++++++++----- .../targets/instance/tasks/main.yml | 3 +++ .../targets/instance/tasks/present.yml | 6 +++++ .../targets/instance/tasks/tests.yml | 19 ++++++++++++++++ 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/plugins/modules/instance.py b/plugins/modules/instance.py index 7eca359..f2b6854 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. @@ -498,6 +506,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 +531,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 +564,7 @@ def main(): "sshkey_id", "backups", "attach_vpc", + "attach_vpc2", "user_scheme", ], resource_update_param_keys=[ @@ -564,6 +577,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..871a19c 100644 --- a/tests/integration/targets/instance/defaults/main.yml +++ b/tests/integration/targets/instance/defaults/main.yml @@ -5,6 +5,17 @@ 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 +102,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..1d63006 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 @@ -80,6 +82,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 @@ -114,6 +117,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 @@ -149,6 +153,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 @@ -183,6 +188,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 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