From 720d7a0620ff87e643dbba5e68e515ba4a4ae045 Mon Sep 17 00:00:00 2001 From: Kushal <43465488+kushalshit27@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:55:13 +0530 Subject: [PATCH] fix: update messages in Forms using terraform. (#1088) fix: update error messages in Forms using terraform. Co-authored-by: Rajat Bajaj --- docs/resources/form.md | 5 +++++ examples/resources/auth0_form/resource.tf | 5 +++++ internal/auth0/form/expand.go | 15 ++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/resources/form.md b/docs/resources/form.md index 470c759b..0dc2da65 100644 --- a/docs/resources/form.md +++ b/docs/resources/form.md @@ -87,6 +87,11 @@ resource "auth0_form" "my_form" { } }) + messages { + errors = jsonencode({ + ERR_REQUIRED_PROPERTY = "This field is required for user kyc." + }) + } languages { default = "en" primary = "en" diff --git a/examples/resources/auth0_form/resource.tf b/examples/resources/auth0_form/resource.tf index 8b977453..25b62371 100644 --- a/examples/resources/auth0_form/resource.tf +++ b/examples/resources/auth0_form/resource.tf @@ -74,6 +74,11 @@ resource "auth0_form" "my_form" { } }) + messages { + errors = jsonencode({ + ERR_REQUIRED_PROPERTY = "This field is required for user kyc." + }) + } languages { default = "en" primary = "en" diff --git a/internal/auth0/form/expand.go b/internal/auth0/form/expand.go index 28bbc29f..fbc098cd 100644 --- a/internal/auth0/form/expand.go +++ b/internal/auth0/form/expand.go @@ -18,7 +18,10 @@ func expandForm(data *schema.ResourceData) (*management.Form, error) { form.Name = value.String(cfg.GetAttr("name")) form.Languages = expandFomLanguages(cfg.GetAttr("languages")) - form.Messages = expandFomMessages(cfg.GetAttr("messages")) + + if data.HasChange("messages") { + form.Messages = expandFomMessages(cfg.GetAttr("messages")) + } if data.HasChange("translations") { translations, err := expandStringInterfaceMap(data, "translations") @@ -157,16 +160,14 @@ func expandStringInterfaceMap(data *schema.ResourceData, key string) (map[string } func convertToInterfaceMap(rawValue cty.Value) *map[string]interface{} { - if rawValue.IsNull() || !rawValue.CanIterateElements() { + if rawValue.IsNull() { return nil } m := make(map[string]interface{}) - for key, value := range rawValue.AsValueMap() { - if value.IsNull() { - continue - } - m[key] = value + m, err := structure.ExpandJsonFromString(rawValue.AsString()) + if err != nil { + return &m } return &m