paybyphone / terraform-provider-phpipam

Terraform provider plugin for PHPIPAM (https://phpipam.net/)
Other
13 stars 24 forks source link

How to use with multiple resources / VMs #7

Open rsjorslev opened 6 years ago

rsjorslev commented 6 years ago

How would I use this to get first free address for a resource im provisioning eg. 5 times?

My use case is provisioning 5 vSphere VMs cloned from a template and get 5 free addresses.

Im currently doing this:

resource "vsphere_virtual_machine" "vm" {
  count            = 3
...

and I have tried:

resource "phpipam_address" "ip" {
  count = 3
...

but that results in 3 resources with the same IP from phpIPAM.

thanks

pinacoelho commented 6 years ago

Looks like the provider is using find_first_free instead of reserve_first_free. Since find_first_free doesn't mark the addresses, it returns the same IP for all calls.

jordips commented 4 years ago

Hi, I'm surprised that only one person is requesting this feature. Has anybody find a way to use "count" to get X free different IPs? Is this the desired beaviour when you are using "phpipam_first_free_address" ?

Thanks!

jordips commented 4 years ago

Hi, I tried to develop a new datasource cloning "data_source_phpipam_first_free_address". What I do in this datasource is the same but executing "CreateAddress" at the end to make sure IP is allocated. Then, I add "count=N" in tf file, calling datasource cloned.

Problem: "count" terraform process are executed in parallel, so N procs request IP at the same time.

If I executed:

terraform apply -parallelism=1

I can get and "reserve" N ips, but is not a solution.

Problem here (as @pinacoelho said) is that IPAM has no method to get and reserve free IP in the same API Call.

pinacoelho commented 4 years ago

Hi @jordips ,

A couple of years back, I had to fork the terraform provider and the go sdk to be able to run parallel tasks. I haven't kept up with terraform, nor PHPIPAM, but maybe you'll get enough there.

TL;DR - Added a ReserveFirstFree to the terraform plugin and the sdk.

https://github.com/pinacoelho/terraform-provider-phpipam https://github.com/pinacoelho/phpipam-sdk-go

jordips commented 4 years ago

Oohh god...I didn't realized POST method "addresses/first_free/{subnetid}" in https://phpipam.net/api/api_documentation 👎

Many thanks @pinacoelho, that's the way I wanted to do it.