Unleash / terraform-provider-unleash

Terraform provider for unleash, the Open-source feature management solution
https://www.getunleash.io
Apache License 2.0
6 stars 1 forks source link

Not able to add a project to an api token #163

Open fdebuire opened 1 month ago

fdebuire commented 1 month ago

Describe the bug

Hello,

We are trying to add another project to an api token, here is what the plan looks like:

  # unleash_api_token.ax_frontend_token will be updated in-place
  ~ resource "unleash_api_token" "ax_frontend_token" {
      ~ project     = "ax-aut-routeco, xxx, xxx, ..." -> (known after apply)
      ~ projects    = [
          + "ax-auth_poc",
            # (15 unchanged elements hidden)
        ]
      ~ secret      = (sensitive value)
        # (4 unchanged attributes hidden)
    }

And we get this error:

╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to unleash_api_token.ax_client_token, provider "provider[\"registry.terraform.io/unleash/unleash\"]" produced an unexpected new value: .projects: planned set element
│ cty.StringVal("ax-auth_poc") does not correlate with any element in actual.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

To workaround this, we deleted the API token in the UI to then recreate it using Terraform and got this error:

╷
│ Error: Request cancelled
│
│ The plugin6.(*GRPCProvider).ReadResource request was cancelled.
╵
╷
│ Error: Request cancelled
│
│ The plugin6.(*GRPCProvider).ReadResource request was cancelled.
╵
╷
│ Error: Request cancelled
│
│ The plugin6.(*GRPCProvider).ReadResource request was cancelled.
╵
╷
│ Error: Request cancelled
│
│ The plugin6.(*GRPCProvider).ReadResource request was cancelled.
╵

Stack trace from the terraform-provider-unleash_v1.1.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1408665]

goroutine 127 [running]:
github.com/Unleash/terraform-provider-unleash/internal/provider.(*apiTokenResource).Read(0xc0002a0068, {0x1944038, 0xc000896c60}, {{{{0x19475c0, 0xc000613680}, {0x1737d00, 0xc0006131a0}}, {0x1948700, 0xc000136050}}, 0xc0002a0078, ...}, ...)
    github.com/Unleash/terraform-provider-unleash/internal/provider/api_token_resource.go:215 +0x325
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0xc00021d600, {0x1944038, 0xc000896c60}, 0xc000897020, 0xc0003635f8)
    github.com/hashicorp/terraform-plugin-framework@v1.4.2/internal/fwserver/server_readresource.go:101 +0x60e
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ReadResource(0xc00021d600, {0x1944038?, 0xc000896450?}, 0xc000815000)
    github.com/hashicorp/terraform-plugin-framework@v1.4.2/internal/proto6server/server_readresource.go:55 +0x27b
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0xc00023b220, {0x1944038?, 0xc00061bb00?}, 0xc0005ace40)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/tf6server/server.go:787 +0x49e
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x17f1200?, 0xc00023b220}, {0x1944038, 0xc00061bb00}, 0xc0001a6150, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:431 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0003201e0, {0x1947778, 0xc000294680}, 0xc0007a0900, 0xc0003f41b0, 0x1de3d68, 0x0)
    google.golang.org/grpc@v1.57.1/server.go:1358 +0xe13
google.golang.org/grpc.(*Server).handleStream(0xc0003201e0, {0x1947778, 0xc000294680}, 0xc0007a0900, 0x0)
    google.golang.org/grpc@v1.57.1/server.go:1735 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.57.1/server.go:970 +0xca
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.57.1/server.go:981 +0x15c

Error: The terraform-provider-unleash_v1.1.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Removing the api token from the Terraform state solved it, we were able to recreate it.

Steps to reproduce the bug

No response

Expected behavior

We are expecting to be able to add a project to an api token.

Logs, error output, etc.

No response

Screenshots

No response

Additional context

No response

Unleash version

v1.1.0

Subscription type

None

Hosting type

None

SDK information (language and version)

No response

ivarconr commented 1 month ago

Hi there, thanks for providing this.

API tokens in Unleash are mostly immutable. Its only the expiry data that can be updated after they are created.

The error produced is not very useful though, and the provider should handle this better.