Closed NickFitz closed 1 month ago
Hey @NickFitz thank you for hunting this down and apologies for the trouble. I am going to assign the labels hacktoberfest
and Up for Grabs
to signal to the community that this is something that has been verified and can be worked. Please feel free to pick the issue up if you have time! Thank you again for all that you do for this community ❤️ !
I can confirm that behaviour, will check it
I believe I'm running into this issue with a private repository:
I look up an existing repository:
data "github_repository" "repository" {
full_name = "org/repo"
}
to try and create a branch:
resource "github_branch" "branch" {
repository = data.github_repository.repo.full_name
branch = "config-update"
}
And the URL that's produced and produces a 404:
https://api.github.com/repos/user/org/repo/git/ref/heads/main
The $user value correctly identifies the user of the token which I am using in my provider instantiation.
We also hit this type of issue on a private repo, trying to generate actions environment secrets:
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 5.0"
}
}
}
provider "github" {
# A fine-grained personal access token with organisation access
token = var.git_repo_access_token
}
data "github_repository" "repo" {
full_name = "myorg/{var.git_repo_access_token}"
}
resource "github_actions_environment_secret" "environment_secrets" {
repository = data.github_repository.repo.name
environment = github_repository_environment.repo_environment.environment
secret_name = key
plaintext_value = value
}
The personal access token used for auth has access granted to the organisation. Applying the plan generates 404 error - the url contains the token creator's username.
Error: GET https://api.github.com/repos/USER/myorg/repo_name: 404 Not Found []
👋 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!
Expected Behavior
Given the provider configuration:
the data source:
is expected to result in
data.github_branch.main
having the attributes documented at https://registry.terraform.io/providers/integrations/github/latest/docs/data-sources/branch relating to the GitHub repository atsomeorg/some_public_repository
.Examining the
DEBUG
logs shows that the path being requested from the GitHub API iswhen it should be
Setting the
GITHUB_OWNER
environment variable does not resolve the issue. It appears from the debug output that the absence of a token (which is not required as the repository is public) causes the data source to configure an anonymous owner. But an anonymous owner does not seem to have a name, and therefore the interpolation of the owner name as the organisation name in URL construction fails, resulting in the//
seen in the URL.This appears to be the same, or very similar, behaviour to that identified in issue #942 with the
github_repository_file
data source. A fix for that issue is in #1494, and from comparing that PR and the corresponding code ingithub_branch
, I believe the fix would be the same or very similar. I also suspect the same issue may be present in other data sources.Actual Behavior
The attributes of
data.github_branch.main
are allnull
due to the malformed path in the API request, which results in a404 Not Found
response.Terraform Version
Affected Resource(s)
Terraform Configuration Files
No response
Steps to Reproduce
Debug Output
Panic Output
No response
Code of Conduct