terraform-provider-github
terraform-provider-github copied to clipboard
422 when creating repository and branch
Hello all,
I searched around a little but didn't see this issue reported already. If it is already reported, please link the original here - thanks!
Terraform Version
1.2.9
Affected Resource(s)
- github_repository
- github_branch
Terraform Configuration Files
terraform {
required_providers {
github = {
source = "integrations/github"
version = "4.31.0"
}
}
}
terraform {
required_version = "1.2.9"
}
variable "GITHUB_TOKEN" {
type = string
sensitive = true
description = "A GitHub access token with owner/admin rights over the repositories managed by terraform"
}
provider "github" {
token = var.GITHUB_TOKEN
owner = "*********" // Redacted for the purposes of this issue report
}
resource "github_repository" "repo-base" {
name = "test-repo"
visibility = "private"
gitignore_template = "Python"
}
resource "github_branch" "main" {
repository = github_repository.repo-base.name
branch = "main"
}
Expected Behavior
I would expect that a repository would be created successfully
Actual Behavior
I get the following error message:
│ Error: Error creating GitHub branch reference ****/test-repo (refs/heads/main): POST https://api.github.com/repos/****/test-repo/git/refs: 422 Reference already exists []
Steps to Reproduce
- Copy the above code snippet to a
.tffile - Run
terraform apply
Important Factoids
This applies specifically when:
- The branch used matches the new repository's default branch, in this case
main - The gitignore_template is used As far as I can understand it, the gitignore_template field tells terraform to create the default branch and add the .gitignore file on it but does not notify terraform that the branch is created. Then terraform goes to create the branch and fails because it now exists.