sullivtr / terraform-provider-graphql

Terraform GraphQL plugin to automate the full life-cycle of graphql api resources.
https://sullivtr.github.io/terraform-provider-graphql
Mozilla Public License 2.0
53 stars 13 forks source link

Support non-string computed keys #96

Closed dlecocq closed 1 month ago

dlecocq commented 7 months ago

Dealing with an API with return values that are non-string scalars, and I need to be able to consume them as part of this provider. Specifically, an API with an id that is getting returned as a number, which is causing this trace:

goroutine 14 [running]:
github.com/sullivtr/terraform-provider-graphql/graphql.computeMutationVariableKeys(0xc0001c4200, 0x1762dcf)
    github.com/sullivtr/terraform-provider-graphql/graphql/keys.go:36 +0x18a
github.com/sullivtr/terraform-provider-graphql/graphql.computeMutationVariables({0xc0001c4200, 0x31, 0x200}, 0x1663040)
    github.com/sullivtr/terraform-provider-graphql/graphql/resource_graphql_mutation.go:327 +0x186
github.com/sullivtr/terraform-provider-graphql/graphql.executeCreateHook({0x184c568, 0xc000054ea0}, 0x0, {0x16473e0, 0xc00009ff60})
    github.com/sullivtr/terraform-provider-graphql/graphql/resource_graphql_mutation.go:273 +0x29f
github.com/sullivtr/terraform-provider-graphql/graphql.resourceGraphqlMutationCreate({0x184c568, 0xc000054ea0}, 0xc0005597b8, {0x16473e0, 0xc00009ff60})
    github.com/sullivtr/terraform-provider-graphql/graphql/resource_graphql_mutation.go:128 +0x45
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0000b8380, {0x184c4f8, 0xc0002842c0}, 0x2, {0x16473e0, 0xc00009ff60})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.0/helper/schema/resource.go:330 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0000b8380, {0x184c4f8, 0xc0002842c0}, 0xc0003362a0, 0xc00009e700, {0x16473e0, 0xc00009ff60})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.0/helper/schema/resource.go:456 +0x871
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0000a6780, {0x184c4f8, 0xc0002842c0}, 0xc000312500)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.0/helper/schema/grpc_provider.go:955 +0x9aa
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc00009efc0, {0x184c5a0, 0xc0004a6270}, 0x101732b)
    github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/server/server.go:332 +0x6c
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1729e00, 0xc00009efc0}, {0x184c5a0, 0xc0004a6270}, 0xc000054660, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000ce700, {0x1858df0, 0xc00019c480}, 0xc0000b2300, 0xc0004226c0, 0x1ce1c60, 0x0)
    google.golang.org/grpc@v1.32.0/server.go:1194 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc0000ce700, {0x1858df0, 0xc00019c480}, 0xc0000b2300, 0x0)
    google.golang.org/grpc@v1.32.0/server.go:1517 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.32.0/server.go:859 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.32.0/server.go:857 +0x294

Error: The terraform-provider-graphql_2.5.4 plugin crashed!
dlecocq commented 7 months ago

I'm trying to run the tests locally, but the makefile isn't working for me (yet). In the meantime, I'm pushing this MR hoping that either 1) automated tests kick off or 2) it's quick enough for someone with a working environment to run the tests to verify.

dlecocq commented 7 months ago

Ah, was able to get the tests working well enough locally to demonstrate that the tests fail without the fix commit, and pass with it.

elixxx commented 2 months ago

Hey, i hitting an issue where a nested mutation_variables makes some issue. Is this fix solving such a issue?

sullivtr commented 1 month ago

Thank you, @dlecocq. I have not have any capacity to maintain this provider the past year or so so I appreciate the contribution. This should help a lot.

sullivtr commented 1 month ago

@dlecocq This will be tagged as v2.5.5 which is being released right now. It should be available soon.