-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Description
Problem
When creating a new repository via Terraform, the github_branch_default resource fails because the repo is empty (no commits/branches yet):
Error: PATCH https://api.github.com/repos/infrahouse/terraform-aws-percona-server: 422 Validation Failed
[{Resource:Repository Field:default_branch Code:invalid Message:Cannot update default branch for an empty repository. Please init the repository and push first.}]
with module.repos["terraform-aws-percona-server"].github_branch_default.main,
on modules/plain-repo/repos.tf line 45, in resource "github_branch_default" "main":
45: resource "github_branch_default" "main" {
The github_repository_file resources create files, but the github_branch_default resource runs before the branch actually exists.
Proposed Solution
Create repos from a template repository that already has an initial commit. This ensures:
- The
mainbranch exists from the start github_branch_defaultcan successfully set the default branch- Subsequent
github_repository_fileresources can commit to the existing branch
Related
- Template repo already exists:
terraform-template(moduleih_tf_templatein repos.tf) - The
plain-repomodule would need to usetemplateargument ingithub_repositoryresource
Workaround
Currently requires manual intervention: re-run terraform apply after the initial files are pushed.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request