Skip to content

Commit 9168f84

Browse files
committed
Merge branch 'master' into zzhou-dashboard-metadata-variable-filter-default
2 parents 0b72a4b + d620fe6 commit 9168f84

16 files changed

+237
-68
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
## 2.28.1 (Unreleased)
1+
## 2.28.2 (Unreleased)
2+
3+
4+
## 2.28.1 (January 19, 2024)
5+
6+
ENHANCEMENTS:
7+
* Added support for `dynamic_severity` for the CSE Custom Insight. (GH-607)
8+
9+
BUG FIXES:
10+
* Minor fixes enabling proper resource import for CSE Rules (`severity`, `severity_mapping`, `aggregation_functions`). (GH-606)
211

312
## 2.28.0 (November 23, 2023)
413
FEATURES:

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ In order to run the full suite of Acceptance tests, run `make testacc`.
5656
To run a specific acceptance test, run `go test -v ./sumologic -run YourSpecificTestName`
5757

5858
*Note:*
59-
- 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-
- 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).
59+
- 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. You can generate a personal access key from your environment. Once your test runs, you are then capable of viewing the real resources created by Terraform in the UI.
6160
```sh
6261
$ export SUMOLOGIC_ACCESSID="yourAccessID"
6362
$ export SUMOLOGIC_ACCESSKEY="yourAccessKey"
64-
$ export SUMOLOGIC_ENVIRONMENT="stag"
65-
$ export SUMOLOGIC_BASE_URL="https://stag-api.sumologic.net/api/"
63+
$ export SUMOLOGIC_ENVIRONMENT="yourEnvironment"
64+
$ export SUMOLOGIC_BASE_URL="yourEnvironmentAPIUrl"
6665
$ export TF_ACC=1
6766
```
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).
67+
- More information on configuration can be found [here](https://github.com/SumoLogic/terraform-provider-sumologic/blob/master/website/docs/index.html.markdown#environment-variables).
6968

7069
- Environment variable `SUMOLOGIC_TEST_GOOGLE_APPLICATION_CREDENTIALS` must be set for gcp metrics acceptance tests to work properly (ex. below).
7170
- export SUMOLOGIC_TEST_GOOGLE_APPLICATION_CREDENTIALS=`cat /path/to/service_acccount.json`

sumologic/resource_sumologic_cse_aggregation_rule_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func TestAccSumologicCSEAggregationRule_createAndUpdate(t *testing.T) {
7373
resource.TestCheckResourceAttrSet(resourceName, "id"),
7474
),
7575
},
76+
{
77+
ResourceName: resourceName,
78+
ImportState: true,
79+
ImportStateVerify: true,
80+
},
7681
},
7782
})
7883
}

sumologic/resource_sumologic_cse_chain_rule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func resourceSumologicCSEChainRuleRead(d *schema.ResourceData, meta interface{})
112112
d.Set("is_prototype", CSEChainRuleGet.IsPrototype)
113113
d.Set("ordered", CSEChainRuleGet.Ordered)
114114
d.Set("name", CSEChainRuleGet.Name)
115+
d.Set("severity", CSEChainRuleGet.Severity)
115116
d.Set("summary_expression", CSEChainRuleGet.SummaryExpression)
116117
d.Set("tags", CSEChainRuleGet.Tags)
117118
d.Set("window_size", CSEChainRuleGet.WindowSizeName)

sumologic/resource_sumologic_cse_chain_rule_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestAccSumologicCSEChainRule_createAndUpdate(t *testing.T) {
6666
resource.TestCheckResourceAttrSet(resourceName, "id"),
6767
),
6868
},
69+
{
70+
ResourceName: resourceName,
71+
ImportState: true,
72+
ImportStateVerify: true,
73+
},
6974
},
7075
})
7176
}

