The gitlab_project_approval_rule
resource allows to manage the lifecycle of a project-level approval rule.
Upstream API: GitLab REST API docs
resource "gitlab_project_approval_rule" "example-one" {
project = 5
name = "Example Rule"
approvals_required = 3
user_ids = [50, 500]
group_ids = [51]
}
# With Protected Branch IDs
resource "gitlab_branch_protection" "example" {
project = 5
branch = "release/*"
push_access_level = "maintainer"
merge_access_level = "developer"
}
resource "gitlab_project_approval_rule" "example-two" {
project = 5
name = "Example Rule 2"
approvals_required = 3
user_ids = [50, 500]
group_ids = [51]
protected_branch_ids = [gitlab_branch_protection.example.branch_protection_id]
}
# Example using `data.gitlab_user` and `for` loop
data "gitlab_user" "users" {
for_each = toset(["user1", "user2", "user3"])
username = each.value
}
resource "gitlab_project_approval_rule" "example-three" {
project = 5
name = "Example Rule 3"
approvals_required = 3
user_ids = [for user in data.gitlab_user.users : user.id]
}
# Example using `approval_rule` using `any_approver` as rule type
resource "gitlab_project_approval_rule" "any_approver" {
project = 5
name = "Any name"
rule_type = "any_approver"
approvals_required = 1
}
# Example using `applies_to_all_protected_branches`
resource "gitlab_project_approval_rule" "example-four" {
project = 5
name = "Example Rule 4"
approvals_required = 3
user_ids = [50, 500]
group_ids = [51]
applies_to_all_protected_branches = true
}
approvals_required
(Number) The number of approvals required for this rule.name
(String) The name of the approval rule.project
(String) The name or id of the project to add the approval rules.applies_to_all_protected_branches
(Boolean) Whether the rule is applied to all protected branches. If set to 'true', the value of protected_branch_ids
is ignored. Default is 'false'.disable_importing_default_any_approver_rule_on_create
(Boolean) When this flag is set, the default any_approver
rule will not be imported if present.group_ids
(Set of Number) A list of group IDs whose members can approve of the merge request.protected_branch_ids
(Set of Number) A list of protected branch IDs (not branch names) for which the rule applies.rule_type
(String) String, defaults to 'regular'. The type of rule. any_approver
is a pre-configured default rule with approvals_required
at 0
. Valid values are regular
, any_approver
.user_ids
(Set of Number) A list of specific User IDs to add to the list of approvers.id
(String) The ID of this resource.Import is supported using the following syntax:
# GitLab project approval rules can be imported using a key composed of `<project-id>:<rule-id>`, e.g.
terraform import gitlab_project_approval_rule.example "12345:6"