Skip to content

Commit

Permalink
fix: update messages in Forms using terraform. (#1088)
Browse files Browse the repository at this point in the history
fix: update error messages in Forms using terraform.

Co-authored-by: Rajat Bajaj <[email protected]>
  • Loading branch information
kushalshit27 and duedares-rvj authored Nov 27, 2024
1 parent 1573c5b commit 720d7a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/resources/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/auth0_form/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 8 additions & 7 deletions internal/auth0/form/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 720d7a0

Please sign in to comment.