sumologic/resource_sumologic_cse_custom_insight.go

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ func resourceSumologicCSECustomInsight() *schema.Resource {
4545
Required: true,
4646
ValidateFunc: validation.StringInSlice([]string{"HIGH", "MEDIUM", "LOW", "CRITICAL"}, false),
4747
},
48+
"dynamic_severity": {
49+
Type: schema.TypeList,
50+
Optional: true,
51+
Elem: &schema.Resource{
52+
Schema: map[string]*schema.Schema{
53+
"minimum_signal_severity": {
54+
Type: schema.TypeInt,
55+
Required: true,
56+
},
57+
"insight_severity": {
58+
Type: schema.TypeString,
59+
Required: true,
60+
ValidateFunc: validation.StringInSlice([]string{"HIGH", "MEDIUM", "LOW", "CRITICAL"}, false),
61+
},
62+
},
63+
},
64+
},
4865
"signal_names": {
4966
Type: schema.TypeList,
5067
Optional: true,
@@ -86,6 +103,7 @@ func resourceSumologicCSECustomInsightRead(d *schema.ResourceData, meta interfac
86103
d.Set("ordered", CSECustomInsightGet.Ordered)
87104
d.Set("rule_ids", CSECustomInsightGet.RuleIds)
88105
d.Set("severity", CSECustomInsightGet.Severity)
106+
d.Set("dynamic_severity", dynamicSeverityArrayToResource(CSECustomInsightGet.DynamicSeverity))
89107
d.Set("signal_names", CSECustomInsightGet.SignalNames)
90108
d.Set("tags", CSECustomInsightGet.Tags)
91109

@@ -103,14 +121,15 @@ func resourceSumologicCSECustomInsightCreate(d *schema.ResourceData, meta interf
103121

104122
if d.Id() == "" {
105123
id, err := c.CreateCSECustomInsight(CSECustomInsight{
106-
Description: d.Get("description").(string),
107-
Enabled: d.Get("enabled").(bool),
108-
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
109-
Name: d.Get("name").(string),
110-
Ordered: d.Get("ordered").(bool),
111-
Severity: d.Get("severity").(string),
112-
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
113-
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
124+
Description: d.Get("description").(string),
125+
Enabled: d.Get("enabled").(bool),
126+
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
127+
Name: d.Get("name").(string),
128+
Ordered: d.Get("ordered").(bool),
129+
Severity: d.Get("severity").(string),
130+
DynamicSeverity: resourceToDynamicSeverityArray(d.Get("dynamic_severity").([]interface{})),
131+
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
132+
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
114133
})
115134

116135
if err != nil {
@@ -143,14 +162,41 @@ func resourceToCSECustomInsight(d *schema.ResourceData) (CSECustomInsight, error
143162
}
144163

145164
return CSECustomInsight{
146-
ID: id,
147-
Description: d.Get("description").(string),
148-
Enabled: d.Get("enabled").(bool),
149-
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
150-
Name: d.Get("name").(string),
151-
Ordered: d.Get("ordered").(bool),
152-
Severity: d.Get("severity").(string),
153-
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
154-
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
165+
ID: id,
166+
Description: d.Get("description").(string),
167+
Enabled: d.Get("enabled").(bool),
168+
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
169+
Name: d.Get("name").(string),
170+
Ordered: d.Get("ordered").(bool),
171+
Severity: d.Get("severity").(string),
172+
DynamicSeverity: resourceToDynamicSeverityArray(d.Get("dynamic_severity").([]interface{})),
173+
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
174+
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
155175
}, nil
156176
}
177+
178+
func resourceToDynamicSeverityArray(resourceDynamicSeverity []interface{}) []DynamicSeverity {
179+
result := make([]DynamicSeverity, len(resourceDynamicSeverity))
180+
181+
for i, resourceDynamicSeverity := range resourceDynamicSeverity {
182+
result[i] = DynamicSeverity{
183+
MinimumSignalSeverity: resourceDynamicSeverity.(map[string]interface{})["minimum_signal_severity"].(int),
184+
InsightSeverity: resourceDynamicSeverity.(map[string]interface{})["insight_severity"].(string),
185+
}
186+
}
187+
188+
return result
189+
}
190+
191+
func dynamicSeverityArrayToResource(dynamicSeverities []DynamicSeverity) []map[string]interface{} {
192+
result := make([]map[string]interface{}, len(dynamicSeverities))
193+
194+
for i, dynamicSeverity := range dynamicSeverities {
195+
result[i] = map[string]interface{}{
196+
"minimum_signal_severity": dynamicSeverity.MinimumSignalSeverity,
197+
"insight_severity": dynamicSeverity.InsightSeverity,
198+
}
199+
}
200+
201+
return result
202+
}

sumologic/resource_sumologic_cse_custom_insight_test.go

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
88
"github.com/hashicorp/terraform-plugin-sdk/terraform"
9+
"github.com/stretchr/testify/assert"
910
)
1011

1112
func TestAccSumologicCSECustomInsight_createAndUpdate(t *testing.T) {
@@ -35,7 +36,7 @@ func TestAccSumologicCSECustomInsight_createAndUpdate(t *testing.T) {
3536
ordered, name, severity, signalName1, signalName2, tag),
3637
Check: resource.ComposeTestCheckFunc(
3738
testCheckCSECustomInsightExists(resourceName, &CustomInsight),
38-
testCheckCustomInsightValues(&CustomInsight, description, enabled,
39+
testCheckCustomInsightValues(t, &CustomInsight, description, enabled,
3940
ordered, name, severity, signalName1, signalName2, tag),
4041
resource.TestCheckResourceAttrSet(resourceName, "id"),
4142
),
@@ -46,12 +47,62 @@ func TestAccSumologicCSECustomInsight_createAndUpdate(t *testing.T) {
4647
signalName2, tag),
4748
Check: resource.ComposeTestCheckFunc(
4849
testCheckCSECustomInsightExists(resourceName, &CustomInsight),
49-
testCheckCustomInsightValues(&CustomInsight, description, enabled,
50+
testCheckCustomInsightValues(t, &CustomInsight, description, enabled,
5051
ordered, nameUpdated, severityUpdated, signalName1,
5152
signalName2, tag),
5253
resource.TestCheckResourceAttrSet(resourceName, "id"),
5354
),
5455
},
56+
{
57+
ResourceName: resourceName,
58+
ImportState: true,
59+
ImportStateVerify: true,
60+
},
61+
},
62+
})
63+
}
64+
65+
func TestAccSumologicCSECustomInsight_createAndUpdateWithDynamicSeverity(t *testing.T) {
66+
SkipCseTest(t)
67+
68+
var CustomInsight CSECustomInsight
69+
minimumSignalSeverity1 := 5
70+
dynamicSeverity1 := "MEDIUM"
71+
minimumSignalSeverity2 := 8
72+
dynamicSeverity2 := "HIGH"
73+
74+
updatedMinimumSignalSeverity2 := 9
75+
updatedDynamicSeverity2 := "CRITICAL"
76+
77+
resourceName := "sumologic_cse_custom_insight.custom_insight2"
78+
resource.Test(t, resource.TestCase{
79+
PreCheck: func() { testAccPreCheck(t) },
80+
Providers: testAccProviders,
81+
CheckDestroy: testAccCSECustomInsightDestroy,
82+
Steps: []resource.TestStep{
83+
{
84+
Config: testCreateCSECustomInsightConfigWithDynamicSeverity(minimumSignalSeverity1, dynamicSeverity1, minimumSignalSeverity2, dynamicSeverity2),
85+
Check: resource.ComposeTestCheckFunc(
86+
testCheckCSECustomInsightExists(resourceName, &CustomInsight),
87+
testCheckCustomInsightDynamicSeverity(t, &CustomInsight,
88+
minimumSignalSeverity1, dynamicSeverity1, minimumSignalSeverity2, dynamicSeverity2),
89+
resource.TestCheckResourceAttrSet(resourceName, "id"),
90+
),
91+
},
92+
{
93+
Config: testCreateCSECustomInsightConfigWithDynamicSeverity(minimumSignalSeverity1, dynamicSeverity1, updatedMinimumSignalSeverity2, updatedDynamicSeverity2),
94+
Check: resource.ComposeTestCheckFunc(
95+
testCheckCSECustomInsightExists(resourceName, &CustomInsight),
96+
testCheckCustomInsightDynamicSeverity(t, &CustomInsight,
97+
minimumSignalSeverity1, dynamicSeverity1, updatedMinimumSignalSeverity2, updatedDynamicSeverity2),
98+
resource.TestCheckResourceAttrSet(resourceName, "id"),
99+
),
100+
},
101+
{
102+
ResourceName: resourceName,
103+
ImportState: true,
104+
ImportStateVerify: true,
105+
},
55106
},
56107
})
57108
}
@@ -96,6 +147,28 @@ resource "sumologic_cse_custom_insight" "custom_insight" {
96147
signalName2, tag)
97148
}
98149

150+
func testCreateCSECustomInsightConfigWithDynamicSeverity(
151+
minimumSignalSeverity1 int, dynamicSeverity1 string, minimumSignalSeverity2 int, dynamicSeverity2 string) string {
152+
return fmt.Sprintf(`
153+
resource "sumologic_cse_custom_insight" "custom_insight2" {
154+
description = "Dynamic severity insight"
155+
enabled = true
156+
ordered = true
157+
name = "Dynamic severity insight"
158+
severity = "LOW"
159+
dynamic_severity {
160+
minimum_signal_severity = %d
161+
insight_severity = "%s"
162+
}
163+
dynamic_severity {
164+
minimum_signal_severity = %d
165+
insight_severity = "%s"
166+
}
167+
tags = ["test tag"]
168+
}
169+
`, minimumSignalSeverity1, dynamicSeverity1, minimumSignalSeverity2, dynamicSeverity2)
170+
}
171+
99172
func testCheckCSECustomInsightExists(n string, CustomInsight *CSECustomInsight) resource.TestCheckFunc {
100173
return func(s *terraform.State) error {
101174
rs, ok := s.RootModule().Resources[n]
@@ -104,7 +177,7 @@ func testCheckCSECustomInsightExists(n string, CustomInsight *CSECustomInsight)
104177
}
105178

106179
if rs.Primary.ID == "" {
107-
return fmt.Errorf("chain rule ID is not set")
180+
return fmt.Errorf("CustomInsight ID is not set")
108181
}
109182

110183
c := testAccProvider.Meta().(*Client)
@@ -119,35 +192,30 @@ func testCheckCSECustomInsightExists(n string, CustomInsight *CSECustomInsight)
119192
}
120193
}
121194

122-
func testCheckCustomInsightValues(CustomInsight *CSECustomInsight, description string,
195+
func testCheckCustomInsightValues(t *testing.T, CustomInsight *CSECustomInsight, description string,
123196
enabled bool, ordered bool, name string, severity string, signalName1 string,
124197
signalName2 string, tag string) resource.TestCheckFunc {
125198
return func(s *terraform.State) error {
126-
if CustomInsight.Description != description {
127-
return fmt.Errorf("bad description, expected \"%s\", got %#v", description, CustomInsight.Description)
128-
}
129-
if CustomInsight.Enabled != enabled {
130-
return fmt.Errorf("bad enabled, expected \"%t\", got %#v", enabled, CustomInsight.Enabled)
131-
}
132-
if CustomInsight.Ordered != ordered {
133-
return fmt.Errorf("bad ordered, expected \"%t\", got %#v", ordered, CustomInsight.Ordered)
134-
}
135-
if CustomInsight.Name != name {
136-
return fmt.Errorf("bad name, expected \"%s\", got %#v", name, CustomInsight.Name)
137-
}
138-
if CustomInsight.Severity != severity {
139-
return fmt.Errorf("bad severity, expected \"%s\", got %#v", severity, CustomInsight.Severity)
140-
}
141-
if CustomInsight.SignalNames[0] != signalName1 {
142-
return fmt.Errorf("bad signalName1, expected \"%s\", got %#v", signalName1, CustomInsight.SignalNames[0])
143-
}
144-
if CustomInsight.SignalNames[1] != signalName2 {
145-
return fmt.Errorf("bad signalName2, expected \"%s\", got %#v", signalName2, CustomInsight.SignalNames[1])
146-
}
147-
if CustomInsight.Tags[0] != tag {
148-
return fmt.Errorf("bad tag, expected \"%s\", got %#v", tag, CustomInsight.Tags[0])
149-
}
199+
assert.Equal(t, description, CustomInsight.Description)
200+
assert.Equal(t, enabled, CustomInsight.Enabled)
201+
assert.Equal(t, ordered, CustomInsight.Ordered)
202+
assert.Equal(t, name, CustomInsight.Name)
203+
assert.Equal(t, severity, CustomInsight.Severity)
204+
assert.Equal(t, signalName1, CustomInsight.SignalNames[0])
205+
assert.Equal(t, signalName2, CustomInsight.SignalNames[1])
206+
assert.Equal(t, tag, CustomInsight.Tags[0])
207+
return nil
208+
}
209+
}
150210

211+
func testCheckCustomInsightDynamicSeverity(t *testing.T, CustomInsight *CSECustomInsight,
212+
minimumSignalSeverity1 int, dynamicSeverity1 string, minimumSignalSeverity2 int, dynamicSeverity2 string) resource.TestCheckFunc {
213+
214+
return func(s *terraform.State) error {
215+
assert.Equal(t, minimumSignalSeverity1, CustomInsight.DynamicSeverity[0].MinimumSignalSeverity)
216+
assert.Equal(t, dynamicSeverity1, CustomInsight.DynamicSeverity[0].InsightSeverity)
217+
assert.Equal(t, minimumSignalSeverity2, CustomInsight.DynamicSeverity[1].MinimumSignalSeverity)
218+
assert.Equal(t, dynamicSeverity2, CustomInsight.DynamicSeverity[1].InsightSeverity)
151219
return nil
152220
}
153221
}

sumologic/resource_sumologic_cse_first_seen_rule_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func TestAccSumologicCSEFirstSeenRule_createAndUpdate(t *testing.T) {
5959
testCheckFirstSeenRuleValues(t, &updatedPayload, &result),
6060
),
6161
},
62+
{
63+
ResourceName: resourceName,
64+
ImportState: true,
65+
ImportStateVerify: true,
66+
},
6267
},
6368
})
6469
}

sumologic/resource_sumologic_cse_match_rule_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func TestAccSumologicCSEMatchRule_createAndUpdate(t *testing.T) {
6262
resource.TestCheckResourceAttrSet(resourceName, "id"),
6363
),
6464
},
65+
{
66+
ResourceName: resourceName,
67+
ImportState: true,
68+
ImportStateVerify: true,
69+
},
6570
},
6671
})
6772
}

sumologic/resource_sumologic_cse_outlier_rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func resourceSumologicCSEOutlierRuleRead(d *schema.ResourceData, meta interface{
132132
return nil
133133
}
134134

135-
d.Set("aggregate_function", aggregationFunctionsArrayToResource(CSEOutlierRuleGet.AggregationFunctions))
135+
d.Set("aggregation_functions", aggregationFunctionsArrayToResource(CSEOutlierRuleGet.AggregationFunctions))
136136
d.Set("baseline_window_size", CSEOutlierRuleGet.BaselineWindowSize)
137137
d.Set("description_expression", CSEOutlierRuleGet.DescriptionExpression)
138138
d.Set("deviation_threshold", CSEOutlierRuleGet.DeviationThreshold)

0 commit comments

Comments
 (0)