terraform-provider-github: Data source github_actions_public_key returns a 404
Terraform Version
Terraform 0.13.6
Affected Resource(s)
- github_actions_public_key
Terraform Configuration Files
provider "github" {
token = var.github_token
organization = "buffalogrid"
}
data "github_actions_public_key" "repo_public_key" {
repository = var.repo
}
resource "github_actions_secret" "secret" {
for_each = var.config
repository = var.repo
secret_name = upper(join("_", [var.env, each.key]))
plaintext_value = each.value
}
Provider configuration:
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 4.3.0"
}
}
}
Debug Output
https://gist.github.com/amogram/a937c1f0d83ec8dee2a390ed8fdcecf6
Panic Output
Expected Behavior
The data source should retrieve information about a GitHub Actions public key.
Actual Behavior
The call returns a 404. The makeup of the GET request doesn’t appear to be correct. It seems to be missing the organization name.
It appears to be a similar issue to #655 and what is discussed here: https://github.com/integrations/terraform-provider-github/issues/652#issuecomment-763603673
Error: GET https://api.github.com/repos//bg-dashboards-and-control-panels-frontend/actions/secrets/public-key: 404 Not Found []
on github-repo-secrets/main.tf line 1, in data "github_actions_public_key" "repo_public_key":
1: data "github_actions_public_key" "repo_public_key" {
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
- Added the data source.
- Organisation is set in the provider.
- Run
terraform plan.
Important Factoids
References
It appears to be a similar issue to #655 and what is discussed here: https://github.com/integrations/terraform-provider-github/issues/652#issuecomment-763603673
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 20
- Comments: 24 (2 by maintainers)
I was able to solve this by setting these ENV variables.
export GITHUB_TOKEN=<Personal Access Token with write permissions>export GITHUB_OWNER=<owner_name>github_actions_public_key data source is failing because my github organization requires SAML auth:
404/Not Found when sending requests without SSO Auth Token as header:
Successful response when providing an SSO-enabled Github Personal Access Token (PAT) as an Authorization header.
There is no way I can see using to authenticate to Github organizations requiring SAML auth in the
github_actions_public_keydata source.–
Alternate question, I possess the public key value which the github_actions_public_key data source wishes to retrieve. Am I able to set this variable in TF so the
github_actions_secretresource can use it? I’ve tried plugging it into local variables namedgithub_actions_public_keyand that does not work.Your PAT token needs to have the
read:public_keypermissions underadmin:public_key.tried everything in this thread, nothing work. Does anybody know about cause of this ?
actions/secrets/public-key: 404 Not Found []
Based on the @iskarconsulting config (huge thanks!), I believe the following causes the 404 error: Secret’s
repositoryfield should be just repo name without the owner part. For instance, it should be “test” instead of “aderesh/test”. it works even without providing “owner” in the provider configuration for me.Full solution:
PAT: Fine-grained with
Secrets:Read and Write, scoped totestrepo.It would be nice to know if there are terms/names for “REPO” and “OWNER/REPO” (e.g. repository vs full_repository_name)? It’s been always confusing to me when to use which…
I got this working with the following configuration:
Configure a fine-grained PAT with
secrets.writepermission.GitHub Actions Workflow:
main.tf
secret.tf
Note: I tried to get this working with the built in GitHub Actions
GITHUB_TOKENbut was getting the response:403 Resource not accessible by integration []Unfortunately, there doesn’t seem to be a way to assign
secrets.writeto theGITHUB_TOKEN. Ideally, I’d like to avoid using a PAT as it’s another secret to manage (it’ll expire and will need rotating).hey all; after combing through the different replies here, and trying a bunch of different things, I simplest way I could get this to work is to leave the
providerconfig empty, and just pass these two env vars when calling theterraformCLI:GITHUB_OWNER=<gh org name> GITHUB_TOKEN=<gh access token> terraform applyThere are, ofc, different ways to achieve this, but I just wanted to leave this as a one-line copy/paste-able workaround to this problem. hope it helps others until the underlying issue is fixed.
Migrating to
integrations/githubfromhashicorp/githuband using latest does not seem to resolve this issue. Did anyone have any recent success?I’m using PAT that generated from org owner account, I’m trying to use TF to push and manage orgnization secret for one private repo github actions, below is how I get it working. I noticed there is a Warning message from terraform when I used organization in my provider block. The message said:
Warning: “organization”: [DEPRECATED] Use owner (or GITHUB_OWNER) instead of organization (or GITHUB_ORGANIZATION) │ │ with provider[“registry.terraform.io/integrations/github”], │ on providers.tf line 237, in provider “github”: │ 237: provider “github” {
So I followed the warning, instead of using organization I used GITHUB_ORGANIZATION. so my provider block looks like this: provider “github” { GITHUB_ORGANIZATION = var.github_org token = (sensitive(aws_ssm_parameter.githubtfctoken.value)) } my resource block looks like this: data “github_repository” “my_private_repo” { full_name = “<org_name>/<my_private_repo_name>” }
resource “github_actions_organization_secret” “org_secret_test” { secret_name = “terraform_test” visibility = “selected” encrypted_value = “terraformtestsecretvalue” selected_repository_ids = [data.github_repository.my_private_repo.repo_id] }
I checked from github actions on that repo and found this secret created there:
Hi, is there a work around for this as I am getting the double slash in my get request url when using the github_actions_secret resource and I’ve not found a way to fix it.
I can swear that I had this working yesterday but I changed my terraform module structure and now there’s a double slash there 😦
I can confirm @paullatzelsperger’s observation:
just found out that there may be a typo in the terraform provider. Terraform reports an error:
GET https://api.github.com/repos//<ORG>/<REPO>/actions/secrets/public-keynote the double forward slashes. They get added, regardless whether I prefix therepositorystring or not.