From 442da39805506ba9f981502e916ac230d981f5e6 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 18 Dec 2024 11:30:57 -0800 Subject: [PATCH 1/3] Fix xray_webhook headers not being imported correctly --- GNUmakefile | 2 +- pkg/xray/resource/resource_xray_webhook.go | 21 ++++---- .../resource/resource_xray_webhook_test.go | 52 +++++++++---------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index ccd5a01e..fb9533b3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -54,7 +54,7 @@ attach: acceptance: fmt export TF_ACC=true && \ - go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}/provider.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 45m ./pkg/... + go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}/provider.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 1h ./pkg/... # To generate coverage.txt run `make acceptance` first coverage: diff --git a/pkg/xray/resource/resource_xray_webhook.go b/pkg/xray/resource/resource_xray_webhook.go index d63f6cfd..7e5874f6 100644 --- a/pkg/xray/resource/resource_xray_webhook.go +++ b/pkg/xray/resource/resource_xray_webhook.go @@ -202,28 +202,31 @@ func (r *WebhookResource) Read(ctx context.Context, req resource.ReadRequest, re state.Name = types.StringValue(webhook.Name) - if state.Description.IsNull() { - state.Description = types.StringValue("") - } + description := types.StringNull() if len(webhook.Description) > 0 { - state.Description = types.StringValue(webhook.Description) + description = types.StringValue(webhook.Description) } + state.Description = description state.URL = types.StringValue(webhook.URL) state.UseProxy = types.BoolValue(webhook.UseProxy) - if !state.UserName.IsNull() { - state.UserName = types.StringValue(webhook.UserName) + username := types.StringNull() + if len(webhook.UserName) > 0 { + username = types.StringValue(webhook.UserName) } + state.UserName = username - if !state.Headers.IsNull() { - headers, ds := types.MapValueFrom(ctx, types.StringType, webhook.Headers) + headers := types.MapNull(types.StringType) + if len(webhook.Headers) > 0 { + hs, ds := types.MapValueFrom(ctx, types.StringType, webhook.Headers) if ds.HasError() { resp.Diagnostics.Append(ds...) return } - state.Headers = headers + headers = hs } + state.Headers = headers // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) diff --git a/pkg/xray/resource/resource_xray_webhook_test.go b/pkg/xray/resource/resource_xray_webhook_test.go index f373591f..6453dd91 100644 --- a/pkg/xray/resource/resource_xray_webhook_test.go +++ b/pkg/xray/resource/resource_xray_webhook_test.go @@ -82,6 +82,23 @@ func TestAccWebhook_full(t *testing.T) { url := fmt.Sprintf("https://tempurl%d.org", testutil.RandomInt()) const template = ` + resource "xray_webhook" "{{ .name }}" { + name = "{{ .name }}" + description = "{{ .description }}" + url = "{{ .url }}" + use_proxy = "{{ .use_proxy }}" + } + ` + testData := map[string]string{ + "name": resourceName, + "description": "test description 2", + "url": url, + "use_proxy": "false", + } + + config := util.ExecuteTemplate("TestAccWebhook_full", template, testData) + + const updateTemplate = ` resource "xray_webhook" "{{ .name }}" { name = "{{ .name }}" description = "{{ .description }}" @@ -96,7 +113,7 @@ func TestAccWebhook_full(t *testing.T) { } } ` - testData := map[string]string{ + updatedTestData := map[string]string{ "name": resourceName, "description": "test description", "url": url, @@ -108,23 +125,6 @@ func TestAccWebhook_full(t *testing.T) { "header2_name": "header2_name", "header2_value": "header2_value", } - - config := util.ExecuteTemplate("TestAccWebhook_full", template, testData) - - const updateTemplate = ` - resource "xray_webhook" "{{ .name }}" { - name = "{{ .name }}" - description = "{{ .description }}" - url = "{{ .url }}" - use_proxy = "{{ .use_proxy }}" - } - ` - updatedTestData := map[string]string{ - "name": resourceName, - "description": "test description 2", - "url": url, - "use_proxy": "false", - } updatedConfig := util.ExecuteTemplate("TestAccWebhook_full", updateTemplate, updatedTestData) resource.Test(t, resource.TestCase{ @@ -138,11 +138,9 @@ func TestAccWebhook_full(t *testing.T) { resource.TestCheckResourceAttr(fqrn, "description", testData["description"]), resource.TestCheckResourceAttr(fqrn, "url", testData["url"]), resource.TestCheckResourceAttr(fqrn, "use_proxy", testData["use_proxy"]), - resource.TestCheckResourceAttr(fqrn, "user_name", testData["user_name"]), - resource.TestCheckResourceAttr(fqrn, "password", testData["password"]), - resource.TestCheckResourceAttr(fqrn, "headers.%", "2"), - resource.TestCheckResourceAttr(fqrn, "headers.header1_name", testData["header1_value"]), - resource.TestCheckResourceAttr(fqrn, "headers.header2_name", testData["header2_value"]), + resource.TestCheckNoResourceAttr(fqrn, "user_name"), + resource.TestCheckNoResourceAttr(fqrn, "password"), + resource.TestCheckNoResourceAttr(fqrn, "headers.%"), ), }, { @@ -152,9 +150,11 @@ func TestAccWebhook_full(t *testing.T) { resource.TestCheckResourceAttr(fqrn, "description", updatedTestData["description"]), resource.TestCheckResourceAttr(fqrn, "url", updatedTestData["url"]), resource.TestCheckResourceAttr(fqrn, "use_proxy", updatedTestData["use_proxy"]), - resource.TestCheckNoResourceAttr(fqrn, "user_name"), - resource.TestCheckNoResourceAttr(fqrn, "password"), - resource.TestCheckNoResourceAttr(fqrn, "headers.%"), + resource.TestCheckResourceAttr(fqrn, "user_name", updatedTestData["user_name"]), + resource.TestCheckResourceAttr(fqrn, "password", updatedTestData["password"]), + resource.TestCheckResourceAttr(fqrn, "headers.%", "2"), + resource.TestCheckResourceAttr(fqrn, "headers.header1_name", updatedTestData["header1_value"]), + resource.TestCheckResourceAttr(fqrn, "headers.header2_name", updatedTestData["header2_value"]), ), ConfigPlanChecks: testutil.ConfigPlanChecks(""), }, From 2916316100de5f230cb990a7294a7ec384196e34 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 18 Dec 2024 11:31:39 -0800 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0db27be..f05cc736 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 3.0.3 (December 19, 2024) + +BUG FIXES: + +* resource/xray_webhook: Fix `headers` attribute not being imported correctly. Issue: [#290](https://github.com/jfrog/terraform-provider-xray/issues/290) PR: [#291](https://github.com/jfrog/terraform-provider-xray/issues/291) + ## 3.0.2 (December 5, 2024). Tested on Artifactory 7.98.9 and Xray 3.107.16 with Terraform 1.10.1 and OpenTofu 1.8.7 BUG FIXES: From 2d2edddd2b444dd6de0b379357f71efd79164d29 Mon Sep 17 00:00:00 2001 From: JFrog CI Date: Wed, 18 Dec 2024 20:09:39 +0000 Subject: [PATCH 3/3] JFrog Pipelines - Add Artifactory version to CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05cc736..9bebaed4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.0.3 (December 19, 2024) +## 3.0.3 (December 19, 2024). Tested on Artifactory 7.98.11 and Xray 3.107.18 with Terraform 1.10.3 and OpenTofu 1.8.7 BUG FIXES: