Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup for required_approval_count in gitlab_project_protected_environment #1097

Merged
merged 1 commit into from Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions docs/resources/project_protected_environment.md
Expand Up @@ -24,8 +24,9 @@ resource "gitlab_project_environment" "this" {

# Example with access level
resource "gitlab_project_protected_environment" "example_with_access_level" {
project = gitlab_project_environment.this.project
environment = gitlab_project_environment.this.name
project = gitlab_project_environment.this.project
required_approval_count = 1
environment = gitlab_project_environment.this.name

deploy_access_levels {
access_level = "developer"
Expand Down Expand Up @@ -54,8 +55,9 @@ resource "gitlab_project_protected_environment" "example_with_user" {

# Example with multiple access levels
resource "gitlab_project_protected_environment" "example_with_multiple" {
project = gitlab_project_environment.this.project
environment = gitlab_project_environment.this.name
project = gitlab_project_environment.this.project
required_approval_count = 2
environment = gitlab_project_environment.this.name

deploy_access_levels {
access_level = "developer"
Expand All @@ -80,6 +82,10 @@ resource "gitlab_project_protected_environment" "example_with_multiple" {
- `environment` (String) The name of the environment.
- `project` (String) The ID or full path of the project which the protected environment is created against.

### Optional

- `required_approval_count` (Number) The number of approvals required to deploy to this environment.

### Read-Only

- `id` (String) The ID of this resource.
Expand Down
Expand Up @@ -6,8 +6,9 @@ resource "gitlab_project_environment" "this" {

# Example with access level
resource "gitlab_project_protected_environment" "example_with_access_level" {
project = gitlab_project_environment.this.project
environment = gitlab_project_environment.this.name
project = gitlab_project_environment.this.project
required_approval_count = 1
environment = gitlab_project_environment.this.name

deploy_access_levels {
access_level = "developer"
Expand Down Expand Up @@ -36,8 +37,9 @@ resource "gitlab_project_protected_environment" "example_with_user" {

# Example with multiple access levels
resource "gitlab_project_protected_environment" "example_with_multiple" {
project = gitlab_project_environment.this.project
environment = gitlab_project_environment.this.name
project = gitlab_project_environment.this.project
required_approval_count = 2
environment = gitlab_project_environment.this.name

deploy_access_levels {
access_level = "developer"
Expand Down
17 changes: 11 additions & 6 deletions internal/provider/resource_gitlab_project_protected_environment.go
Expand Up @@ -38,12 +38,12 @@ var _ = registerResource("gitlab_project_protected_environment", func() *schema.
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
// Uncomment and validate after 14.9 is released, update acceptance tests
// "required_approval_count": {
// Description: "The number of approvals required to deploy to this environment.",
// Type: schema.TypeInt,
// ForceNew: true,
// },
"required_approval_count": {
Description: "The number of approvals required to deploy to this environment.",
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"deploy_access_levels": {
Description: "Array of access levels allowed to deploy, with each described by a hash.",
Type: schema.TypeList,
Expand Down Expand Up @@ -96,6 +96,10 @@ func resourceGitlabProjectProtectedEnvironmentCreate(ctx context.Context, d *sch
DeployAccessLevels: &deployAccessLevels,
}

if v, ok := d.GetOk("required_approval_count"); ok {
options.RequiredApprovalCount = gitlab.Int(v.(int))
}

project := d.Get("project").(string)

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

if err := d.Set("deploy_access_levels", flattenDeployAccessLevels(protectedEnvironment.DeployAccessLevels)); err != nil {
return diag.Errorf("error setting deploy_access_levels: %v", err)
Expand Down
Expand Up @@ -65,6 +65,7 @@ func TestAccGitlabProjectProtectedEnvironment_basic(t *testing.T) {
resource "gitlab_project_protected_environment" "this" {
project = %d
environment = %q
required_approval_count = 1
deploy_access_levels {
access_level = "maintainer"
}
Expand All @@ -83,6 +84,8 @@ func TestAccGitlabProjectProtectedEnvironment_basic(t *testing.T) {
// access_level is computed when not specified.
resource.TestCheckResourceAttrSet("gitlab_project_protected_environment.this", "deploy_access_levels.1.access_level"),
resource.TestCheckResourceAttrSet("gitlab_project_protected_environment.this", "deploy_access_levels.2.access_level"),
// required_approval_count is set.
resource.TestCheckResourceAttrSet("gitlab_project_protected_environment.this", "required_approval_count"),
),
},
// Verify upstream attributes with an import.
Expand Down