@@ -20,6 +20,19 @@ var customFieldsSchema = &schema.Schema{
2020 Type : schema .TypeString ,
2121 Default : nil ,
2222 },
23+ DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool {
24+ if old == "" && new == "0" {
25+ return true // treat empty and "0" as equal? Wait, for maps it's different
26+ }
27+ // For maps, old and new are JSON strings
28+ if old == "{}" && new == "" {
29+ return true
30+ }
31+ if old == "" && new == "{}" {
32+ return true
33+ }
34+ return false
35+ },
2336}
2437
2538func getCustomFields (cf interface {}) map [string ]interface {} {
@@ -31,7 +44,8 @@ func getCustomFields(cf interface{}) map[string]interface{} {
3144}
3245
3346// flattenCustomFields converts custom fields to a map where all values are strings.
34- // Complex nested objects (like IP address references) are converted to JSON strings.
47+ // Object references (maps with "id" field) are converted to just their ID string.
48+ // Other complex types are converted to JSON strings.
3549func flattenCustomFields (cf interface {}) map [string ]interface {} {
3650 cfm , ok := cf .(map [string ]interface {})
3751 if ! ok || len (cfm ) == 0 {
@@ -51,8 +65,21 @@ func flattenCustomFields(cf interface{}) map[string]interface{} {
5165 result [key ] = v
5266 case float64 , int , int64 , bool :
5367 result [key ] = fmt .Sprintf ("%v" , v )
68+ case map [string ]interface {}:
69+ // Check if this is an object reference with an ID
70+ if id , hasID := v ["id" ]; hasID {
71+ // Extract just the ID for object references
72+ result [key ] = fmt .Sprintf ("%v" , id )
73+ } else {
74+ // For other complex objects without ID, convert to JSON
75+ if jsonBytes , err := json .Marshal (value ); err == nil {
76+ result [key ] = string (jsonBytes )
77+ } else {
78+ result [key ] = fmt .Sprintf ("%v" , value )
79+ }
80+ }
5481 default :
55- // For complex types (maps, arrays, objects ), convert to JSON string
82+ // For other complex types (arrays, etc. ), convert to JSON string
5683 if jsonBytes , err := json .Marshal (value ); err == nil {
5784 result [key ] = string (jsonBytes )
5885 } else {
0 commit comments