-
Notifications
You must be signed in to change notification settings - Fork 769
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
[BUG]: github_rest_api Data Source returns null values for body and headers #2109
Comments
Hey @srgustafson8 thanks for tracking this down. Let us know if you'd be interested in fixing the issue and submitting a PR. For now I have labeled this as "Up For Grabs" so that the community can take a stab at getting this fixed as well. ❤️ |
Hi @nickfloyd - way ahead of you 😉 submitted #2110 earlier |
💥 Awesome. Thank you so much! We'll have a look! ❤ |
@srgustafson8 shouldn't this be Looks like the test could also be expanded to test for some or actual value instead of only presence. I fail to get the tests run locally Update: I think I solved it: #2152 |
Expected Behavior
I am looking to use the
github_rest_api
data source to get information about the rate limit of the authenticated user/app. I would expect that given;I would get:
Actual Behavior
Instead the result shows partially, but the body and headers attributes are null.
This is partially replicated with other API calls, for example, changing the endpoint to
repos/integrations/terraform-provider-github/git/refs/heads/main
returns:Partially managing to decode the body, but failing to decode the headers. This is also unstable, with changes to what manages to get decoded differing each time you run an apply.
Deduction Time
Attempting to debug this, I recreated the data resource locally to run:
Which would run without error, but the resourceData fields for body and headers would not be populated, following the behaviour of the data source.
Purely by accident, I also tried this same code with the v2 of the plugin sdk schema module, which throws errors:
So I then tried to use the 6.0.0-alpha version of the provider which utilises the v2 sdk, and got the following:
My final diagnosis is that the error stems from the fact that the
body
andheaders
attributes are givenschema.TypeMap
, which I assume Terraform defaults to assuming means map[string]string, and all map elements must be the same type. The GitHub API calls return a variety of schemas with mostly differing types which can't be normalised. This never showed up when using the v1 sdk as the error seems to be never generated or swallowed.Proposed Fix
I don't think it would be possible to come up with a schema type that allows for the variety of API responses that can be returned. I believe this resource should be changed to return
body
andheaders
as a (JSON) string, and users can usejsondecode()
to get to the underlying values returned, with knowledge of the API call they are making and it's schema.I'm happy to make these changes if no-one else wants to pick them up.
Terraform Version
Terraform v1.5.7
on darwin_arm64
Affected Resource(s)
Terraform Configuration Files
No response
Steps to Reproduce
No response
Debug Output
No response
Panic Output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: