Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unmarshal error of type []*string #32

Closed
pepito987 opened this Issue Jul 30, 2018 · 9 comments

Comments

Projects
None yet
2 participants
@pepito987
Copy link

pepito987 commented Jul 30, 2018

I'm using kong v0.10.2, I'm using apis as Resource and I'm facing an unmarshal error.
It looks like that if a list field like hosts is empty this will set to an actual empty object {}
rather than empty list [].

After running PATCH on an apis resources:
{ "hosts": [] }

The GET will return:
{ ..., "upstream_read_timeout": 60000, "upstream_send_timeout": 60000, "https_only": false, "hosts": {} }
As you can see hosts is not an empty list but an empty object and terraform throw this during the import:
could not find kong api: could not parse api get response, error: json: cannot unmarshal object into Go struct field Api.hosts of type []*string

Also, I have the same error during a plan.

Terraform Version

v0.11.0

Expected Behavior

be able to import a resource with empty hosts list

Actual Behavior

unmarshal error: could not find kong api: could not parse api get response, error: json: cannot unmarshal object into Go struct field Api.hosts of type []*string

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. run PATCH to an api resources with body { "hosts": [] }
  2. run import of the api: `terraform import module.proxy.kong_api.test-service e9da8a938-355b-4c69-ab26-2f507c688d02
@kevholditch

This comment has been minimized.

Copy link
Owner

kevholditch commented Jul 30, 2018

which version of the terraform provider are you using as I cannot reproduce this

@pepito987

This comment has been minimized.

Copy link
Author

pepito987 commented Jul 30, 2018

I'm using terraform-provider-kong_v1.5.0

@pepito987

This comment has been minimized.

Copy link
Author

pepito987 commented Jul 30, 2018

Are you still unable to reproduce the issue?
I'm also using kong v0.10.2. Did you try to set the hosts field so an actual value and setting it to empty later?

@kevholditch

This comment has been minimized.

Copy link
Owner

kevholditch commented Jul 30, 2018

ok I can reproduce this now. I tried to reproduce it directly in terraform by creating a resource with no hosts but kong seems to handle that ok. It seems to be when you patch with an empty hosts array that you see this. Will need to make a fix in gokong to handle this and pull that through into the terraform provider

@pepito987

This comment has been minimized.

Copy link
Author

pepito987 commented Jul 30, 2018

Thanks @kevholditch much appreciated. Is really weird for me that Kong marshal an empty list as empty object in the first place.

@kevholditch

This comment has been minimized.

Copy link
Owner

kevholditch commented Jul 30, 2018

@pepito987 it looks like if you use the terraform provider for everything then you are fine. Looks like a bug in kong that is caused by sending the payload {"hosts":[]}

@pepito987

This comment has been minimized.

Copy link
Author

pepito987 commented Jul 30, 2018

Well the issue in my case is that I'm importing existing resources which were managed manually via the web interface.
Also, you have the same issue during a plan. If you set host to empty after creating the api, you won't be able to run a plan, because you will receive the same error.
Is it possible to abstract the base model to work with Objects and do the casting later checking the type first? In that case if empty object then empty list.

@kevholditch

This comment has been minimized.

Copy link
Owner

kevholditch commented Jul 30, 2018

yeah but both of these issues are when you manually interface with the kong api yourself setting the hosts to an empty array outside of using terraform. I think I know how I can fix this

@pepito987

This comment has been minimized.

Copy link
Author

pepito987 commented Jul 30, 2018

I would be surprised if the following scenario would work atm:

  1. create api with hosts = ["example.com"] using terraform
  2. update api to host = [] using terraform
  3. run a terraform plan

I would expect the same error here

kevholditch added a commit that referenced this issue Jul 30, 2018

fixing the empty array bug in kong
empty array bug in kong is stopping any api with no hosts, uris or
methods set.  Fixes #32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.