Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message when GITHUB_TOKEN not set #598

Open
lukiffer opened this issue Nov 11, 2020 · 8 comments
Open

Misleading error message when GITHUB_TOKEN not set #598

lukiffer opened this issue Nov 11, 2020 · 8 comments
Labels
Authentication Provider Status: Pinned A way to keep old or long lived issues around Type: Bug Something isn't working as documented

Comments

@lukiffer
Copy link

When configuring the provider with only the organization property and relying on the GITHUB_TOKEN environment variable for authentication, if the environment variable hasn't been set, apply and import operations display the following error message:

Error: This resource can only be used in the context of an organization, "" is a user.

This is misleading as the actual error is a missing credential.

After setting the environment variable, everything works as expected.

Terraform Version

0.13.5

Affected Resource(s)

Have only reproduced this with github_membership and github_team, but it probably applies to more.

Terraform Configuration Files

terraform {
  required_version = "=0.13.5"

  required_providers {
    github = {
      source  = "hashicorp/github"
      version = "=4.0.0"
    }
  }
}

provider "github" {
  version = "=4.0.0"
  organization = "example-org"
}

resource "github_membership" "member" {
  username = "lukiffer"
  role     = "admin"
}

Expected Behavior

A more accurate error message should be displayed, like Error: Missing GITHUB_TOKEN environment variable.

Actual Behavior

I received the error message Error: This resource can only be used in the context of an organization, "" is a user. and subsequently spent an hour debugging the provider config trying to figure out why when I supply organization it's being interpreted as an empty string.

Steps to Reproduce

  • terraform apply; or
  • terraform import github_membership.member "example-org:lukiffer"
@jcudit jcudit added Type: Bug Something isn't working as documented Provider labels Nov 24, 2020
@JeroenRijks
Copy link

Has anyone got a workaround for this issue?

@jcudit
Copy link
Contributor

jcudit commented Jan 26, 2021

Does this relate to the fix that was shipped in v4.3.1? Can anyone try out this release and confirm?

@dgteixeira
Copy link

dgteixeira commented Sep 23, 2021

Hello everyone, I hope you are all well :)
@jcudit, I have tried and I have a similar problem when my GITHUB_TOKEN is expired or already inactive.

Terraform version: 1.0.7;
Github Provider version: v4.14.0

With the following terraform code, I get a Error: Plugin did not respond error

terraform {
  required_version = ">= 1.0.0"

  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 4.14.0"
    }
  }
}

provider "github" {
  owner = var.org_name
}

data "github_organization" "org_name" {
  name = var.org_name
}

resource "github_membership" "members" {
  username = foobar
  role          = "member"
}

Full error:

│ Error: Plugin did not respond
│
│   with data.github_organization.org_name,
│   on main.tf line 23, in data "github_organization" "org_name":
│   23: data "github_organization" "org_name" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵
╷
│ Error: This resource can only be used in the context of an organization, "" is a user.
│
│   with github_membership.members["foobar"],
│    in resource "github_membership" "members":
│   XX: resource "github_membership" "members" {
│
╵

The plugin error, checking DEBUG logs is as follows:

Stack trace from the terraform-provider-github_v4.14.0 plugin:

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

goroutine 57 [running]:
github.com/terraform-providers/terraform-provider-github/github.dataSourceGithubOrganizationRead(0xc00074d7a0, 0xe1f4c0, 0xc000045d80, 0xc00074d7a0, 0x0)
        github.com/terraform-providers/terraform-provider-github/github/data_source_github_organization.go:120 +0x8b1
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).ReadDataApply(0xc00057a280, 0xc0004c82e0, 0xe1f4c0, 0xc000045d80, 0xc000585030, 0x1, 0x0)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/helper/schema/resource.go:398 +0x91
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).ReadDataApply(0xc00057aa80, 0xc0006a19a8, 0xc0004c82e0, 0xc0004c82e0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/helper/schema/provider.go:451 +0x8f
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc000214598, 0x1169bb0, 0xc00030ede0, 0xc0007ae480, 0xc000214598, 0xc00030ede0, 0xc00008ea50)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/internal/helper/plugin/grpc_provider.go:1036 +0x42d
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadDataSource_Handler(0xf97c40, 0xc000214598, 0x1169bb0, 0xc00030ede0, 0xc0002fc240, 0x0, 0x1169bb0, 0xc00030ede0, 0xc0007241c0, 0x69)
        github.com/hashicorp/terraform-plugin-sdk@v1.7.0/internal/tfplugin5/tfplugin5.pb.go:3225 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000480000, 0x11713d8, 0xc00043e780, 0xc000190300, 0xc0000f6b10, 0x16d8b10, 0x0, 0x0, 0x0)
        google.golang.org/grpc@v1.23.0/server.go:995 +0x482
google.golang.org/grpc.(*Server).handleStream(0xc000480000, 0x11713d8, 0xc00043e780, 0xc000190300, 0x0)
        google.golang.org/grpc@v1.23.0/server.go:1275 +0xd2c
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc0000344d0, 0xc000480000, 0x11713d8, 0xc00043e780, 0xc000190300)
        google.golang.org/grpc@v1.23.0/server.go:710 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.23.0/server.go:708 +0xa5

Error: The terraform-provider-github_v4.14.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.

When I setup my env var GITHUB_TOKEN correctly with a permission-sufficient PAT , it works without problem.
This shouldn't crash the plugin, only show an error like @lukiffer has mentioned:

Error: Missing GITHUB_TOKEN environment variable.

Thanks!

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Dec 7, 2022
@ulfjack
Copy link

ulfjack commented Dec 7, 2022

We're seeing this (or a similar issue) with 5.7.0. In our case, we're seeing hangs when someone doesn't have the GITHUB_TOKEN environment variable set, and we're seeing a large number of added resources if they do but missing scopes necessary to create those resources. It's a very bad user experience.

Also, dear bot, we can't add the Status: Pinned label.

@kfcampbell kfcampbell added Priority: Normal Status: Pinned A way to keep old or long lived issues around and removed Status: Stale Used by stalebot to clean house Priority: Normal labels Dec 8, 2022
@kfcampbell
Copy link
Member

Thanks for the notice, I've pinned the issue and I'll look into why label permissions aren't working.

PRs for adding appropriate error messages are appreciated!

@ulfjack
Copy link

ulfjack commented Dec 9, 2022

Thanks! We're generally happy to send PRs, but given that we don't currently see an error message in the first place, we're not entirely sure where to start.

@kfcampbell
Copy link
Member

The hanging thing is very weird. The error message in the original issue is found here, which might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Authentication Provider Status: Pinned A way to keep old or long lived issues around Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

7 participants