mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-07 14:44:11 -06:00
e999ae77ba
This commit adds ValidateFunc to the policy attribute so that JSON parsing errors can be caught early. Generally, when there is a ValidateFunc set for the attribute, one can safely assume that before any of the creation and/or update of the existing resource would happen it would have to succeed validation. Also adds support for new helper function which is used to normalise JSON string. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
25 lines
524 B
Go
25 lines
524 B
Go
package azurerm
|
|
|
|
import "encoding/json"
|
|
|
|
// Takes a value containing JSON string and passes it through
|
|
// the JSON parser to normalize it, returns either a parsing
|
|
// error or normalized JSON string.
|
|
func normalizeJsonString(jsonString interface{}) (string, error) {
|
|
var j interface{}
|
|
|
|
if jsonString == nil || jsonString.(string) == "" {
|
|
return "", nil
|
|
}
|
|
|
|
s := jsonString.(string)
|
|
|
|
err := json.Unmarshal([]byte(s), &j)
|
|
if err != nil {
|
|
return s, err
|
|
}
|
|
|
|
bytes, _ := json.Marshal(j)
|
|
return string(bytes[:]), nil
|
|
}
|