goauthentik / terraform-provider-authentik

Manage https://goauthentik.io with terraform.
https://registry.terraform.io/providers/goauthentik/authentik/latest/docs
GNU General Public License v3.0
58 stars 16 forks source link

authentik_token has a plugin issue #521

Closed jonathanfinley closed 3 weeks ago

jonathanfinley commented 3 weeks ago

I've tried to deploy a token after upgrading to 2024.4.X using both 2024.4.1 and 2024.4.2 provider versions.

My Terraform using modules to provision certain applications and this is the last piece left to finalize the module. It seems related to this: https://github.com/goauthentik/terraform-provider-authentik/issues/507 Any help would be greatly appreciated. The odd part is the token DOES get created.

Authentik Version: 2024.4.2 Terraform/OpenTofu: Latest

resource "authentik_user" "this" {
  username   = "service.${replace(lower("${var.slug}ldap"), "/[^a-z0-9]/", "")}"
  name       = "Service User used by ${title(var.name)} to authenticate against LDAP server"
  path       = "users/ldap"
  groups     = try(var.search_group != null ? [var.search_group] : [], null)
  depends_on = [authentik_application.this]
}

resource "authentik_token" "this" {
  identifier   = "ldap-app-password-${replace(lower("${var.slug}"), "/[^a-z0-9]/", "")}"
  user         = authentik_user.this.id
  intent       = "app_password"
  description  = "Password used by ${title(var.name)} to authenticate using LDAP"
  expiring     = false
  retrieve_key = true
  depends_on   = [authentik_user.this]
}

I keep getting the following error:

module.authentik.module.server01.module.ldap["My_APP"].authentik_token.this: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with module.authentik.module.server01.module.ldap["My_APP"].authentik_token.this,
│   on templates/authentik/provider/ldap/main.tf line 57, in resource "authentik_token" "this":
│   57: resource "authentik_token" "this" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
Stack trace from the terraform-provider-authentik_v2024.4.1 plugin:

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

goroutine 116 [running]:
goauthentik.io/terraform-provider-authentik/internal/provider.resourceTokenRead({0x16732c0, 0xc00023ce70}, 0xc00063ab00, {0x120cb60?, 0xc0000ac678})
    goauthentik.io/terraform-provider-authentik/internal/provider/resource_token.go:125 +0x2dc
goauthentik.io/terraform-provider-authentik/internal/provider.resourceTokenCreate({0x16732c0, 0xc00023ce70}, 0x14caedc?, {0x120cb60?, 0xc0000ac678?})
    goauthentik.io/terraform-provider-authentik/internal/provider/resource_token.go:109 +0x134
goauthentik.io/terraform-provider-authentik/internal/provider.tr.func1({0x16732c0, 0xc00023ce70}, 0x0?, {0x120cb60, 0xc0000ac678})
    goauthentik.io/terraform-provider-authentik/internal/provider/tracing.go:18 +0x15f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc00030fb20, {0x1673218, 0xc0007c0750}, 0xd?, {0x120cb60, 0xc0000ac678})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:778 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00030fb20, {0x1673218, 0xc0007c0750}, 0xc000614ea0, 0xc00063a980, {0x120cb60, 0xc0000ac678})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:909 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000175770, {0x1673218?, 0xc0007c0660?}, 0xc0007a9360)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:1078 +0xdbc
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000450280, {0x1673218?, 0xc0007b1c50?}, 0xc00023c3f0)
    github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/tf5server/server.go:846 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1446c80?, 0xc000450280}, {0x1673218, 0xc0007b1c50}, 0xc0001cde00, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000201400, {0x1673218, 0xc0007b1bc0}, {0x16777a0, 0xc000603040}, 0xc0007ad7a0, 0xc0002e7fb0, 0x2008838, 0x0)
    google.golang.org/grpc@v1.61.1/server.go:1385 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc000201400, {0x16777a0, 0xc000603040}, 0xc0007ad7a0)
    google.golang.org/grpc@v1.61.1/server.go:1796 +0xfec
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.61.1/server.go:1029 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 84
    google.golang.org/grpc@v1.61.1/server.go:1040 +0x135

Error: The terraform-provider-authentik_v2024.4.1 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.
rissson commented 3 weeks ago

Already fixed by https://github.com/goauthentik/terraform-provider-authentik/pull/517. Will be released along with 2024.6