Skip to content

Commit 84bc480

Browse files
authored
Merge pull request #579 from SumoLogic/INVS-1700-Unable-to-add-new-items-to-match-list
INVS-1700: Unable to add new items to match list
2 parents 7611847 + acb302b commit 84bc480

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ENHANCEMENTS:
99
DEPRECATIONS:
1010
* resource/sumologic_cse_inventory_entity_group_configuration: Deprecated `groups` in favor of `inventory_key`, `inventory_value`. (GH-495)
1111

12+
BUG FIXES:
13+
* Fixes `resource_sumologic_cse_match_list` Unable to add new items to match list (GH-579)
14+
1215
## 2.26.0 (September 7, 2023)
1316
FEATURES:
1417
* **New Resource:** sumologic_muting_schedule (GH-569)

sumologic/resource_sumologic_cse_match_list.go

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},

sumologic/resource_sumologic_cse_match_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAccSumologicSCEMatchList_createAndUpdate(t *testing.T) {
2424
liDescription := "Match List Item Description"
2525
liExpiration := "2122-02-27T04:00:00"
2626
liValue := "value"
27-
liCount := 3
27+
liCount := 1
2828

2929
// Update values
3030
uDefaultTtl := 3600

0 commit comments

Comments
 (0)