Skip to content

Commit 40a06bf

Browse files
authored
Merge pull request #1097 from thenom/add-protected-env-approvers
Setup for required_approval_count in gitlab_project_protected_environment
2 parents 5b3eaef + f58e44a commit 40a06bf

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

docs/resources/project_protected_environment.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ resource "gitlab_project_environment" "this" {
2424
2525
# Example with access level
2626
resource "gitlab_project_protected_environment" "example_with_access_level" {
27-
project = gitlab_project_environment.this.project
28-
environment = gitlab_project_environment.this.name
27+
project = gitlab_project_environment.this.project
28+
required_approval_count = 1
29+
environment = gitlab_project_environment.this.name
2930
3031
deploy_access_levels {
3132
access_level = "developer"
@@ -54,8 +55,9 @@ resource "gitlab_project_protected_environment" "example_with_user" {
5455
5556
# Example with multiple access levels
5657
resource "gitlab_project_protected_environment" "example_with_multiple" {
57-
project = gitlab_project_environment.this.project
58-
environment = gitlab_project_environment.this.name
58+
project = gitlab_project_environment.this.project
59+
required_approval_count = 2
60+
environment = gitlab_project_environment.this.name
5961
6062
deploy_access_levels {
6163
access_level = "developer"
@@ -80,6 +82,10 @@ resource "gitlab_project_protected_environment" "example_with_multiple" {
8082
- `environment` (String) The name of the environment.
8183
- `project` (String) The ID or full path of the project which the protected environment is created against.
8284

85+
### Optional
86+
87+
- `required_approval_count` (Number) The number of approvals required to deploy to this environment.
88+
8389
### Read-Only
8490

8591
- `id` (String) The ID of this resource.

examples/resources/gitlab_project_protected_environment/resource.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ resource "gitlab_project_environment" "this" {
66

77
# Example with access level
88
resource "gitlab_project_protected_environment" "example_with_access_level" {
9-
project = gitlab_project_environment.this.project
10-
environment = gitlab_project_environment.this.name
9+
project = gitlab_project_environment.this.project
10+
required_approval_count = 1
11+
environment = gitlab_project_environment.this.name
1112

1213
deploy_access_levels {
1314
access_level = "developer"
@@ -36,8 +37,9 @@ resource "gitlab_project_protected_environment" "example_with_user" {
3637

3738
# Example with multiple access levels
3839
resource "gitlab_project_protected_environment" "example_with_multiple" {
39-
project = gitlab_project_environment.this.project
40-
environment = gitlab_project_environment.this.name
40+
project = gitlab_project_environment.this.project
41+
required_approval_count = 2
42+
environment = gitlab_project_environment.this.name
4143

4244
deploy_access_levels {
4345
access_level = "developer"

internal/provider/resource_gitlab_project_protected_environment.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ var _ = registerResource("gitlab_project_protected_environment", func() *schema.
3838
Required: true,
3939
ValidateFunc: validation.StringIsNotEmpty,
4040
},
41-
// Uncomment and validate after 14.9 is released, update acceptance tests
42-
// "required_approval_count": {
43-
// Description: "The number of approvals required to deploy to this environment.",
44-
// Type: schema.TypeInt,
45-
// ForceNew: true,
46-
// },
41+
"required_approval_count": {
42+
Description: "The number of approvals required to deploy to this environment.",
43+
Type: schema.TypeInt,
44+
Optional: true,
45+
ForceNew: true,
46+
},
4747
"deploy_access_levels": {
4848
Description: "Array of access levels allowed to deploy, with each described by a hash.",
4949
Type: schema.TypeList,
@@ -96,6 +96,10 @@ func resourceGitlabProjectProtectedEnvironmentCreate(ctx context.Context, d *sch
9696
DeployAccessLevels: &deployAccessLevels,
9797
}
9898

99+
if v, ok := d.GetOk("required_approval_count"); ok {
100+
options.RequiredApprovalCount = gitlab.Int(v.(int))
101+
}
102+
99103
project := d.Get("project").(string)
100104

101105
log.Printf("[DEBUG] Project %s create gitlab protected environment %q", project, *options.Name)
@@ -137,6 +141,7 @@ func resourceGitlabProjectProtectedEnvironmentRead(ctx context.Context, d *schem
137141
}
138142
return diag.Errorf("error getting gitlab project %q protected environment %q: %v", project, environment, err)
139143
}
144+
d.Set("required_approval_count", protectedEnvironment.RequiredApprovalCount)
140145

141146
if err := d.Set("deploy_access_levels", flattenDeployAccessLevels(protectedEnvironment.DeployAccessLevels)); err != nil {
142147
return diag.Errorf("error setting deploy_access_levels: %v", err)

internal/provider/resource_gitlab_project_protected_environment_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestAccGitlabProjectProtectedEnvironment_basic(t *testing.T) {
6565
resource "gitlab_project_protected_environment" "this" {
6666
project = %d
6767
environment = %q
68+
required_approval_count = 1
6869
deploy_access_levels {
6970
access_level = "maintainer"
7071
}
@@ -83,6 +84,8 @@ func TestAccGitlabProjectProtectedEnvironment_basic(t *testing.T) {
8384
// access_level is computed when not specified.
8485
resource.TestCheckResourceAttrSet("gitlab_project_protected_environment.this", "deploy_access_levels.1.access_level"),
8586
resource.TestCheckResourceAttrSet("gitlab_project_protected_environment.this", "deploy_access_levels.2.access_level"),
87+
// required_approval_count is set.
88+
resource.TestCheckResourceAttrSet("gitlab_project_protected_environment.this", "required_approval_count"),
8689
),
8790
},
8891
// Verify upstream attributes with an import.

0 commit comments

Comments
 (0)