It is not possible to create a new project mirroring an external repository with a default branch that does not exist in the external repository.
Bug Report
On creation of a new project using mirroring with a default branch not existing in the mirrored repository, the default branch will not correctly be set (nor will mirror correctly be set to true, but at least this is fixed on a second run of terraform if it doesn't fail for other reasons). However on subsequent runs the adjustment of the default branch will fail as the branch does not exist.
Further there is no way to add pull mirroring to a project other than in the project resource and no way to manage the default branch other than the project resource meaning it is not possible to adjust either of these properties in a manner that can be repeatable via terraform without external management or multiple iterations.
Relevant Terraform Configuration
resource "gitlab_project" "project" {
name = "example"
description = "example"
default_branch = "example"
import_url = "https://gitlab.com/gitlab-org/terraform-provider-gitlab.git"
mirror = true
only_mirror_protected_branches = true
}
Relevant Terraform Command
terraform apply
Relevant Log Output
╷
│ Error: PUT https://gitlab.com/api/v4/projects/******: 400 {message: {base: [Could not change HEAD: branch 'example' does not exist]}}
│
│ with gitlab_project.project,
│ on test.tf line 14, in resource "gitlab_project" "project":
│ 14: resource "gitlab_project" "project" {
│
- GitLab Terraform Provider Version:
17.9.0 - GitLab Instance Version:
17.9 - Terraform Version:
1.11.1
Edited by 🤖 GitLab Bot 🤖