Unable to import organisation #7

Closed
opened 2023-04-18 19:23:55 +00:00 by pim · 5 comments
Contributor

I am unable to import an organisation into Terraform.
Below is the log of the error.
I investigated it a bit and it seems the problem is the use of schema.ImportStatePassthrough. Apparently, if you use that feature, you can only use d.Id() when refreshing the state. See https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/import#importer-state-function.
In the resourceOrgRead function d.get(orgName) is used, so this fails.

gitea_org.home: Importing from ID "3"...
gitea_org.home: Import prepared!
  Prepared gitea_org for import
gitea_org.home: Refreshing state... [id=3]
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵


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

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

goroutine 54 [running]:
code.gitea.io/terraform-provider-gitea/gitea.resourceOrgRead(0xc00048ecc0?, {0xd53d80?, 0xc000134370})
	code.gitea.io/terraform-provider-gitea/gitea/resource_gitea_organisation.go:29 +0x72
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0003ff0e0, 0xc000274a00, {0xd53d80, 0xc000134370})
	github.com/hashicorp/terraform-plugin-sdk@v1.13.0/helper/schema/resource.go:460 +0x1aa
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc000012ba0, {0xc00042c300?, 0x5b5f66?}, 0xc00042c300)
	github.com/hashicorp/terraform-plugin-sdk@v1.13.0/internal/helper/plugin/grpc_provider.go:525 +0x365
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler({0xd2c5e0?, 0xc000012ba0}, {0xed97a8, 0xc0001fee70}, 0xc00042c2a0, 0x0)
	github.com/hashicorp/terraform-plugin-sdk@v1.13.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000002480, {0xedd060, 0xc0001d8000}, 0xc000154300, 0xc000097770, 0x13cc750, 0x0)
	google.golang.org/grpc@v1.27.1/server.go:1024 +0xd4f
google.golang.org/grpc.(*Server).handleStream(0xc000002480, {0xedd060, 0xc0001d8000}, 0xc000154300, 0x0)
	google.golang.org/grpc@v1.27.1/server.go:1313 +0xa25
google.golang.org/grpc.(*Server).serveStreams.func1.1()
	google.golang.org/grpc@v1.27.1/server.go:722 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.27.1/server.go:720 +0xea

Error: The terraform-provider-gitea_v0.1.0 plugin crashed!
I am unable to import an organisation into Terraform. Below is the log of the error. I investigated it a bit and it seems the problem is the use of `schema.ImportStatePassthrough`. Apparently, if you use that feature, you can only use `d.Id()` when refreshing the state. See https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/import#importer-state-function. In the `resourceOrgRead` function `d.get(orgName)` is used, so this fails. ```shell gitea_org.home: Importing from ID "3"... gitea_org.home: Import prepared! Prepared gitea_org for import gitea_org.home: Refreshing state... [id=3] ╷ │ Error: Plugin did not respond │ │ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details. ╵ Stack trace from the terraform-provider-gitea_v0.1.0 plugin: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb5b412] goroutine 54 [running]: code.gitea.io/terraform-provider-gitea/gitea.resourceOrgRead(0xc00048ecc0?, {0xd53d80?, 0xc000134370}) code.gitea.io/terraform-provider-gitea/gitea/resource_gitea_organisation.go:29 +0x72 github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0003ff0e0, 0xc000274a00, {0xd53d80, 0xc000134370}) github.com/hashicorp/terraform-plugin-sdk@v1.13.0/helper/schema/resource.go:460 +0x1aa github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc000012ba0, {0xc00042c300?, 0x5b5f66?}, 0xc00042c300) github.com/hashicorp/terraform-plugin-sdk@v1.13.0/internal/helper/plugin/grpc_provider.go:525 +0x365 github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler({0xd2c5e0?, 0xc000012ba0}, {0xed97a8, 0xc0001fee70}, 0xc00042c2a0, 0x0) github.com/hashicorp/terraform-plugin-sdk@v1.13.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x170 google.golang.org/grpc.(*Server).processUnaryRPC(0xc000002480, {0xedd060, 0xc0001d8000}, 0xc000154300, 0xc000097770, 0x13cc750, 0x0) google.golang.org/grpc@v1.27.1/server.go:1024 +0xd4f google.golang.org/grpc.(*Server).handleStream(0xc000002480, {0xedd060, 0xc0001d8000}, 0xc000154300, 0x0) google.golang.org/grpc@v1.27.1/server.go:1313 +0xa25 google.golang.org/grpc.(*Server).serveStreams.func1.1() google.golang.org/grpc@v1.27.1/server.go:722 +0x98 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.27.1/server.go:720 +0xea Error: The terraform-provider-gitea_v0.1.0 plugin crashed! ```
Author
Contributor

@techknowlogick I checked the Gitea API and it does not seem possible to get an organisation using its ID instead of the name. Not sure how to fix this.

@techknowlogick I checked the Gitea API and it does not seem possible to get an organisation using its ID instead of the name. Not sure how to fix this.
Member

Hi @pim
i think this was fixed in my fork already with https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea/pulls/13 and released under my version 0.7.2
i would kindly ask you to re check once we get a full release out of the official provider if this is working then

Hi @pim i think this was fixed in my fork already with https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea/pulls/13 and released under my version 0.7.2 i would kindly ask you to re check once we get a full release out of the official provider if this is working then
Author
Contributor

@lerentis Hi, thanks for the heads-up. I didn't continue using the official provider, but I'm excited to try it again once your code is merged!

@lerentis Hi, thanks for the heads-up. I didn't continue using the official provider, but I'm excited to try it again once your code is merged!

@pim could you try with v0.3.0 of this provider? It has @lerentis's changes merged in.

@pim could you try with v0.3.0 of this provider? It has @lerentis's changes merged in.
Author
Contributor

Can confirm it is working, thanks!

Can confirm it is working, thanks!
pim closed this issue 2023-09-18 18:18:32 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/terraform-provider-gitea#7
No description provided.