terraform-provider-github
terraform-provider-github copied to clipboard
data source github_repository_file assumes the repository isn't in an org and assumes the repository was created by the github token owner.
The github_repository_file data source was added in the last release. It returns 404 no matter what I try. It looks like instead of using the provided repository name, it prepends the username of the github token. So, it is assuming that the repo is owed by the user and that the repo is also not an organization repo Below is an example trying to pull a file from this repository.
Terraform Configuration Files
data "github_repository_file" "lambda_file" {
repository = "integrations/terraform-provider-github"
branch = "main"
file = "README.md"
}
provider "github" {
token = "ghp_sometokenmemberofanorg"
}
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 4.16"
}
}
}
I've tried it with variations such as:
data "github_repository_file" "lambda_file" {
repository = "integrations/terraform-provider-github"
branch = "main"
file = "README.md"
}
and
data "github_repository_file" "lambda_file" {
repository = "terraform-provider-github"
branch = "main"
file = "README.md"
}
Debug Output
bash-3.2$ terraform plan
╷
│ Error: unexpected status code: 404 Not Found
│
│ with data.github_repository_file.lambda_file,
│ on test.tf line 1, in data "github_repository_file" "lambda_file":
│ 1: data "github_repository_file" "lambda_file" {
│
╵
bash-3.2$ export TF_LOG="DEBUG"
bash-3.2$ terraform plan
2021-10-14T16:39:40.259-0500 [DEBUG] Adding temp file log sink: /var/folders/nz/7pk419rj4dzf8mm5pr5290040000gp/T/terraform-log662639515
2021-10-14T16:39:40.260-0500 [INFO] Terraform version: 0.15.4
2021-10-14T16:39:40.260-0500 [INFO] Go runtime version: go1.16.3
2021-10-14T16:39:40.260-0500 [INFO] CLI args: []string{"/usr/local/bin/terraform", "plan"}
2021-10-14T16:39:40.260-0500 [DEBUG] Attempting to open CLI config file: /Users/user/.terraformrc
2021-10-14T16:39:40.260-0500 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2021-10-14T16:39:40.260-0500 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2021-10-14T16:39:40.260-0500 [DEBUG] ignoring non-existing provider search directory /Users/conner/.terraform.d/plugins
2021-10-14T16:39:40.260-0500 [DEBUG] ignoring non-existing provider search directory /Users/conner/Library/Application Support/io.terraform/plugins
2021-10-14T16:39:40.260-0500 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2021-10-14T16:39:40.260-0500 [INFO] CLI command args: []string{"plan"}
2021-10-14T16:39:40.262-0500 [DEBUG] New state was assigned lineage "e9e172a4-e825-8f6a-51bc-5ccb6b1f82f1"
2021-10-14T16:39:40.320-0500 [DEBUG] checking for provisioner in "."
2021-10-14T16:39:40.322-0500 [DEBUG] checking for provisioner in "/usr/local/bin"
2021-10-14T16:39:40.322-0500 [INFO] Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory
2021-10-14T16:39:40.323-0500 [INFO] backend/local: starting Plan operation
2021-10-14T16:39:40.324-0500 [DEBUG] created provider logger: level=debug
2021-10-14T16:39:40.324-0500 [INFO] provider: configuring client automatic mTLS
2021-10-14T16:39:40.357-0500 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 args=[.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0]
2021-10-14T16:39:40.361-0500 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 pid=79062
2021-10-14T16:39:40.361-0500 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0
2021-10-14T16:39:40.374-0500 [INFO] provider.terraform-provider-github_v4.16.0: configuring server automatic mTLS: timestamp=2021-10-14T16:39:40.374-0500
2021-10-14T16:39:40.408-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: plugin address: address=/var/folders/nz/7pk419rj4dzf8mm5pr5290040000gp/T/plugin769247669 network=unix timestamp=2021-10-14T16:39:40.408-0500
2021-10-14T16:39:40.409-0500 [DEBUG] provider: using plugin: version=5
2021-10-14T16:39:40.453-0500 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unimplemented desc = unknown service plugin.GRPCStdio"
2021-10-14T16:39:40.454-0500 [DEBUG] No provider meta schema returned
2021-10-14T16:39:40.458-0500 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 pid=79062
2021-10-14T16:39:40.458-0500 [DEBUG] provider: plugin exited
2021-10-14T16:39:40.458-0500 [INFO] terraform: building graph: GraphTypeValidate
2021-10-14T16:39:40.459-0500 [DEBUG] ProviderTransformer: "data.github_repository_file.lambda_file" (*terraform.NodeValidatableResource) needs provider["registry.terraform.io/integrations/github"]
2021-10-14T16:39:40.459-0500 [DEBUG] ReferenceTransformer: "data.github_repository_file.lambda_file" references: []
2021-10-14T16:39:40.459-0500 [DEBUG] ReferenceTransformer: "provider["registry.terraform.io/integrations/github"]" references: []
2021-10-14T16:39:40.460-0500 [DEBUG] Starting graph walk: walkValidate
2021-10-14T16:39:40.460-0500 [DEBUG] created provider logger: level=debug
2021-10-14T16:39:40.460-0500 [INFO] provider: configuring client automatic mTLS
2021-10-14T16:39:40.492-0500 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 args=[.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0]
2021-10-14T16:39:40.496-0500 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 pid=79063
2021-10-14T16:39:40.496-0500 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0
2021-10-14T16:39:40.509-0500 [INFO] provider.terraform-provider-github_v4.16.0: configuring server automatic mTLS: timestamp=2021-10-14T16:39:40.509-0500
2021-10-14T16:39:40.544-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: plugin address: address=/var/folders/nz/7pk419rj4dzf8mm5pr5290040000gp/T/plugin206281242 network=unix timestamp=2021-10-14T16:39:40.543-0500
2021-10-14T16:39:40.544-0500 [DEBUG] provider: using plugin: version=5
2021-10-14T16:39:40.586-0500 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unimplemented desc = unknown service plugin.GRPCStdio"
2021-10-14T16:39:40.588-0500 [DEBUG] No provider meta schema returned
2021-10-14T16:39:40.594-0500 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 pid=79063
2021-10-14T16:39:40.594-0500 [DEBUG] provider: plugin exited
2021-10-14T16:39:40.594-0500 [INFO] backend/local: plan calling Plan
2021-10-14T16:39:40.594-0500 [INFO] terraform: building graph: GraphTypePlan
2021-10-14T16:39:40.594-0500 [DEBUG] ProviderTransformer: "data.github_repository_file.lambda_file (expand)" (*terraform.nodeExpandPlannableResource) needs provider["registry.terraform.io/integrations/github"]
2021-10-14T16:39:40.595-0500 [DEBUG] ReferenceTransformer: "data.github_repository_file.lambda_file (expand)" references: []
2021-10-14T16:39:40.595-0500 [DEBUG] ReferenceTransformer: "provider["registry.terraform.io/integrations/github"]" references: []
2021-10-14T16:39:40.595-0500 [DEBUG] Starting graph walk: walkPlan
2021-10-14T16:39:40.595-0500 [DEBUG] created provider logger: level=debug
2021-10-14T16:39:40.596-0500 [INFO] provider: configuring client automatic mTLS
2021-10-14T16:39:40.626-0500 [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 args=[.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0]
2021-10-14T16:39:40.630-0500 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0 pid=79064
2021-10-14T16:39:40.630-0500 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/integrations/github/4.16.0/darwin_amd64/terraform-provider-github_v4.16.0
2021-10-14T16:39:40.644-0500 [INFO] provider.terraform-provider-github_v4.16.0: configuring server automatic mTLS: timestamp=2021-10-14T16:39:40.644-0500
2021-10-14T16:39:40.678-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: plugin address: address=/var/folders/nz/7pk419rj4dzf8mm5pr5290040000gp/T/plugin924949319 network=unix timestamp=2021-10-14T16:39:40.677-0500
2021-10-14T16:39:40.678-0500 [DEBUG] provider: using plugin: version=5
2021-10-14T16:39:40.721-0500 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unimplemented desc = unknown service plugin.GRPCStdio"
2021-10-14T16:39:40.723-0500 [DEBUG] No provider meta schema returned
2021-10-14T16:39:40.726-0500 [WARN] ValidateProviderConfig from "provider["registry.terraform.io/integrations/github"]" changed the config value, but that value is unused
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: 2021/10/14 16:39:40 [DEBUG] Selecting owner from GITHUB_OWNER environment variable
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: 2021/10/14 16:39:40 [DEBUG] Setting write_delay_ms to 1000
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: 2021/10/14 16:39:40 [DEBUG] Github API Request Details:
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: ---[ REQUEST ]---------------------------------------
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: GET /user HTTP/1.1
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: Host: api.github.com
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: User-Agent: go-github
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: Accept: application/vnd.github.v3+json
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: Accept-Encoding: gzip
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0:
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0:
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: -----------------------------------------------------
2021-10-14T16:39:40.726-0500 [DEBUG] provider.terraform-provider-github_v4.16.0: 2021/10/14 16:39:40 [TRACE] Acquiring lock for GitHub API request (%!q(
Expected Behavior
The Data resource populates the file info
Actual Behavior
404 error
Steps to Reproduce
- copy the above with your own token, terraform
Confirmed that this is a bug due to the recently added data source coming from it's resource counterpart.
Adding an owner
field here makes a lot of sense from a usability perspective.
This issue also affects resources. The plan somehow works fine but the apply leads to the not found issue
Confirmed that this is a bug due to the recently added data source coming from it's resource counterpart. Adding an
owner
field here makes a lot of sense from a usability perspective.
I have the same problem here.
But adding the owner
param into provider configuration don't solve the problem.
I have this structure:
├── backend.tf
├── locals.tf
├── provider.tf
├── repository
│ ├── data-sources.tf
│ ├── secrets.tf
│ ├── variables.tf
│ └── webhook.tf
├── risco-terraform-modules.tf
└── variables.tf
When I'm calling the local module named repository
the resource don't get the owner
value then I get 404.
Below a log level line:
{"@level":"error","@message":"Error: GET https://api.github.com/repos//risco-terraform-gcp-module-monitoring-by-status-code/actions/secrets/public-key: 404 Not Found []","@module":"terraform.ui","@timestamp":"2021-12-12T08:46:32.761759Z","diagnostic":{"severity":"error","summary":"GET https://api.github.com/repos//risco-terraform-gcp-module-monitoring-by-status-code/actions/secrets/public-key: 404 Not Found []","detail":"","address":"module.module_repositories[\"monitoring-by-status-code\"].github_actions_secret.module_secret_tf_auth_token","range":{"filename":"repository/secrets.tf","start":{"line":1,"column":64,"byte":63},"end":{"line":1,"column":65,"byte":64}},"snippet":{"context":"resource \"github_actions_secret\" \"module_secret_tf_auth_token\"","code":"resource \"github_actions_secret\" \"module_secret_tf_auth_token\" {","start_line":1,"highlight_start_offset":63,"highlight_end_offset":64,"values":[]}},"type":"diagnostic"}
Problem is still there. owner parameter doesn't seem to make any difference, environmental variable GITHUB_ORGANIZATION makes it work.
Just ran up against this today and importing was troublesome, too. Trying to add a CODEOWNERS file to one of the two orgs I manage with my TF configuration:
resource "github_repository_file" "myorg_codeowners" {
for_each = toset(data.github_repositories.myorg_org_prod.full_names)
repository = data.github_repository.myorg_org_prod[each.value].name
branch = data.github_repository.myorg_org_prod[each.value].default_branch
file = ".github/CODEOWNERS"
content = "* @myorg/myorg-devs"
commit_message = "Managed by Terraform"
commit_author = "Firstname Lastname"
commit_email = "[email protected]"
overwrite_on_create = false
}
data "github_repositories" "myorg_org_prod" {
query = "org:myorg topic:in-production"
}
data "github_repository" "myorg_org_prod" {
for_each = toset(data.github_repositories.myorg_org_prod.full_names)
full_name = each.value
}
I had to do this to import for the one repo that already had a CODEOWNERS:
GITHUB_OWNER=myorg terraform import \
'github_repository_file.myorg_codeowners["myorg/common-scripts"]' \
'common-scripts/.github/CODEOWNERS:master'
and this to plan/apply:
GITHUB_OWNER=myorg terraform apply
This was successful but I'd have to add a separate configuration for CODEOWNERS for the other org I manage and invoke them separately. I'm not sure what would happen if they needed to make changes at the same time because the GITHUB_OWNER
envvar can only be set to one thing per invocation!
It feels like the whole github plugin needs some work to better respect the org/repo
coordinates of a repository.
This is still broken, please fix soon.
This also happens with a github_repository
data source.
data "github_repository" "main" {
full_name = format("%s/%s", var.github_owner, var.repository_name)
}
I am also getting this when just trying to get a file that I know exists.
data "github_repository" "ftf-account-management" {
full_name = "FundThatFlip/ftf-account-management"
}
data "github_repository_file" "cognito-css" {
repository = data.github_repository.ftf-account-management.name
branch = "dev"
file = ".gitignore"
}
I am seeing error:
╷
│ Error: unexpected status code: 404 Not Found
│
│ with data.github_repository_file.cognito-css,
│ on cognito.tf line 259, in data "github_repository_file" "cognito-css":
│ 259: data "github_repository_file" "cognito-css" {
│
╵
For the repo that needs to have files, auto_init = true
and github_repository_file
needs to depend on github_repository
. This is what I found to be true for new repositories.
When can we get a release with this fix in?
I'm planning on cutting a new release today!
Has there been any fix on this? still facing this issue in an organization owned repository