From d8593d245940714d390fe2f9515ac99518408b08 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Mon, 2 Dec 2024 10:27:38 -0800 Subject: [PATCH 1/4] Fix "Value Conversion Error" for saml_settings --- pkg/platform/resource_saml_settings.go | 14 ++++--- pkg/platform/resource_saml_settings_test.go | 42 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/pkg/platform/resource_saml_settings.go b/pkg/platform/resource_saml_settings.go index 6423fb2..08d58f8 100644 --- a/pkg/platform/resource_saml_settings.go +++ b/pkg/platform/resource_saml_settings.go @@ -86,11 +86,13 @@ func (r *SAMLSettingsResourceModelV1) toAPIModel(ctx context.Context, apiModel * apiModel.VerifyAudienceRestriction = r.VerifyAudienceRestriction.ValueBool() apiModel.UseEncryptedAssertion = r.UseEncryptedAssertion.ValueBool() - var ldapGroupSettings []string - d := r.LDAPGroupSettings.ElementsAs(ctx, &ldapGroupSettings, false) - if d.HasError() { - diags.Append(d...) - return diags + ldapGroupSettings := []string{} // API treats absent or null value as noop so needs empty array to reset + if !r.LDAPGroupSettings.IsNull() { + d := r.LDAPGroupSettings.ElementsAs(ctx, &ldapGroupSettings, false) + if d.HasError() { + diags.Append(d...) + return diags + } } apiModel.LDAPGroupSettings = ldapGroupSettings @@ -159,7 +161,7 @@ type SAMLSettingsAPIModel struct { GroupAttribute string `json:"group_attribute"` EmailAttribute string `json:"email_attribute"` NameIDAttribute string `json:"name_id_attribute"` - LDAPGroupSettings []string `json:"ldap_group_settings,omitempty"` + LDAPGroupSettings []string `json:"ldap_group_settings"` } var samlSettingsSchemaV0 = map[string]schema.Attribute{ diff --git a/pkg/platform/resource_saml_settings_test.go b/pkg/platform/resource_saml_settings_test.go index 00e3d18..9cb8302 100644 --- a/pkg/platform/resource_saml_settings_test.go +++ b/pkg/platform/resource_saml_settings_test.go @@ -59,6 +59,27 @@ func TestAccSAMLSettings_full(t *testing.T) { updatedConfig := util.ExecuteTemplate(name, temp, updatedTestData) + temp2 := ` + resource "platform_saml_settings" "{{ .name }}" { + name = "{{ .name }}" + enable = true + certificate = "{{ .certificate }}" + email_attribute = "{{ .email_attribute }}" + group_attribute = "{{ .group_attribute }}" + name_id_attribute = "{{ .name_id_attribute }}" + login_url = "http://tempurl.org/login" + logout_url = "http://tempurl.org/logout" + auto_user_creation = {{ .auto_user_creation }} + service_provider_name = "okta" + allow_user_to_access_profile = true + auto_redirect = true + sync_groups = true + verify_audience_restriction = true + use_encrypted_assertion = false + }` + + updatedConfig2 := util.ExecuteTemplate(name, temp2, updatedTestData) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProviders(), @@ -109,6 +130,27 @@ func TestAccSAMLSettings_full(t *testing.T) { resource.TestCheckResourceAttr(fqrn, "ldap_group_settings.1", "test-group-2"), ), }, + { + Config: updatedConfig2, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fqrn, "name", updatedTestData["name"]), + resource.TestCheckResourceAttr(fqrn, "enable", "true"), + resource.TestCheckResourceAttr(fqrn, "certificate", updatedTestData["certificate"]), + resource.TestCheckResourceAttr(fqrn, "email_attribute", updatedTestData["email_attribute"]), + resource.TestCheckResourceAttr(fqrn, "group_attribute", updatedTestData["group_attribute"]), + resource.TestCheckResourceAttr(fqrn, "name_id_attribute", updatedTestData["name_id_attribute"]), + resource.TestCheckResourceAttr(fqrn, "login_url", "http://tempurl.org/login"), + resource.TestCheckResourceAttr(fqrn, "logout_url", "http://tempurl.org/logout"), + resource.TestCheckResourceAttr(fqrn, "auto_user_creation", updatedTestData["auto_user_creation"]), + resource.TestCheckResourceAttr(fqrn, "service_provider_name", "okta"), + resource.TestCheckResourceAttr(fqrn, "allow_user_to_access_profile", "true"), + resource.TestCheckResourceAttr(fqrn, "auto_redirect", "true"), + resource.TestCheckResourceAttr(fqrn, "sync_groups", "true"), + resource.TestCheckResourceAttr(fqrn, "verify_audience_restriction", "true"), + resource.TestCheckResourceAttr(fqrn, "use_encrypted_assertion", "false"), + resource.TestCheckNoResourceAttr(fqrn, "ldap_group_settings"), + ), + }, { ResourceName: fqrn, ImportState: true, From 4d452b28dcf2500056cf9da275241dab20f66399 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Mon, 2 Dec 2024 10:28:27 -0800 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 270db68..9c65923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.19.0 (December 2, 2024). Tested on Artifactory 7.98.9 with Terraform 1.10.0 and OpenTofu 1.8.6 +## 1.19.0 (December 3, 2024) FEATURES: @@ -6,6 +6,10 @@ FEATURES: * `platform_crowd_settings` - Resource to manage Crowd/JIRA authentication provider. PR: [#167](https://github.com/jfrog/terraform-provider-platform/pull/167) +BUG FIXES: + +* resource/platform_saml_settings: Fix `Value Conversion Error` for attribute `ldap_group_settings`. Issue: [#168](https://github.com/jfrog/terraform-provider-platform/issues/168) PR: [#171](https://github.com/jfrog/terraform-provider-platform/pull/171) + ## 1.18.2 (November 27, 2024). Tested on Artifactory 7.98.9 with Terraform 1.9.8 and OpenTofu 1.8.6 BUG FIXES: From ca5d01486565e387773763923fe9eecd49344dcc Mon Sep 17 00:00:00 2001 From: JFrog CI Date: Mon, 2 Dec 2024 18:34:54 +0000 Subject: [PATCH 3/4] 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 9c65923..abdd064 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.19.0 (December 3, 2024) +## 1.19.0 (December 3, 2024). Tested on Artifactory 7.98.9 with Terraform 1.10.0 and OpenTofu 1.8.6 FEATURES: From c63902190fd42cffa23a8205aff57dc9644e10d8 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Mon, 2 Dec 2024 10:48:32 -0800 Subject: [PATCH 4/4] Replace unused func arg --- pkg/platform/resource_crowd_settings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/platform/resource_crowd_settings.go b/pkg/platform/resource_crowd_settings.go index 569b804..95d6333 100644 --- a/pkg/platform/resource_crowd_settings.go +++ b/pkg/platform/resource_crowd_settings.go @@ -45,7 +45,7 @@ type CrowdSettingsResourceModel struct { OverrideAllGroupsUponLogin types.Bool `tfsdk:"override_all_groups_upon_login"` } -func (r *CrowdSettingsResourceModel) toAPIModel(ctx context.Context, apiModel *CrowdSettingsAPIModel) diag.Diagnostics { +func (r *CrowdSettingsResourceModel) toAPIModel(_ context.Context, apiModel *CrowdSettingsAPIModel) diag.Diagnostics { diags := diag.Diagnostics{} apiModel.Enable = r.Enable.ValueBool() @@ -62,7 +62,7 @@ func (r *CrowdSettingsResourceModel) toAPIModel(ctx context.Context, apiModel *C return diags } -func (r *CrowdSettingsResourceModel) fromAPIModel(ctx context.Context, apiModel *CrowdSettingsAPIModel) (ds diag.Diagnostics) { +func (r *CrowdSettingsResourceModel) fromAPIModel(_ context.Context, apiModel *CrowdSettingsAPIModel) (ds diag.Diagnostics) { r.Enable = types.BoolValue(apiModel.Enable) r.ServerURL = types.StringValue(apiModel.ServerURL) r.ApplicationName = types.StringValue(apiModel.ApplicationName)