Skip to content

Misleading error message when GITHUB_TOKEN not set #598

@lukiffer

Description

@lukiffer

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions