Skip to content

Commit

Permalink
instance: add vpc2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Mar 9, 2024
1 parent d3dae8b commit e953813
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
17 changes: 16 additions & 1 deletion plugins/modules/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
)

Expand Down Expand Up @@ -552,6 +564,7 @@ def main():
"sshkey_id",
"backups",
"attach_vpc",
"attach_vpc2",
"user_scheme",
],
resource_update_param_keys=[
Expand All @@ -564,6 +577,8 @@ def main():
"user_data",
"attach_vpc",
"detach_vpc",
"attach_vpc2",
"detach_vpc2",
],
resource_key_name="label",
)
Expand Down
22 changes: 16 additions & 6 deletions tests/integration/targets/instance/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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= [email protected]"

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
Expand Down Expand Up @@ -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"
3 changes: 3 additions & 0 deletions tests/integration/targets/instance/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
- ansible.builtin.import_role:
name: cleanup
tasks_from: cleanup_vpc
- ansible.builtin.import_role:
name: cleanup
tasks_from: cleanup_vpc2
6 changes: 6 additions & 0 deletions tests/integration/targets/instance/tasks/present.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/targets/instance/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit e953813

Please sign in to comment.