@@ -3,76 +3,12 @@ package sumologic
33import (
44 "fmt"
55 "log"
6- "reflect"
7- "strings"
86 "time"
97
108 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
119 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
1210)
1311
14- func MatchListItemsDiffSuppressFunc (key , oldValue , newValue string , d * schema.ResourceData ) bool {
15- // Suppresses the diff shown if the items are the same but in different order
16-
17- // The key is either the list itself (e.g "items") or a path to the list element (e.g. "items.0")
18- lastDotIndex := strings .LastIndex (key , "." )
19- if lastDotIndex != - 1 {
20- key = string (key [:lastDotIndex ])
21- }
22-
23- oldData , newData := d .GetChange (key )
24-
25- // Case where two individual items are being compared
26- if key != "items" {
27- oldMap := oldData .(map [string ]interface {})
28- newMap := newData .(map [string ]interface {})
29- return reflect .DeepEqual (oldMap , newMap )
30- }
31-
32- // Check if lists are null or different lengths
33- if oldData == nil || newData == nil {
34- return false
35- }
36-
37- println ("key: " + key , fmt .Sprintf ("%T" , oldData ), fmt .Sprintf ("%T" , newData ))
38-
39- oldArray := oldData .([]interface {})
40- newArray := newData .([]interface {})
41-
42- println ("len oldArray: " , len (oldArray ), " len newArray:" , len (newArray ))
43-
44- if len (oldArray ) != len (newArray ) {
45- return false
46- }
47-
48- // Check if the new array contains each map in the old array
49- for i := 0 ; i < len (oldArray ); i ++ {
50- newArrayContainsOldMap := false
51-
52- println (fmt .Sprintf ("%T" , oldArray [i ]))
53-
54- oldMap := oldArray [i ].(map [string ]interface {})
55-
56- println (fmt .Sprintf ("oldmap %#v" , oldMap ))
57-
58- for j := 0 ; j < len (newArray ); j ++ {
59-
60- newMap := newArray [j ].(map [string ]interface {})
61- if reflect .DeepEqual (oldMap , newMap ) {
62- println (fmt .Sprintf ("newmap match %#v" , newMap ))
63-
64- newArrayContainsOldMap = true
65- break
66- }
67- }
68-
69- if ! newArrayContainsOldMap {
70- return false
71- }
72- }
73- return true
74- }
75-
7612func resourceSumologicCSEMatchList () * schema.Resource {
7713 return & schema.Resource {
7814 Create : resourceSumologicCSEMatchListCreate ,
@@ -123,7 +59,6 @@ func resourceSumologicCSEMatchList() *schema.Resource {
12359 "items" : {
12460 Type : schema .TypeSet ,
12561 Optional : true ,
126- //DiffSuppressFunc: MatchListItemsDiffSuppressFunc,
12762 Elem : & schema.Resource {
12863 Schema : map [string ]* schema.Schema {
12964 "id" : {
@@ -215,13 +150,20 @@ func setItems(d *schema.ResourceData, items []CSEMatchListItemGet) {
215150}
216151
217152func resourceSumologicCSEMatchListDelete (d * schema.ResourceData , meta interface {}) error {
153+ println ("delete: started resourceSumologicCSEMatchListDelete" )
154+
218155 c := meta .(* Client )
219156 err := c .DeleteCSEMatchList (d .Id ())
157+
158+ println ("delete: finished resourceSumologicCSEMatchListDelete" )
159+
220160 return err
221161
222162}
223163
224164func resourceSumologicCSEMatchListCreate (d * schema.ResourceData , meta interface {}) error {
165+ println ("create: starting resourceSumologicCSEMatchListCreate" )
166+
225167 c := meta .(* Client )
226168
227169 if d .Id () == "" {
@@ -279,7 +221,7 @@ func resourceSumologicCSEMatchListCreate(d *schema.ResourceData, meta interface{
279221
280222 }
281223
282- fmt . Println ( " finished creating match list " )
224+ println ( "create: finished resourceSumologicCSEMatchListCreate " )
283225
284226 return resourceSumologicCSEMatchListRead (d , meta )
285227}
@@ -299,7 +241,7 @@ func resourceToCSEMatchListItem(data interface{}) (CSEMatchListItemPost, string)
299241}
300242
301243func resourceSumologicCSEMatchListUpdate (d * schema.ResourceData , meta interface {}) error {
302- println ("in update" )
244+ println ("update: starting resourceSumologicCSEMatchListUpdate " )
303245 CSEMatchListPost , err := resourceToCSEMatchList (d )
304246 if err != nil {
305247 return err
@@ -322,7 +264,7 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
322264 itemIds = append (itemIds , id )
323265 }
324266
325- println (itemIds )
267+ println ("update: creating new updated items" )
326268
327269 if len (items ) > 0 {
328270 err2 := c .CreateCSEMatchListItems (items , d .Id ())
@@ -340,7 +282,7 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
340282 }
341283 if CSEMatchListItems != nil {
342284
343- println ("343" )
285+ println (fmt . Sprintf ( "update: checking %d items for deletion" , len ( CSEMatchListItems . CSEMatchListItemsGetObjects )) )
344286
345287 for _ , t := range CSEMatchListItems .CSEMatchListItemsGetObjects {
346288 if ! contains (itemIds , t .ID ) {
@@ -352,7 +294,7 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
352294 }
353295 }
354296
355- println ("355 " )
297+ println ("update: finished deleting, now getting items " )
356298
357299 createStateConf := & resource.StateChangeConf {
358300 Target : []string {
@@ -373,12 +315,12 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
373315
374316 _ , err = createStateConf .WaitForState ()
375317
376- println ("376" )
377-
378318 if err != nil {
379319 return fmt .Errorf ("error waiting for match list (%s) to be updated: %s" , d .Id (), err )
380320 }
381321
322+ println ("update: finished resourceSumologicCSEMatchListUpdate" )
323+
382324 return resourceSumologicCSEMatchListRead (d , meta )
383325}
384326
0 commit comments