terraform-provider-github icon indicating copy to clipboard operation
terraform-provider-github copied to clipboard

`github_team` resource fails with `Error: this resource can only be used in the context of an organization, "foo" is a user` in v5.9.2

Open chamoisla opened this issue 2 years ago • 13 comments

    Still hitting this issue in 5.9.2 for the `github_team` resource.

Originally posted by @chamoisla in https://github.com/integrations/terraform-provider-github/issues/1373#issuecomment-1329370004

Terraform Version 1.1.3

Affected Resource(s) github_team If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

provider "github" {
  token    = var.token
  base_url = var.base_url
  owner    = var.owner
}

resource "github_team" "foo" {
  name           = var.name
  description    =  var.description
  privacy        = var.privacy
}

Debug Output

2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: 2022/11/28 08:54:21 [DEBUG] Github API Request Details:
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: ---[ REQUEST ]---------------------------------------
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: GET /api/v3/orgs/myorgname HTTP/1.1
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: Host: REDACTED
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: User-Agent: go-github/v48.0.0
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: Accept: application/vnd.github.surtur-preview+json,application/vnd.github.stone-crop-preview+json
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: Accept-Encoding: gzip
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: 
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: 
2022-11-28T08:54:21.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: -----------------------------------------------------
2022-11-28T08:54:51.183-0800 [DEBUG] provider.terraform-provider-github_v5.9.2: 2022/11/28 08:54:51 [INFO] Token present; configuring authenticated owner: myorgname
2022-11-28T08:54:51.187-0800 [DEBUG] ReferenceTransformer: "module.foo.github_team.bar" references: []
2022-11-28T08:54:51.206-0800 [ERROR] vertex "module.foo.github_team.bar" error: this resource can only be used in the context of an organization, "myorgname" is a user

Panic Output N/A

Expected Behavior Access should be refreshed, changes should be proposed by terraform plan

Actual Behavior terraform plan errors:

│ Error: this resource can only be used in the context of an organization, "foo" is a user
│ 
│   with module.foo.github_team.bar,
│   on modules/foor/bar.tf line 85, in resource "github_team" "foo":
│   85: resource "github_team" "foo" {

Steps to Reproduce

  • Fails with multiple version of Terraform and of the provider plugin.
  • Made the following change directly to the provider source code and it works for me locally. github/config.go
func RateLimitedHTTPClient(client *http.Client, writeDelay time.Duration, readDelay time.Duration) *http.Client {

	client.Transport = NewEtagTransport(client.Transport)
	client.Transport = NewRateLimitTransport(client.Transport, WithWriteDelay(writeDelay), WithReadDelay(readDelay))
	client.Transport = logging.NewTransport("Github", client.Transport)
	client.Transport = newPreviewHeaderInjectorTransport(map[string]string{
		// TODO: remove when Stone Crop preview is moved to general availability in the GraphQL API
		"Accept": "application/vnd.github.v3.repository+json", // Replaced the Stone Crop API with GitHub v3
	}, client.Transport)

	return client
}

References

  • https://github.com/integrations/terraform-provider-github/issues/1373

chamoisla avatar Nov 28 '22 16:11 chamoisla