lord-kyron / terraform-provider-phpipam

Terrform provider for PHPIPAM
https://registry.terraform.io/providers/lord-kyron/phpipam/latest
Apache License 2.0
54 stars 30 forks source link

Error: Subnet either missing or multiple results returned by reading subnet after creation #43

Closed MrKoopaKiller closed 2 years ago

MrKoopaKiller commented 2 years ago

Affected resource phpipam_subnet resource

Issue:

The phpIPAM allow us to disable the strict mode per section and also allow us to create more than one subnet using the same cidr in diferente sections. That being said, if we try to create 2 subnets with the same CIDR but in different sections, it should work, but in fact, it's not working and terraform throws an error:

Error: Subnet either missing or multiple results returned by reading subnet after creation

Seems the main reason is by this function that tries to retry if the subnet was correctly create querying by CIDR:

https://github.com/lord-kyron/terraform-provider-phpipam/blob/1dd3754c3e2e91fb343f6289774620b3f0f6c1a3/vendor/github.com/lord-kyron/phpipam-sdk-go/controllers/subnets/subnets.go#L120-L123

But since we have more than 1 result, it throws the error:

https://github.com/lord-kyron/terraform-provider-phpipam/blob/1dd3754c3e2e91fb343f6289774620b3f0f6c1a3/plugin/providers/phpipam/resource_phpipam_subnet.go#L62-L64

Use case: Just to give a quick explanation why I'm using this in that way. I have multiples AWS accounts, and I'm putting all the vpc and subnets from all this accounts and all regions in the phpIPAM. AWS regions has the default vpc, using the same CIDR and it causes the error. If for some reason the subnets weren't correctly architect and an overlap occurs, is it possible to face the same error even if the strict mode is disabled in the phpIPAM.

Expected Behavior Be able to create subnets using the same CIDR.

lord-kyron commented 2 years ago

@pavel-z1 - is it possible to fix this one easily?

pavel-z1 commented 2 years ago

Hi @MrKoopaKiller I've updated phpipam-sdk and this provider to allow search CIDR in the specific section during subnet creation.

Check this feature in your environment

MrKoopaKiller commented 2 years ago

Thanks @pavel-z1! I'll test the changes soon!

@lord-kyron Do you think is it possible to create a new tag including the latest commits?

lord-kyron commented 2 years ago

@MrKoopaKiller I will prepare new tag and new release build tomorrow!

MrKoopaKiller commented 2 years ago

Ping @lord-kyron 🙏

lord-kyron commented 2 years ago

@MrKoopaKiller published with the latest release!