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

[BUG]: github_repository_collaborator import not working #1798

Open
1 task done
thenaturalist opened this issue Jul 17, 2023 · 1 comment
Open
1 task done

[BUG]: github_repository_collaborator import not working #1798

thenaturalist opened this issue Jul 17, 2023 · 1 comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request

Comments

@thenaturalist
Copy link

Describe the need

The docs for a github_repository_collaborator resource specify the following import command for existing resources:

$ terraform import github_repository_collaborator.collaborator terraform:someuser

Source: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator

Expected behavior:
An existing collaborator someuser for the repo terraform is imported into Terraform state without further configuration or any other dependent Terraform resources.

Actual behavior:
The terraform import command fails with

github_repository_collaborator.this["someuser-terraform"]: Importing from ID "terraform:someuser"...
github_repository_collaborator.this["someuser-terraform"]: Import prepared!
  Prepared github_repository_collaborator for import
github_repository_collaborator.this["someuser-terraform"]: Refreshing state... [id=terraform:someuser]
╷
│ Error: Cannot import non-existent remote object
│ 
│ While attempting to import an existing object to "github_repository_collaborator.this[\"someuser-terraform\"]", the provider detected that
│ no object exists with the given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's
│ configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
╵

The provider looks for outstanding invitations on the GitHub API.
This makes no sense, as this command should import existing, already invited collaborators.

TF_LOG=DEBUG output:

2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: 2023/07/17 17:19:16 [DEBUG] GitHub API Request Details:
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: ---[ REQUEST ]---------------------------------------
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: GET /repos/foo-org/terraform/invitations?per_page=100 HTTP/1.1
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: Host: api.github.com
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: User-Agent: go-github/v53.2.0
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: Accept: application/vnd.github.v3+json,application/vnd.github.stone-crop-preview+json
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: X-Github-Api-Version: 2022-11-28
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: Accept-Encoding: gzip
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: 
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: 
2023-07-17T17:19:16.581+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: -----------------------------------------------------
2023-07-17T17:19:16.782+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: 2023/07/17 17:19:16 [DEBUG] GitHub API Response Details:
2023-07-17T17:19:16.782+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: ---[ RESPONSE ]--------------------------------------
2023-07-17T17:19:16.782+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: HTTP/2.0 404 Not Found
2023-07-17T17:19:16.782+0200 [DEBUG] provider.terraform-provider-github_v5.31.0: Access-Control-Allow-Origin: *
...

Steps to reproduce:

Try importing an existing, no outstanding invitation collaborator with the documented import command.

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@thenaturalist thenaturalist added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Jul 17, 2023
@nickfloyd nickfloyd added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Jul 17, 2023
@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 21, 2023
@carlpett
Copy link

I ran into this as well, but with some debugging found at that for me at least, the problem was partially caused by running under my own credentials. It appears the owner parameter of the provider is not respected during import (and planning, even?).
If I run with GITHUB_OWNER=my-org terraform import ..., it works. 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants