Skip to content

Commit b2588ea

Browse files
committed
lint check fix and update count to 3
1 parent d9c7772 commit b2588ea

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ Then run `terraform init` to initialize it.
5353

5454
In order to run the full suite of Acceptance tests, run `make testacc`.
5555

56-
To run a specific acceptance test, run `go test -v ./sumologic -run TheSpecificTestName`
56+
To run a specific acceptance test, run `go test -v ./sumologic -run YourSpecificTestName`
5757

5858
*Note:*
5959
- Acceptance tests *create real resources*, and often cost money to run. The environment variables `SUMOLOGIC_ACCESSID`, `SUMOLOGIC_ACCESSKEY`, `SUMOLOGIC_ENVIRONMENT` / `SUMOLOGIC_BASE_URL`, and `TF_ACC` must also be set for acceptance tests to work properly.
60-
- More information on configuration can be found at the [Terraform Provider codelabs documentation](https://github.com/Sanyaku/codelabs/blob/master/backend/pages/SumoLogicTerraformProvider.md).
61-
- Stag example:
60+
- For example, you can generate a personal access key in stag-alpha [here](https://cse-stag-alpha.stag.sumologic.net/ui/#/preferences). Once your test runs, you are then capable of viewing the real resources created by Terraform in the [stag-alpha UI](https://cse-stag-alpha.stag.sumologic.net/sec/hud?hours=24).
6261
```sh
6362
$ export SUMOLOGIC_ACCESSID="yourAccessID"
6463
$ export SUMOLOGIC_ACCESSKEY="yourAccessKey"
6564
$ export SUMOLOGIC_ENVIRONMENT="stag"
6665
$ export SUMOLOGIC_BASE_URL="https://stag-api.sumologic.net/api/"
6766
$ export TF_ACC=1
6867
```
68+
- More information on configuration can be found at the [Terraform Provider codelabs documentation](https://github.com/Sanyaku/codelabs/blob/master/backend/pages/SumoLogicTerraformProvider.md).
69+
6970
- Environment variable `SUMOLOGIC_TEST_GOOGLE_APPLICATION_CREDENTIALS` must be set for gcp metrics acceptance tests to work properly (ex. below).
7071
- export SUMOLOGIC_TEST_GOOGLE_APPLICATION_CREDENTIALS=`cat /path/to/service_acccount.json`
7172
- Set Environment variable `SUMOLOGIC_ENABLE_GCP_METRICS_ACC_TESTS` to false, to disable acceptance test for Gcp Metrics.

sumologic/resource_sumologic_cse_match_list.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ func resourceSumologicCSEMatchList() *schema.Resource {
8787
}
8888
}
8989

90-
func getCSEMatchListItemsInMatchList(id string, meta interface{}) *CSEMatchListItemsInMatchListGet {
91-
c := meta.(*Client)
92-
93-
CSEMatchListItems, err := c.GetCSEMatchListItemsInMatchList(id)
94-
if err != nil {
95-
log.Printf("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v", id, err)
96-
}
97-
return CSEMatchListItems
98-
}
99-
10090
func resourceSumologicCSEMatchListRead(d *schema.ResourceData, meta interface{}) error {
10191
c := meta.(*Client)
10292

@@ -125,7 +115,10 @@ func resourceSumologicCSEMatchListRead(d *schema.ResourceData, meta interface{})
125115
d.Set("last_updated", CSEMatchList.LastUpdated)
126116
d.Set("last_updated_by", CSEMatchList.LastUpdatedBy)
127117

128-
CSEMatchListItems := getCSEMatchListItemsInMatchList(id, meta)
118+
CSEMatchListItems, err := c.GetCSEMatchListItemsInMatchList(id)
119+
if err != nil {
120+
log.Printf("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v", id, err)
121+
}
129122

130123
if CSEMatchListItems == nil {
131124
d.Set("items", nil)
@@ -185,9 +178,9 @@ func resourceSumologicCSEMatchListCreate(d *schema.ResourceData, meta interface{
185178
}
186179

187180
if len(items) > 0 {
188-
err2 := c.CreateCSEMatchListItems(items, id)
189-
if err2 != nil {
190-
log.Printf("[WARN] An error occurred while adding match list items to match list id: %s, err: %v", id, err2)
181+
err = c.CreateCSEMatchListItems(items, id)
182+
if err != nil {
183+
log.Printf("[WARN] An error occurred while adding match list items to match list id: %s, err: %v", id, err)
191184
}
192185

193186
}
@@ -199,6 +192,7 @@ func resourceSumologicCSEMatchListCreate(d *schema.ResourceData, meta interface{
199192
Refresh: func() (interface{}, string, error) {
200193
resp, err := c.GetCSEMatchListItemsInMatchList(d.Id())
201194
if err != nil {
195+
log.Printf("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v", d.Id(), err)
202196
return 0, "", err
203197
}
204198
return resp, fmt.Sprint(resp.Total), nil
@@ -251,7 +245,10 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
251245
newItems = append(newItems, item)
252246
}
253247

254-
CSEMatchListItems := getCSEMatchListItemsInMatchList(d.Id(), meta)
248+
CSEMatchListItems, err := c.GetCSEMatchListItemsInMatchList(d.Id())
249+
if err != nil {
250+
log.Printf("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v", d.Id(), err)
251+
}
255252
var oldItemIds []string
256253
for _, item := range CSEMatchListItems.CSEMatchListItemsGetObjects {
257254
oldItemIds = append(oldItemIds, item.ID)
@@ -269,11 +266,34 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
269266

270267
}
271268

272-
// Wait until all new items have finished being indexed in ES
273-
CSEMatchListItems = getCSEMatchListItemsInMatchList(d.Id(), meta)
274-
for CSEMatchListItems.Total < newItemCount {
275-
time.Sleep(3 * time.Second)
276-
CSEMatchListItems = getCSEMatchListItemsInMatchList(d.Id(), meta)
269+
CSEMatchListItems, err = c.GetCSEMatchListItemsInMatchList(d.Id())
270+
if err != nil {
271+
log.Printf("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v", d.Id(), err)
272+
}
273+
274+
// Wait for addition to finish
275+
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)
277297
}
278298

279299
// Delete old items
@@ -286,13 +306,15 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
286306
}
287307
}
288308

289-
createStateConf := &resource.StateChangeConf{
309+
// Wait for deletion to finish
310+
createStateConf = &resource.StateChangeConf{
290311
Target: []string{
291312
fmt.Sprint(len(newItems)),
292313
},
293314
Refresh: func() (interface{}, string, error) {
294315
resp, err := c.GetCSEMatchListItemsInMatchList(d.Id())
295316
if err != nil {
317+
log.Printf("[WARN] CSE Match List items not found when looking by match list id: %s, err: %v", d.Id(), err)
296318
return 0, "", err
297319
}
298320
return resp, fmt.Sprint(resp.Total), nil

sumologic/resource_sumologic_cse_match_list_test.go

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

2929
// Update values
3030
uDefaultTtl := 3600
3131
uDescription := "Updated Match List Description"
3232
uliDescription := "Updated Match List item Description"
3333
uliExpiration := "2122-02-27T05:00:00"
3434
uliValue := "updated value"
35-
uliCount := 1001
35+
uliCount := 3
3636

3737
resource.Test(t, resource.TestCase{
3838
PreCheck: func() { testAccPreCheck(t) },
@@ -111,8 +111,6 @@ resource "sumologic_cse_match_list" "match_list" {
111111
target_column = "%s" %s
112112
}`, nDefaultTtl, nDescription, nName, nTargetColumn, itemsStr)
113113

114-
fmt.Println(str)
115-
116114
return str
117115
}
118116

0 commit comments

Comments
 (0)