From b4a09f091abe5c852001c1a3af87e7259de50154 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 4 Jan 2023 09:17:39 -0800 Subject: [PATCH 1/3] Flip boolean packing/unpacking of block_deployments_on_limit Project API's value is opposite of this attribute (and web UI as well). Add update and import tests --- pkg/project/resource_project.go | 8 ++--- pkg/project/resource_project_test.go | 44 ++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/pkg/project/resource_project.go b/pkg/project/resource_project.go index fa302b4b..a9026c4e 100644 --- a/pkg/project/resource_project.go +++ b/pkg/project/resource_project.go @@ -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, @@ -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, @@ -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, @@ -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, @@ -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), } @@ -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{ diff --git a/pkg/project/resource_project_test.go b/pkg/project/resource_project_test.go index 4f26e197..caf15343 100644 --- a/pkg/project/resource_project_test.go +++ b/pkg/project/resource_project_test.go @@ -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) @@ -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 }}" @@ -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() { @@ -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, + }, }, }) } From 0a2e96d54cc4bb8f8b150d493c0abf974313d690 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 4 Jan 2023 09:19:53 -0800 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0deaa4d9..d81324ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.1.13 (Jan 5, 2023) + +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: From 8ee9e69abf9a07238bacb1e88bcb9ac3ded5a5c2 Mon Sep 17 00:00:00 2001 From: JFrog CI Date: Wed, 4 Jan 2023 17:46:48 +0000 Subject: [PATCH 3/3] JFrog Pipelines - Add Artifactory and Xray versions to CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d81324ca..4a8421e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.1.13 (Jan 5, 2023) +## 1.1.13 (Jan 5, 2023). Tested on Artifactory 7.49.3 and Xray 3.63.2 BUG FIXES: