vultr / ansible-collection-vultr

GNU General Public License v3.0
28 stars 17 forks source link

[Feature] - automatic private network set up with enable_vpc: true|false #94

Closed timdiggins closed 12 months ago

timdiggins commented 1 year ago

Is your feature request related to a problem? Please describe.

I'm migrating from old "vultr_server" (https://docs.ansible.com/ansible/2.8/modules/vultr_server_module.html) ansible (late to the party) and looking for an equivalent to private_network_enabled: true

This is mostly provided by api v2 enable_vpc or enable_vpc2 (https://www.vultr.com/api/#tag/instances/operation/create-instance)

Describe the solution you'd like

A simple way to setup default vpc on creating an instance and use enable_vpc or enable_vpc2 on the api

Describe alternatives you've considered

Manual set up of vpcs - however I just need one default vpc (seems like the simplest use case) and this is what the api provides

resmo commented 1 year ago

Hi @timdiggins

In terms of idempotency, enable_vpc/enable_vpc2 is tricky for the following reasons:

  1. users have no control over the IP subnet and CIDR
  2. if a user ever wants to have a 2nd VPC, it would no longer work

Therefore, our suggestion is to define a VPC as follows:


- name: Ensure a VPC is present
  vultr.cloud.vpc:
    description: default
    subnet: 10.99.1.0
    subnet_mask: 24
    region: ams

- name: Create an instance using OS
  vultr.cloud.instance:
    label: web1
    hostname: my-hostname
    os: Debian 12 x64 (bookworm)
    firewall_group: my firewall group
    plan: vc2-1c-2gb
    ssh_keys:
      - my ssh key
    vpcs:
      - default
    region: ams

Would this be an option?

P.s. As an inspiration, you might want to look at https://github.com/ngine-io/ansible-vultr-demo

timdiggins commented 1 year ago

@resmo - thanks that's very helpful!

I can see your points, and this does the same thing with better idempotency. But also by adapting the name to be specific to the cluster I'm setting up then have isolation between eg. staging and production clusters (and more straightforward destruction if needed - not sure if one should clean up the vpc for temporary clusters (e.g. staging), but i guess best practice)

timdiggins commented 1 year ago

(Closing this - useful to have around as docs)

timdiggins commented 1 year ago

@resmo sorry one more question: which parameters governs identity (and thus idempotency) in the vpc module? Is it description + region?

It might help to have some documentation of this in the vpc module. (particularly asdescription (rather than name) doesn't sound like a label for an identity parameter)

resmo commented 1 year ago

it's description (or name as it is an alias https://docs.ansible.com/ansible/latest/collections/vultr/cloud/vpc_module.html#parameter-description) only. But I see it would make sense to probably also take the region into account. This would allow to have similar "names" in many regions.

resmo commented 12 months ago

Closing this as #98 has been merged.