Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update messages in Forms using terraform. #1088

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading