Skip to content

Commit 98c5fb8

Browse files
committed
Catch 404 status for when default branch doesn't exist
This can happen when default_branch or initialize_with_readme are not set (or the initialize is set to false explicitly) as the branch doesn't exist until first commit.
1 parent cd232fe commit 98c5fb8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/provider/resource_gitlab_project.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,16 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
629629
Target: []string{"true"},
630630
Timeout: 2 * time.Minute, //The async action usually completes very quickly, within seconds. Don't wait too long.
631631
Refresh: func() (interface{}, string, error) {
632-
branch, _, err := client.Branches.GetBranch(project.ID, project.DefaultBranch, gitlab.WithContext(ctx))
632+
branch, response, err := client.Branches.GetBranch(project.ID, project.DefaultBranch, gitlab.WithContext(ctx))
633633
if err != nil {
634+
if response.StatusCode == 404 {
635+
// When we hit a 404 here, it means the default branch wasn't created at all as part of the project
636+
// this will happen when "default_branch" isn't set, or "initialize_with_readme" is set to false.
637+
// We don't need to wait anymore, so return "true" to exist the wait loop.
638+
return branch, "true", nil
639+
}
640+
641+
//This is legit error, return the error.
634642
return nil, "", err
635643
}
636644

0 commit comments

Comments
 (0)