Skip to content

Commit

Permalink
Merge pull request #67 from jfrog/GH-62-fix-block-deployments-on-limit
Browse files Browse the repository at this point in the history
Flip boolean packing/unpacking of block_deployments_on_limit
  • Loading branch information
alexhung authored Jan 4, 2023
2 parents 58e1c62 + 8ee9e69 commit edb5a72
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.1.13 (Jan 5, 2023). Tested on Artifactory 7.49.3 and Xray 3.63.2

BUG FIXES:

* resource/project: Fix `block_deployments_on_limit` attribute value opposite to Artifactory Project web UI. Issue: [#62](https://github.com/jfrog/terraform-provider-project/issues/62) PR: [#67](https://github.com/jfrog/terraform-provider-project/pull/67)

## 1.1.12 (Dec 22, 2022). Tested on Artifactory 7.47.14 and Xray 3.62.4

BUG FIXES:
Expand Down
8 changes: 2 additions & 6 deletions pkg/project/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func projectResource() *schema.Resource {
Default: false,
Description: "Alerts will be sent when reaching 75% and 95% of the storage quota. This serves as a notification only and is not a blocker",
},

"member": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -150,7 +149,6 @@ func projectResource() *schema.Resource {
},
Description: "Member of the project. Element has one to one mapping with the [JFrog Project Users API](https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-UpdateUserinProject).",
},

"group": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -172,7 +170,6 @@ func projectResource() *schema.Resource {
},
Description: "Project group. Element has one to one mapping with the [JFrog Project Groups API](https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-UpdateGroupinProject)",
},

"role": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -212,7 +209,6 @@ func projectResource() *schema.Resource {
},
Description: "Project role. Element has one to one mapping with the [JFrog Project Roles API](https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-AddaNewRole)",
},

"repos": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -232,7 +228,7 @@ func projectResource() *schema.Resource {
DisplayName: d.GetString("display_name", false),
Description: d.GetString("description", false),
StorageQuota: GibibytesToBytes(d.GetInt("max_storage_in_gibibytes", false)),
SoftLimit: d.GetBool("block_deployments_on_limit", false),
SoftLimit: !d.GetBool("block_deployments_on_limit", false),
QuotaEmailNotification: d.GetBool("email_notification", false),
}

Expand Down Expand Up @@ -268,7 +264,7 @@ func projectResource() *schema.Resource {
setValue("display_name", project.DisplayName)
setValue("description", project.Description)
setValue("max_storage_in_gibibytes", BytesToGibibytes(project.StorageQuota))
setValue("block_deployments_on_limit", project.SoftLimit)
setValue("block_deployments_on_limit", !project.SoftLimit)
errors = setValue("email_notification", project.QuotaEmailNotification)
errors = setValue("admin_privileges", []interface{}{
map[string]bool{
Expand Down
44 changes: 41 additions & 3 deletions pkg/project/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestAccProjectUpdateKey(t *testing.T) {
})
}

func TestAccProject(t *testing.T) {
func TestAccProject_full(t *testing.T) {
name := fmt.Sprintf("tftestprojects%s", randSeq(10))
resourceName := fmt.Sprintf("project.%s", name)

Expand Down Expand Up @@ -204,7 +204,7 @@ func TestAccProject(t *testing.T) {
"repo2": repo2,
}

project := test.ExecuteTemplate("TestAccProjects", `
template := `
resource "project" "{{ .name }}" {
key = "{{ .project_key }}"
display_name = "{{ .name }}"
Expand Down Expand Up @@ -256,7 +256,27 @@ func TestAccProject(t *testing.T) {
repos = ["{{ .repo1 }}", "{{ .repo2 }}"]
}
`, params)
`

project := test.ExecuteTemplate("TestAccProjects", template, params)

updateParams := map[string]interface{}{
"max_storage_in_gibibytes": params["max_storage_in_gibibytes"],
"block_deployments_on_limit": !params["block_deployments_on_limit"].(bool),
"email_notification": !params["email_notification"].(bool),
"manage_members": !params["manage_members"].(bool),
"manage_resources": !params["manage_resources"].(bool),
"index_resources": !params["index_resources"].(bool),
"name": params["name"],
"project_key": params["project_key"],
"username1": params["username1"],
"username2": params["username2"],
"group1": params["group1"],
"group2": params["group2"],
"repo1": params["repo1"],
"repo2": params["repo2"],
}
projectUpdated := test.ExecuteTemplate("TestAccProjects", template, updateParams)

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -313,6 +333,24 @@ func TestAccProject(t *testing.T) {
resource.TestCheckTypeSetElemAttr(resourceName, "repos.*", repo2),
),
},
{
Config: projectUpdated,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "key", fmt.Sprintf("%s", updateParams["project_key"])),
resource.TestCheckResourceAttr(resourceName, "display_name", name),
resource.TestCheckResourceAttr(resourceName, "max_storage_in_gibibytes", fmt.Sprintf("%d", updateParams["max_storage_in_gibibytes"])),
resource.TestCheckResourceAttr(resourceName, "block_deployments_on_limit", fmt.Sprintf("%t", updateParams["block_deployments_on_limit"])),
resource.TestCheckResourceAttr(resourceName, "email_notification", fmt.Sprintf("%t", updateParams["email_notification"])),
resource.TestCheckResourceAttr(resourceName, "admin_privileges.0.manage_members", fmt.Sprintf("%t", updateParams["manage_members"])),
resource.TestCheckResourceAttr(resourceName, "admin_privileges.0.manage_resources", fmt.Sprintf("%t", updateParams["manage_resources"])),
resource.TestCheckResourceAttr(resourceName, "admin_privileges.0.index_resources", fmt.Sprintf("%t", updateParams["index_resources"])),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

0 comments on commit edb5a72

Please sign in to comment.