terraform-provider-phpipam icon indicating copy to clipboard operation
terraform-provider-phpipam copied to clipboard

showVLAN showVRF and showSupernetOnly became int in phpIPAM version 1.6.0

Open chavan-dinesh opened this issue 1 year ago • 9 comments

showVLAN showVRF and showSupernetOnly became int in phpIPAM version 1.6.0 causing provider to fail

│ Error: JSON parsing error: json: cannot unmarshal number into Go struct field Section.showVLAN of type string - Response data: [{"id":3,"name":"XXXX","description":"XXXX","masterSection":0,"permissions":"{\"2\":\"2\",\"3\":\"1\"}","strictMode":"1","subnetOrdering":"default","order":null,"editDate":"2024-06-10 18:52:52","showVLAN":1,"showVRF":1,"showSupernetOnly":1,"DNS":null,"showSubnet":1}]

Previous versions of phpIPAM were returning BoolIntString but latest version not doing so!

Same output from phpIPAM 1.4.5:

{"code":200,"success":true,"data":[{"id":"26","name":"XXXX","description":"XXXX","masterSection":"0","permissions":"[]","strictMode":"1","subnetOrdering":"default","order":null,"editDate":"2021-11-17 12:05:24","showVLAN":"1","showVRF":"1","showSupernetOnly":"1","DNS":null}],"time":0.004}

As you can see API call from 1.4.5 version returning showVLAN , showVRF and showSupernetOnly as BoolIntString. Not sure who should fix it either you from provider side or phpIPAM from API side :) But terraform provider is breaking due to this.

chavan-dinesh avatar Jun 10 '24 19:06 chavan-dinesh

I'm also having this issue.

Terraform v1.8.5
on linux_amd64
+ provider registry.terraform.io/lord-kyron/phpipam v1.6.2

Looks like we're waiting for a release to include this change https://github.com/phpipam/phpipam/issues/4043#issuecomment-2093611911 which should fix this issue @pavel-z1 ?

d-costa avatar Jun 11 '24 14:06 d-costa

Same issue here

Terraform v1.5.7
on darwin_arm64
+ provider registry.terraform.io/lord-kyron/phpipam v1.6.2

CapMousse avatar Jun 11 '24 14:06 CapMousse

@d-costa Similar issue https://github.com/lord-kyron/terraform-provider-phpipam/issues/84 already closed with comments as new release will have backward compatibility! Am using latest version of provider i.e. 1.6.2 (still facing issue) , Do we know what we should do for the backward compatibility ?

chavan-dinesh avatar Jun 11 '24 17:06 chavan-dinesh

Have a solution for this problem?

lucasdk3 avatar Jul 16 '24 19:07 lucasdk3

I think the problem is not in the terraform provider but in the database phpipam conversion script when installing version 1.6.0. In tinyint type fields, instead of having the value 0, there is now the value \u0000 which causes a problem for the terraform requests. The solution is to delete the entry in phpipam and recreate the entry with terraform (terraform put the value 0 back into fields) or simply make a modification to the entry in phpipam to reset the value to 0 in the tinyint type fields.

Marquis79 avatar Jul 25 '24 16:07 Marquis79

@pavel-z1 FYI

lord-kyron avatar Aug 06 '24 10:08 lord-kyron

I reproduced this issue. It is not related specifically to 1.6.0, but rather to php8 support (that is included with 1.6.0).

If you run 1.6.0 with php7, there is no issue. With php8+, the ints in the json response of the API are encoded as json ints, instead of string before. Here is an example of output for a sections resource

sdiff -s php8.json php7.json
"id": 3,						     |	     "id": "3",
      "masterSection": 0,				     |	     "masterSection": "0",
      "showSubnet": 1,					     |	     "showSubnet": "1",
      "showVLAN": 0,					     |	     "showVLAN": "0",
      "showVRF": 0,					     |	     "showVRF": "0",
      "showSupernetOnly": 0,				     |	     "showSupernetOnly": "0"

I guess the provider is expecting ints encoded as string ("showVLAN": "0"), like before with php7, instead of int: ( "showVLAN": 0), that causes the unmarshal error : Error: JSON parsing error: json: cannot unmarshal number into Go struct field Section.showVLAN of type string -

yeswexav avatar Aug 29 '24 20:08 yeswexav

Hi @chavan-dinesh @d-costa @CapMousse @lucasdk3 @Marquis79

This issue was discussed previously here https://github.com/lord-kyron/terraform-provider-phpipam/issues/84 PHPIPAM changed API fields format due to migration to PHP 8 without back compatibility

Back compatibility was added:

  • from PHPIPAM team side https://github.com/phpipam/phpipam/issues/4043
  • in this project https://github.com/lord-kyron/terraform-provider-phpipam/pull/90

Now, to make it all work, the PHPIPAM team needs to release a new version with this fix.

We have been expecting this action from the PHPIPAM team since May. You can additionally create a request to the PHPIPAM project https://github.com/phpipam/phpipam/issues to release new minor version with fix https://github.com/phpipam/phpipam/commit/11a5ea0bbbe67b12f6db57b03e08560bfe1f7d65

Till the new release of PHPIPAM will be created you can use workaround for PHPIPAM 1.6.0 discribed here https://github.com/lord-kyron/terraform-provider-phpipam/issues/84#issuecomment-1959896507

pavel-z1 avatar Sep 24 '24 07:09 pavel-z1

works fine for we now with phpipam release 1.7.3 and php8

yeswexav avatar Jan 28 '25 09:01 yeswexav