RunVariable in `/runs` request payload is not marshalled as expected
Description
Release https://github.com/hashicorp/go-tfe/releases/tag/v0.21.0 added the ability to pass run variable to workspaces' run.
Expected behaviour
As for official documentation, the expected payload should be something like:
"attributes": {
"variables": [
{ "key": "replicas", "value": "2" },
{ "key": "access_key", "value": "\"ABCDE12345\"" }
]
}
Actual behaviour
"variables": [
{
"Key": "version",
"Value": "\"dummy\""
}
]
The case of Key and Value does not seem to be respected.
Hello, I'm sorry to hear that run variables are not behaving as you expected. Do you mean that go-tfe is capitalizing Key and Value unnecessarily? If you can clarify what you mean I can update the documentation to be more clear.
I do think run variables are behaving as expected. Here is some test code I used to test run variables:
package main
import (
"context"
"github.com/hashicorp/go-tfe"
)
func main() {
client, err := tfe.NewClient(&tfe.Config{
Address: "https://app.terraform.io",
Token: "TEST_TOKEN",
})
if err != nil {
panic(err)
}
client.Runs.Create(context.Background(), tfe.RunCreateOptions{
Workspace: &tfe.Workspace{
ID: "ws-MY_WORKSPACE_ID",
},
Variables: []*tfe.RunVariable{
{
Key: "foo",
Value: "\"bar\"",
},
},
})
}
Let me know how I can help troubleshoot!
Hello Brandon, I am sorry not have explained clearly enough.
Do you mean that go-tfe is capitalizing Key and Value unnecessarily?
This is exactly what I meant. The payload is marshalled ignoring the jsonapi meta tag definition of the struct.
It's also worth mentioning that our Terraform enterprise (we are on version v202203-1) is responding to requests successfully, so it seems that the case is insensitive on the Terraform enterprise API server side.
I wasn't able to find any reference to JSON payload sensitiveness in the API reference, for this reason I decided to open the issue to let maintainers of this repository aware: while the client is working as expected as it is, it's not guaranteed that a "fix" on the server side wouldn't break it.
I personally think that it would be better for the client to honour the contract of the provider, as it is described by the reference documentation.
Please let me know if I can help you any further :)
I confirmed that the jsonapi meta tag is being ignored and the request body is incorrect. Thanks for bringing this to our attention
This was fixed in release v1.11.0