@@ -254,8 +254,15 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
254254 oldItemIds = append (oldItemIds , item .ID )
255255 }
256256
257- oldItemCount := CSEMatchListItems .Total
258- newItemCount := len (itemsData ) + oldItemCount
257+ // Delete old items
258+ for _ , t := range CSEMatchListItems .CSEMatchListItemsGetObjects {
259+ if contains (oldItemIds , t .ID ) {
260+ err = c .DeleteCSEMatchListItem (t .ID )
261+ if err != nil {
262+ log .Printf ("[WARN] An error occurred deleting match list item with id: %s, err: %v" , t .ID , err )
263+ }
264+ }
265+ }
259266
260267 //Add new items
261268 if len (newItems ) > 0 {
@@ -271,43 +278,8 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
271278 log .Printf ("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v" , d .Id (), err )
272279 }
273280
274- // Wait for addition to finish
281+ // Wait for update to finish
275282 createStateConf := & resource.StateChangeConf {
276- Target : []string {
277- fmt .Sprint (newItemCount ),
278- },
279- Refresh : func () (interface {}, string , error ) {
280- CSEMatchListItems , err = c .GetCSEMatchListItemsInMatchList (d .Id ())
281- if err != nil {
282- log .Printf ("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v" , d .Id (), err )
283- return 0 , "" , err
284- }
285-
286- return CSEMatchListItems , fmt .Sprint (CSEMatchListItems .Total ), nil
287- },
288- Timeout : d .Timeout (schema .TimeoutUpdate ),
289- Delay : 10 * time .Second ,
290- MinTimeout : 5 * time .Second ,
291- ContinuousTargetOccurence : 1 ,
292- }
293-
294- _ , err = createStateConf .WaitForState ()
295- if err != nil {
296- return fmt .Errorf ("error waiting for match list (%s) to be updated: %s" , d .Id (), err )
297- }
298-
299- // Delete old items
300- for _ , t := range CSEMatchListItems .CSEMatchListItemsGetObjects {
301- if contains (oldItemIds , t .ID ) {
302- err = c .DeleteCSEMatchListItem (t .ID )
303- if err != nil {
304- log .Printf ("[WARN] An error occurred deleting match list item with id: %s, err: %v" , t .ID , err )
305- }
306- }
307- }
308-
309- // Wait for deletion to finish
310- createStateConf = & resource.StateChangeConf {
311283 Target : []string {
312284 fmt .Sprint (len (newItems )),
313285 },
0 commit comments