Skip to content

Commit 5c48c36

Browse files
beekeeptimofurrer
authored andcommitted
Add default branch protection workaround text to project
Added documentation to the `gitlab_project` resource describing a workaround to allow Terraform to manage the default branch protection on a project.
1 parent 5bc59f0 commit 5c48c36

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/resources/project.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ subcategory: ""
55
description: |-
66
The gitlab_project resource allows to manage the lifecycle of a project.
77
A project can either be created in a group or user namespace.
8+
-> Default Branch Protection Workaround Projects are created with default branch protection.
9+
Since this default branch protection is not currently managed via Terraform, to workaround this limitation,
10+
you can remove the default branch protection via the API and create your desired Terraform managed branch protection.
11+
In the gitlab_project resource, define a local-exec provisioner which invokes
12+
the /projects/:id/protected_branches/:name API via curl to delete the branch protection on the default
13+
branch using a DELETE request. Then define the desired branch protection using the gitlab_branch_protection resource.
814
Upstream API: GitLab REST API docs https://docs.gitlab.com/ce/api/projects.html
915
---
1016

@@ -14,6 +20,13 @@ The `gitlab_project` resource allows to manage the lifecycle of a project.
1420

1521
A project can either be created in a group or user namespace.
1622

23+
-> **Default Branch Protection Workaround** Projects are created with default branch protection.
24+
Since this default branch protection is not currently managed via Terraform, to workaround this limitation,
25+
you can remove the default branch protection via the API and create your desired Terraform managed branch protection.
26+
In the `gitlab_project` resource, define a `local-exec` provisioner which invokes
27+
the `/projects/:id/protected_branches/:name` API via curl to delete the branch protection on the default
28+
branch using a `DELETE` request. Then define the desired branch protection using the `gitlab_branch_protection` resource.
29+
1730
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ce/api/projects.html)
1831

1932
## Example Usage

internal/provider/resource_gitlab_project.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,13 @@ var _ = registerResource("gitlab_project", func() *schema.Resource {
644644
645645
A project can either be created in a group or user namespace.
646646
647+
-> **Default Branch Protection Workaround** Projects are created with default branch protection.
648+
Since this default branch protection is not currently managed via Terraform, to workaround this limitation,
649+
you can remove the default branch protection via the API and create your desired Terraform managed branch protection.
650+
In the ` + "`gitlab_project`" + ` resource, define a ` + "`local-exec`" + ` provisioner which invokes
651+
the ` + "`/projects/:id/protected_branches/:name`" + ` API via curl to delete the branch protection on the default
652+
branch using a ` + "`DELETE`" + ` request. Then define the desired branch protection using the ` + "`gitlab_branch_protection`" + ` resource.
653+
647654
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ce/api/projects.html)`,
648655

649656
CreateContext: resourceGitlabProjectCreate,

0 commit comments

Comments
 (0)