Skip to content

Commit bf7d2d1

Browse files
TRIDENT-16345: Support CSE FirstSeenRule (#476)
* TRIDENT-16345: Support CSE FirstSeenRule Issues: TRIDENT-16345
1 parent eebd028 commit bf7d2d1

File tree

8 files changed

+543
-4
lines changed

8 files changed

+543
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
## 2.20.1 (Unreleased)
2+
FEATURES:
3+
* **New Resource:** sumologic_cse_first_seen_rule (GH-476)
4+
25
BUG FIXES:
36
* Added validations to fail if no trigger conditions defined in monitor resource (GH-463)
4-
7+
58
## 2.20.0 (December 15, 2022)
69
FEATURES:
710
* **New Resource:** sumologic_cse_custom_match_list_column (GH-462)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/go-errors/errors v1.4.0
77
github.com/hashicorp/go-retryablehttp v0.7.0
88
github.com/hashicorp/terraform-plugin-sdk v1.17.2
9+
github.com/stretchr/testify v1.7.0
910
)
1011

1112
require (
@@ -65,6 +66,7 @@ require (
6566
github.com/mitchellh/mapstructure v1.1.2 // indirect
6667
github.com/mitchellh/reflectwalk v1.0.1 // indirect
6768
github.com/oklog/run v1.1.0 // indirect
69+
github.com/pmezard/go-difflib v1.0.0 // indirect
6870
github.com/posener/complete v1.2.3 // indirect
6971
github.com/spf13/afero v1.2.2 // indirect
7072
github.com/ulikunitz/xz v0.5.10 // indirect
@@ -87,4 +89,5 @@ require (
8789
google.golang.org/genproto v0.0.0-20210721163202-f1cecdd8b78a // indirect
8890
google.golang.org/grpc v1.39.0 // indirect
8991
google.golang.org/protobuf v1.27.1 // indirect
92+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
9093
)

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
4343
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
4444
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4545
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
46-
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
4746
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
4847
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
4948
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
@@ -216,7 +215,6 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng
216215
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
217216
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
218217
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
219-
github.com/hashicorp/go-getter v1.5.3 h1:NF5+zOlQegim+w/EUhSLh6QhXHmZMEeHLQzllkQ3ROU=
220218
github.com/hashicorp/go-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI=
221219
github.com/hashicorp/go-getter v1.6.2 h1:7jX7xcB+uVCliddZgeKyNxv0xoT7qL5KDtH7rU4IqIk=
222220
github.com/hashicorp/go-getter v1.6.2/go.mod h1:IZCrswsZPeWv9IkVnLElzRU/gz/QPi6pZHn4tv6vbwA=
@@ -569,7 +567,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
569567
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
570568
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
571569
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
572-
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
573570
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
574571
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e h1:w36l2Uw3dRan1K3TyXriXvY+6T56GNmlKGcqiQUJDfM=
575572
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

sumologic/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func Provider() terraform.ResourceProvider {
6161
"sumologic_cse_chain_rule": resourceSumologicCSEChainRule(),
6262
"sumologic_cse_match_rule": resourceSumologicCSEMatchRule(),
6363
"sumologic_cse_threshold_rule": resourceSumologicCSEThresholdRule(),
64+
"sumologic_cse_first_seen_rule": resourceSumologicCSEFirstSeenRule(),
6465
"sumologic_collector": resourceSumologicCollector(),
6566
"sumologic_installed_collector": resourceSumologicInstalledCollector(),
6667
"sumologic_http_source": resourceSumologicHTTPSource(),
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
package sumologic
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
6+
"log"
7+
)
8+
9+
func resourceSumologicCSEFirstSeenRule() *schema.Resource {
10+
return &schema.Resource{
11+
Create: resourceSumologicCSEFirstSeenRuleCreate,
12+
Read: resourceSumologicCSEFirstSeenRuleRead,
13+
Delete: resourceSumologicCSEFirstSeenRuleDelete,
14+
Update: resourceSumologicCSEFirstSeenRuleUpdate,
15+
Importer: &schema.ResourceImporter{
16+
State: schema.ImportStatePassthrough,
17+
},
18+
19+
Schema: map[string]*schema.Schema{
20+
"baseline_type": {
21+
Type: schema.TypeString,
22+
Required: true,
23+
},
24+
"baseline_window_size": {
25+
Type: schema.TypeString,
26+
Required: true,
27+
},
28+
"description_expression": {
29+
Type: schema.TypeString,
30+
Required: true,
31+
},
32+
"enabled": {
33+
Type: schema.TypeBool,
34+
Required: true,
35+
},
36+
"entity_selectors": getEntitySelectorsSchema(),
37+
"filter_expression": {
38+
Type: schema.TypeString,
39+
Required: true,
40+
},
41+
"group_by_fields": {
42+
Type: schema.TypeList,
43+
Optional: true,
44+
Elem: &schema.Schema{
45+
Type: schema.TypeString,
46+
},
47+
},
48+
"is_prototype": {
49+
Type: schema.TypeBool,
50+
Optional: true,
51+
},
52+
"name": {
53+
Type: schema.TypeString,
54+
Required: true,
55+
},
56+
"name_expression": {
57+
Type: schema.TypeString,
58+
Required: true,
59+
},
60+
"retention_window_size": {
61+
Type: schema.TypeString,
62+
Required: true,
63+
},
64+
"severity": {
65+
Type: schema.TypeInt,
66+
Required: true,
67+
},
68+
"summary_expression": {
69+
Type: schema.TypeString,
70+
Optional: true,
71+
},
72+
"tags": {
73+
Type: schema.TypeList,
74+
Optional: true,
75+
Elem: &schema.Schema{
76+
Type: schema.TypeString,
77+
ValidateFunc: validation.StringIsNotEmpty,
78+
},
79+
},
80+
"value_fields": {
81+
Type: schema.TypeList,
82+
Required: true,
83+
Elem: &schema.Schema{
84+
Type: schema.TypeString,
85+
ValidateFunc: validation.StringIsNotEmpty,
86+
},
87+
},
88+
},
89+
}
90+
}
91+
92+
func resourceSumologicCSEFirstSeenRuleRead(d *schema.ResourceData, meta interface{}) error {
93+
c := meta.(*Client)
94+
95+
var CSEFirstSeenRuleGet *CSEFirstSeenRule
96+
id := d.Id()
97+
98+
CSEFirstSeenRuleGet, err := c.GetCSEFirstSeenRule(id)
99+
if err != nil {
100+
log.Printf("[WARN] CSE FirstSeen Rule not found when looking by id: %s, err: %v", id, err)
101+
}
102+
103+
if CSEFirstSeenRuleGet == nil {
104+
log.Printf("[WARN] CSE FirstSeen Rule not found, removing from state: %v - %v", id, err)
105+
d.SetId("")
106+
return nil
107+
}
108+
109+
d.Set("baseline_type", CSEFirstSeenRuleGet.BaselineType)
110+
d.Set("baseline_window_size", CSEFirstSeenRuleGet.BaselineWindowSize)
111+
d.Set("description_expression", CSEFirstSeenRuleGet.DescriptionExpression)
112+
d.Set("enabled", CSEFirstSeenRuleGet.Enabled)
113+
d.Set("entity_selectors", entitySelectorArrayToResource(CSEFirstSeenRuleGet.EntitySelectors))
114+
d.Set("filter_expression", CSEFirstSeenRuleGet.FilterExpression)
115+
d.Set("group_by_fields", CSEFirstSeenRuleGet.GroupByFields)
116+
d.Set("is_prototype", CSEFirstSeenRuleGet.IsPrototype)
117+
d.Set("name", CSEFirstSeenRuleGet.Name)
118+
d.Set("name_expression", CSEFirstSeenRuleGet.NameExpression)
119+
d.Set("retention_window_size", CSEFirstSeenRuleGet.RetentionWindowSize)
120+
d.Set("severity", CSEFirstSeenRuleGet.Severity)
121+
d.Set("summary_expression", CSEFirstSeenRuleGet.SummaryExpression)
122+
d.Set("tags", CSEFirstSeenRuleGet.Tags)
123+
d.Set("value_fields", CSEFirstSeenRuleGet.ValueFields)
124+
125+
return nil
126+
}
127+
128+
func resourceSumologicCSEFirstSeenRuleDelete(d *schema.ResourceData, meta interface{}) error {
129+
c := meta.(*Client)
130+
131+
return c.DeleteCSEFirstSeenRule(d.Id())
132+
133+
}
134+
135+
func resourceSumologicCSEFirstSeenRuleCreate(d *schema.ResourceData, meta interface{}) error {
136+
c := meta.(*Client)
137+
138+
if d.Id() == "" {
139+
id, err := c.CreateCSEFirstSeenRule(CSEFirstSeenRule{
140+
BaselineType: d.Get("baseline_type").(string),
141+
BaselineWindowSize: d.Get("baseline_window_size").(string),
142+
DescriptionExpression: d.Get("description_expression").(string),
143+
Enabled: d.Get("enabled").(bool),
144+
EntitySelectors: resourceToEntitySelectorArray(d.Get("entity_selectors").([]interface{})),
145+
FilterExpression: d.Get("filter_expression").(string),
146+
GroupByFields: resourceToStringArray(d.Get("group_by_fields").([]interface{})),
147+
IsPrototype: d.Get("is_prototype").(bool),
148+
Name: d.Get("name").(string),
149+
NameExpression: d.Get("name_expression").(string),
150+
RetentionWindowSize: d.Get("retention_window_size").(string),
151+
Severity: d.Get("severity").(int),
152+
SummaryExpression: d.Get("summary_expression").(string),
153+
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
154+
ValueFields: resourceToStringArray(d.Get("value_fields").([]interface{})),
155+
Version: 1,
156+
})
157+
158+
if err != nil {
159+
return err
160+
}
161+
d.SetId(id)
162+
}
163+
164+
return resourceSumologicCSEFirstSeenRuleRead(d, meta)
165+
}
166+
167+
func resourceSumologicCSEFirstSeenRuleUpdate(d *schema.ResourceData, meta interface{}) error {
168+
CSEFirstSeenRule, err := resourceToCSEFirstSeenRule(d)
169+
if err != nil {
170+
return err
171+
}
172+
173+
c := meta.(*Client)
174+
if err = c.UpdateCSEFirstSeenRule(CSEFirstSeenRule); err != nil {
175+
return err
176+
}
177+
178+
return resourceSumologicCSEFirstSeenRuleRead(d, meta)
179+
}
180+
181+
func resourceToCSEFirstSeenRule(d *schema.ResourceData) (CSEFirstSeenRule, error) {
182+
id := d.Id()
183+
if id == "" {
184+
return CSEFirstSeenRule{}, nil
185+
}
186+
187+
return CSEFirstSeenRule{
188+
ID: id,
189+
BaselineType: d.Get("baseline_type").(string),
190+
BaselineWindowSize: d.Get("baseline_window_size").(string),
191+
DescriptionExpression: d.Get("description_expression").(string),
192+
Enabled: d.Get("enabled").(bool),
193+
EntitySelectors: resourceToEntitySelectorArray(d.Get("entity_selectors").([]interface{})),
194+
FilterExpression: d.Get("filter_expression").(string),
195+
GroupByFields: resourceToStringArray(d.Get("group_by_fields").([]interface{})),
196+
IsPrototype: d.Get("is_prototype").(bool),
197+
Name: d.Get("name").(string),
198+
NameExpression: d.Get("name_expression").(string),
199+
RetentionWindowSize: d.Get("retention_window_size").(string),
200+
Severity: d.Get("severity").(int),
201+
SummaryExpression: d.Get("summary_expression").(string),
202+
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
203+
ValueFields: resourceToStringArray(d.Get("value_fields").([]interface{})),
204+
Version: 1,
205+
}, nil
206+
}

0 commit comments

Comments
 (0)