From aee337f890dfa8287ed546225d2cb0b4a64b9daf Mon Sep 17 00:00:00 2001 From: zaalbarxx Date: Mon, 17 Jun 2024 17:06:35 +0200 Subject: [PATCH] 199 - Order of options in form field (#280) Fixes #199 Fixes #281 * * fixed issue with options order not being preserved for `form_field` object * Update helpers.go removed debug statement * Update resource_fusionauth_application.go * * converting `authorized_redirect_urls` to list instead of set --- fusionauth/helpers.go | 10 ++++++++++ fusionauth/resource_fusionauth_application.go | 4 ++-- fusionauth/resource_fusionauth_application_helpers.go | 4 ++-- fusionauth/resource_fusionauth_form_field.go | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/fusionauth/helpers.go b/fusionauth/helpers.go index f612f90..b6564ef 100644 --- a/fusionauth/helpers.go +++ b/fusionauth/helpers.go @@ -16,6 +16,16 @@ func handleStringSlice(key string, data *schema.ResourceData) []string { return handleStringSliceFromSet(data.Get(key).(*schema.Set)) } +func handleStringSliceFromList(list []interface{}) []string { + s := make([]string, 0, len(list)) + + for _, x := range list { + s = append(s, x.(string)) + } + + return s +} + func handleStringSliceFromSet(set *schema.Set) []string { l := set.List() s := make([]string, 0, len(l)) diff --git a/fusionauth/resource_fusionauth_application.go b/fusionauth/resource_fusionauth_application.go index 126a667..b02de78 100644 --- a/fusionauth/resource_fusionauth_application.go +++ b/fusionauth/resource_fusionauth_application.go @@ -412,7 +412,7 @@ func newSamlv2Configuration() *schema.Resource { Description: "The audience for the SAML response sent to back to the service provider from FusionAuth. Some service providers require different audience values than the issuer and this configuration option lets you change the audience in the response.", }, "authorized_redirect_urls": { - Type: schema.TypeSet, + Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, Required: true, Description: "An array of URLs that are the authorized redirect URLs for FusionAuth OAuth.", @@ -587,7 +587,7 @@ func newOAuthConfiguration() *schema.Resource { Description: "An array of URLs that are the authorized origins for FusionAuth OAuth.", }, "authorized_redirect_urls": { - Type: schema.TypeSet, + Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, Description: "An array of URLs that are the authorized redirect URLs for FusionAuth OAuth.", diff --git a/fusionauth/resource_fusionauth_application_helpers.go b/fusionauth/resource_fusionauth_application_helpers.go index 51fdb7b..f755ba0 100644 --- a/fusionauth/resource_fusionauth_application_helpers.go +++ b/fusionauth/resource_fusionauth_application_helpers.go @@ -63,7 +63,7 @@ func buildApplication(data *schema.ResourceData) fusionauth.Application { Name: data.Get("name").(string), OauthConfiguration: fusionauth.OAuth2Configuration{ AuthorizedOriginURLs: handleStringSlice("oauth_configuration.0.authorized_origin_urls", data), - AuthorizedRedirectURLs: handleStringSlice("oauth_configuration.0.authorized_redirect_urls", data), + AuthorizedRedirectURLs: handleStringSliceFromList(data.Get("oauth_configuration.0.authorized_redirect_urls").([]interface{})), AuthorizedURLValidationPolicy: fusionauth.Oauth2AuthorizedURLValidationPolicy(data.Get("oauth_configuration.0.authorized_url_validation_policy").(string)), ClientAuthenticationPolicy: fusionauth.ClientAuthenticationPolicy(data.Get("oauth_configuration.0.client_authentication_policy").(string)), ClientSecret: data.Get("oauth_configuration.0.client_secret").(string), @@ -109,7 +109,7 @@ func buildApplication(data *schema.ResourceData) fusionauth.Application { Samlv2Configuration: fusionauth.SAMLv2Configuration{ Enableable: buildEnableable("samlv2_configuration.0.enabled", data), Audience: data.Get("samlv2_configuration.0.audience").(string), - AuthorizedRedirectURLs: handleStringSlice("samlv2_configuration.0.authorized_redirect_urls", data), + AuthorizedRedirectURLs: handleStringSliceFromList(data.Get("samlv2_configuration.0.authorized_redirect_urls").([]interface{})), CallbackURL: data.Get("samlv2_configuration.0.callback_url").(string), Debug: data.Get("samlv2_configuration.0.debug").(bool), DefaultVerificationKeyId: data.Get("samlv2_configuration.0.default_verification_key_id").(string), diff --git a/fusionauth/resource_fusionauth_form_field.go b/fusionauth/resource_fusionauth_form_field.go index b3ab3eb..81f5a86 100644 --- a/fusionauth/resource_fusionauth_form_field.go +++ b/fusionauth/resource_fusionauth_form_field.go @@ -76,7 +76,7 @@ func resourceFormField() *schema.Resource { Description: "The unique name of the Form Field.", }, "options": { - Type: schema.TypeSet, + Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, Description: "A list of options that are applied to checkbox, radio, or select controls.", @@ -208,7 +208,7 @@ func buildFormField(data *schema.ResourceData) fusionauth.FormField { Description: data.Get("description").(string), Key: data.Get("key").(string), Name: data.Get("name").(string), - Options: handleStringSlice("options", data), + Options: handleStringSliceFromList(data.Get("options").([]interface{})), Required: data.Get("required").(bool), Type: fusionauth.FormDataType(data.Get("type").(string)), Validator: fusionauth.FormFieldValidator{