You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in which we see id=legunto set correctly. However, the next line contains Reading repository: /legunto, with an appended slash, that we then see in the request string: GET /repos//legunto HTTP/1.1.
My guess is that somewhere we're accidentally appending an extra slash, and if we removed that, the GET request would succeed. I'm going to poke around the code a little bit to see if I can prove that.
Nope, you're totally correct that it's indicative of a missing owner. I've been unable to reproduce this locally, which makes me think it's perhaps related to the remote backend organization configuration. I'm going to try to create a remote backend for this test and try to reproduce that way.
I've been unable to repro this using Terraform Cloud, either...my full HCL is below:
resource "github_repository" "legunto" {
name = "legunto"
description = "Fetch MediaWiki Scribunto modules from wikis"
default_branch = local.default_repo.default_branch
has_issues = local.default_repo.has_issues
vulnerability_alerts = local.default_repo.vulnerability_alerts
archive_on_destroy = local.default_repo.archive_on_destroy
}
terraform {
required_version = "~> 0.14.0"
backend "remote" {
organization = "example-org-b8a054"
workspaces {
name = "github"
}
}
required_providers {
github = {
source = "hashicorp/github"
version = "~> 4.0"
}
}
}
provider "github" {
organization = "kfcampbell-terraform-provider"
}
locals {
default_repo = {
# repository
default_branch = "main",
has_issues = true,
vulnerability_alerts = true,
archive_on_destroy = true,
# branch_protection
pattern = "main"
push_restrictions = [],
enforce_admins = false,
dismiss_stale_reviews = false,
require_code_owner_reviews = false,
required_approving_review_count = 1,
}
with_cd = merge(local.default_repo, {
# enforce_admins is temporarily disabled due to too few development members.
enforce_admins = false,
})
docker = merge(local.default_repo, {
# enforce_admins is temporarily disabled due to too few development members.
enforce_admins = false,
default_branch = "master",
pattern = "master"
})
bot = local.with_cd
}
The only things I've attempted to change from your setup is my GitHub organization name, and my Terraform Cloud organization name. I've also copied in your local configuration setup as well.
In order to run this test, I created a github workspace using my Terraform Cloud account, used terraform apply to create the resource, then destroyed the workspace to remove the terraform state, recreated the workspace, and then ran the below import command:
sh$ terraform import github_repository.legunto legunto
github_repository.legunto: Importing from ID "legunto"...
github_repository.legunto: Import prepared!
Prepared github_repository for import
github_repository.legunto: Refreshing state... [id=legunto]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
@lens0021 is there anything about this reproduction that appears incorrect or not in line with what you're doing?
I retried the import in few other ways, I have noticed it was GITHUB_TOKEN that I was missing.
$ export GITHUB_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ terraform import github_repository.legunto legunto
...
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
It will be helpful if there could be a message for the missing token, Thanks!
Reacted by Fahima Mokhtari, arafat-shopify, Darren Taylor, Kurt Lehnardt and ricky26j
Oh I'm glad to hear you got it resolved! I think a 404 is somewhat appropriate if a token isn't present, since visiting a GitHub private repository from an unauthenticated or anonymous account will give a 404. I agree it's confusing to see the path missing the organization and perhaps the messaging could be improved.
I've also been experiencing this issue, specifically when trying to import a github_repository resource into a child module.
If I run export GITHUB_OWNER=<org name>, the import works successfully.
Reacted by Lens0021 / Leslie, Naka Masato, Andrew Waters, Chih-Hsuan Yen, Bob Rohan, Dan Kelly, Jeff Moser, Theo Skolnik, Jaume Devesa, Ivan Larin and 3 more
👋 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!
I'm having the same issue with the latest version of this provider (5.18.3) and a repo internal to my org (myorg/mobile). I set TF_LOG=INFO and this is the relevant part of the log:
$ terraform import module.github.github_repository.repos[\"mobile\"] mobile
...
2023-03-25T17:32:17.042+0100 [WARN] Provider "registry.terraform.io/integrations/github" produced an unexpected new value for module.github.github_repository.repos["mobile"] during refresh.
- Root resource was present, but now absent
2023-03-25T17:32:17.042+0100 [ERROR] vertex "import module.github.github_repository.repos[\"mobile\"] result" error: Cannot import non-existent remote object
2023-03-25T17:32:17.042+0100 [ERROR] vertex "module.github.github_repository.repos[\"mobile\"] (import id \"mobile\")" error: Cannot import non-existent remote object
2023-03-25T17:32:17.042+0100 [ERROR] vertex "module.github.github_repository.repos (expand)" error: Cannot import non-existent remote object
╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "module.github.github_repository.repos[\"mobile\"]", 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.
I am having the same issue now as well, on the same version as @crmne
It seem to succeed (Import prepared!) and then utterly fails.
It also refuses to work with a nested module, although the nested module is able to create repos from scratch.
github_repository.eaas: Importing from ID "eaas"...
github_repository.eaas: Import prepared!
Prepared github_repository for import
github_repository.eaas: Refreshing state... [id=eaas]
╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "github_repository.eaas",
│ 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.
╵
I may or may not have started with the now-deprecated hashicorp/github. You must ensure with terraform -version or terraform providers that only one provider is present. If more than is present, remove it with terraform state replace-provider registry.terraform.io/hashicorp/github registry.terraform.io/integrations/github.
The docs for this provider note that a nested module must have a providers import there as well, not just at the root. Otherwise everything breaks horribly. Go into your subdirectories and put this in providers.tf or something:
# this must be included in each submodule or you will get horrible and strange errors
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 5.0"
}
}
}
My module is nested. You must provide a path to it. terraform import -config=github/repos github_repository.embeddings_api embeddings_api, where github and repos are both directories.
Finally, the resource was still not properly created. After import, Terraform wanted to destroy and to create the resource. Of course Github will not allow it to do so. Looking at terraform.tfstate, the new resource (my imported repo) was missing this at the top: "module": "module.repos",. All the other blocks had it. I manually added it and things worked. I had to do this for every imported resource.
god what a journey. Hope this helps and good luck.
I managed to solve the issue for me. It looks like I didn't set GITHUB_TOKEN locally, and was assuming it would be using Terraform Cloud's GITHUB_TOKEN. My bad, but perhaps it would be helpful to have a message, at least at the TF_LOG=INFO that clearly tells the use they haven't set GITHUB_TOKEN. Thanks!
Activity
olaven commentedon Feb 17, 2021
➕
Experiencing the same issue with version 4.4.0 and S3 backend.
lens0021 commentedon Mar 19, 2021
Same in Terraform v0.14.8 and terraform-provider-github v4.5.2.
lens0021 commentedon Apr 8, 2021
The name of the organization is empty in the log.
lens0021 commentedon Apr 8, 2021
TF_LOG=TRACE terraform import github_repository.legunto femiwiki/leguntoalso falied:kfcampbell commentedon Apr 10, 2021
Your debug output has the following snippet:
in which we see
id=leguntoset correctly. However, the next line containsReading repository: /legunto, with an appended slash, that we then see in the request string:GET /repos//legunto HTTP/1.1.My guess is that somewhere we're accidentally appending an extra slash, and if we removed that, the GET request would succeed. I'm going to poke around the code a little bit to see if I can prove that.
kfcampbell commentedon Apr 10, 2021
Nope, you're totally correct that it's indicative of a missing owner. I've been unable to reproduce this locally, which makes me think it's perhaps related to the
remotebackend organization configuration. I'm going to try to create a remote backend for this test and try to reproduce that way.kfcampbell commentedon Apr 10, 2021
I've been unable to repro this using Terraform Cloud, either...my full HCL is below:
The only things I've attempted to change from your setup is my GitHub organization name, and my Terraform Cloud organization name. I've also copied in your
localconfiguration setup as well.In order to run this test, I created a
githubworkspace using my Terraform Cloud account, usedterraform applyto create the resource, then destroyed the workspace to remove the terraform state, recreated the workspace, and then ran the belowimportcommand:@lens0021 is there anything about this reproduction that appears incorrect or not in line with what you're doing?
lens0021 commentedon Apr 14, 2021
@kfcampbell Thank you for your investigation.
I retried the import in few other ways, I have noticed it was
GITHUB_TOKENthat I was missing.It will be helpful if there could be a message for the missing token, Thanks!
kfcampbell commentedon Apr 15, 2021
Oh I'm glad to hear you got it resolved! I think a 404 is somewhat appropriate if a token isn't present, since visiting a GitHub private repository from an unauthenticated or anonymous account will give a 404. I agree it's confusing to see the path missing the organization and perhaps the messaging could be improved.
kungfuchicken commentedon May 27, 2021
still not resolved for me.
running TF 13.6 (because of reasons).
provider registry.terraform.io/hashicorp/github v4.10.1
Artemu commentedon Jun 11, 2021
So for anyone having this issue.
You need to set the
GITHUB_TOKENin both TF Cloud and on your CLI. They also need to match - use the same token.call commentedon Jun 16, 2021
I've also been experiencing this issue, specifically when trying to import a
github_repositoryresource into a child module.If I run
export GITHUB_OWNER=<org name>, the import works successfully.kohsuke commentedon Jul 21, 2021
I had the same symptom. Like @lens0021 , I saw in the debug output that the GET request to GitHub was missing the organization name part:
And just as he did, setting
GITHUB_TOKENenvironment variable resolved the issue.What I'd love to see is the error message improvement.
9 remaining items
Use hashcorp/github
github-actions commentedon Dec 6, 2022
👋 Hey Friends, this issue has been automatically marked as
stalebecause it has no recent activity. It will be closed if no further activity occurs. Please add theStatus: Pinnedlabel if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!crmne commentedon Mar 25, 2023
I'm having the same issue with the latest version of this provider (5.18.3) and a repo internal to my org (myorg/mobile). I set
TF_LOG=INFOand this is the relevant part of the log:coyotespike commentedon Mar 25, 2023
I am having the same issue now as well, on the same version as @crmne
It seem to succeed (
Import prepared!) and then utterly fails.It also refuses to work with a nested module, although the nested module is able to create repos from scratch.
coyotespike commentedon Mar 26, 2023
I have now solved this problem.
Several issues may have contributed.
I may or may not have started with the now-deprecated hashicorp/github. You must ensure with
terraform -versionorterraform providersthat only one provider is present. If more than is present, remove it withterraform state replace-provider registry.terraform.io/hashicorp/github registry.terraform.io/integrations/github.The docs for this provider note that a nested module must have a providers import there as well, not just at the root. Otherwise everything breaks horribly. Go into your subdirectories and put this in
providers.tfor something:My module is nested. You must provide a path to it.
terraform import -config=github/repos github_repository.embeddings_api embeddings_api, wheregithubandreposare both directories.Finally, the resource was still not properly created. After import, Terraform wanted to destroy and to create the resource. Of course Github will not allow it to do so. Looking at
terraform.tfstate, the new resource (my imported repo) was missing this at the top:"module": "module.repos",. All the other blocks had it. I manually added it and things worked. I had to do this for every imported resource.god what a journey. Hope this helps and good luck.
crmne commentedon Mar 27, 2023
Thanks for your comments @coyotespike, glad that it worked for you but unfortunately they didn't help in my case.
However, I managed to find the issue, by setting
TF_LOG=DEBUG:the
GETshould be done on/repos/freshflowai/freshflow.aibut I can't find a way in the resource to specify the owner of the repository.crmne commentedon Mar 31, 2023
I managed to solve the issue for me. It looks like I didn't set
GITHUB_TOKENlocally, and was assuming it would be using Terraform Cloud'sGITHUB_TOKEN. My bad, but perhaps it would be helpful to have a message, at least at theTF_LOG=INFOthat clearly tells the use they haven't setGITHUB_TOKEN. Thanks!tekumara commentedon Aug 14, 2023
I'm getting this error when using
And setting the env vars:
With this authentication I can plan and apply, but not import.
If I switch to
GITHUB_TOKEN(ie: not app auth) it works.