Skip to content

Commit ed51611

Browse files
BE-468: Add test
1 parent bc6a24e commit ed51611

File tree

3 files changed

+405
-51
lines changed

3 files changed

+405
-51
lines changed

sumologic/resource_sumologic_scan_budget.go

Lines changed: 109 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Sumo Logic and manual
8+
// changes will be clobbered when the file is regenerated. Do not submit
9+
// changes to this file.
10+
//
11+
// ----------------------------------------------------------------------------
112
package sumologic
213

314
import (
@@ -24,12 +35,6 @@ func resourceSumologicScanBudget() *schema.Resource {
2435
ForceNew: false,
2536
},
2637

27-
"orgId": {
28-
Type: schema.TypeString,
29-
Required: true,
30-
ForceNew: false,
31-
},
32-
3338
"capacity": {
3439
Type: schema.TypeInt,
3540
Required: true,
@@ -42,7 +47,7 @@ func resourceSumologicScanBudget() *schema.Resource {
4247
ForceNew: false,
4348
},
4449

45-
"budgetType": {
50+
"budget_type": {
4651
Type: schema.TypeString,
4752
Required: true,
4853
ForceNew: false,
@@ -54,24 +59,54 @@ func resourceSumologicScanBudget() *schema.Resource {
5459
ForceNew: false,
5560
},
5661

57-
"groupBy": {
62+
"group_by": {
5863
Type: schema.TypeString,
5964
Required: true,
6065
ForceNew: false,
6166
},
6267

63-
"applicableOn": {
68+
"applicable_on": {
6469
Type: schema.TypeString,
6570
Required: true,
6671
ForceNew: false,
6772
},
6873

6974
"scope": {
70-
Type: schema.TypeMap,
75+
Type: schema.TypeList,
7176
Required: true,
7277
ForceNew: false,
73-
Elem: &schema.Schema{
74-
Type: schema.TypeList,
78+
MaxItems: 1,
79+
Elem: &schema.Resource{
80+
Schema: map[string]*schema.Schema{
81+
"included_users": {
82+
Type: schema.TypeList,
83+
Optional: true,
84+
Elem: &schema.Schema{
85+
Type: schema.TypeString,
86+
},
87+
},
88+
"excluded_users": {
89+
Type: schema.TypeList,
90+
Optional: true,
91+
Elem: &schema.Schema{
92+
Type: schema.TypeString,
93+
},
94+
},
95+
"included_roles": {
96+
Type: schema.TypeList,
97+
Optional: true,
98+
Elem: &schema.Schema{
99+
Type: schema.TypeString,
100+
},
101+
},
102+
"excluded_roles": {
103+
Type: schema.TypeList,
104+
Optional: true,
105+
Elem: &schema.Schema{
106+
Type: schema.TypeString,
107+
},
108+
},
109+
},
75110
},
76111
},
77112

@@ -110,28 +145,27 @@ func resourceSumologicScanBudgetRead(d *schema.ResourceData, meta interface{}) e
110145
c := meta.(*Client)
111146

112147
id := d.Id()
113-
ScanBudget, err := c.GetScanBudget(id)
148+
scanBudget, err := c.GetScanBudget(id)
114149
if err != nil {
115150
return err
116151
}
117152

118-
if ScanBudget == nil {
153+
if scanBudget == nil {
119154
log.Printf("[WARN] ScanBudget not found, removing from state: %v - %v", id, err)
120155
d.SetId("")
121156
return nil
122157
}
123158

124-
d.Set("name", ScanBudget.Name)
125-
d.Set("orgId", ScanBudget.OrgID)
126-
d.Set("capacity", ScanBudget.Capacity)
127-
d.Set("unit", ScanBudget.Unit)
128-
d.Set("budgetType", ScanBudget.BudgetType)
129-
d.Set("window", ScanBudget.Window)
130-
d.Set("applicableOn", ScanBudget.Grouping)
131-
d.Set("groupBy", ScanBudget.GroupingEntity)
132-
d.Set("action", ScanBudget.Action)
133-
d.Set("scope", ScanBudget.Scope)
134-
d.Set("status", ScanBudget.Status)
159+
d.Set("name", scanBudget.Name)
160+
d.Set("capacity", scanBudget.Capacity)
161+
d.Set("unit", scanBudget.Unit)
162+
d.Set("budget_type", scanBudget.BudgetType)
163+
d.Set("window", scanBudget.Window)
164+
d.Set("applicable_on", scanBudget.ApplicableOn)
165+
d.Set("group_by", scanBudget.GroupBy)
166+
d.Set("action", scanBudget.Action)
167+
d.Set("scope", scanBudget.Scope)
168+
d.Set("status", scanBudget.Status)
135169

136170
return nil
137171
}
@@ -145,8 +179,8 @@ func resourceSumologicScanBudgetDelete(d *schema.ResourceData, meta interface{})
145179
func resourceSumologicScanBudgetUpdate(d *schema.ResourceData, meta interface{}) error {
146180
c := meta.(*Client)
147181

148-
ScanBudget := resourceToScanBudget(d)
149-
err := c.UpdateScanBudget(ScanBudget)
182+
scanBudget := resourceToScanBudget(d)
183+
err := c.UpdateScanBudget(scanBudget)
150184
if err != nil {
151185
return err
152186
}
@@ -156,17 +190,53 @@ func resourceSumologicScanBudgetUpdate(d *schema.ResourceData, meta interface{})
156190

157191
func resourceToScanBudget(d *schema.ResourceData) ScanBudget {
158192
return ScanBudget{
159-
ID: d.Id(),
160-
OrgID: d.Get("orgId").(string),
161-
Name: d.Get("name").(string),
162-
Capacity: d.Get("capacity").(int),
163-
Unit: d.Get("unit").(string),
164-
BudgetType: d.Get("budgetType").(string),
165-
Window: d.Get("window").(string),
166-
Grouping: d.Get("applicableOn").(string),
167-
GroupingEntity: d.Get("groupBy").(string),
168-
Action: d.Get("action").(string),
169-
Scope: d.Get("scope").(map[string]interface{}),
170-
Status: d.Get("status").(string),
193+
ID: d.Id(),
194+
Name: d.Get("name").(string),
195+
Capacity: d.Get("capacity").(int),
196+
Unit: d.Get("unit").(string),
197+
BudgetType: d.Get("budget_type").(string),
198+
Window: d.Get("window").(string),
199+
ApplicableOn: d.Get("applicable_on").(string),
200+
GroupBy: d.Get("group_by").(string),
201+
Action: d.Get("action").(string),
202+
Scope: resourceToScanBudgetScope(d.Get("scope")),
203+
Status: d.Get("status").(string),
204+
}
205+
}
206+
207+
func resourceToScanBudgetScope(data interface{}) ScanBudgetScope {
208+
scopeMap, ok := data.([]interface{})[0].(map[string]interface{})
209+
if !ok {
210+
return ScanBudgetScope{}
211+
}
212+
213+
scanBudgetScope := ScanBudgetScope{
214+
IncludedUsers: convertToStringSlice(scopeMap["included_users"]),
215+
ExcludedUsers: convertToStringSlice(scopeMap["excluded_users"]),
216+
IncludedRoles: convertToStringSlice(scopeMap["included_roles"]),
217+
ExcludedRoles: convertToStringSlice(scopeMap["excluded_roles"]),
218+
}
219+
220+
return scanBudgetScope
221+
}
222+
223+
func convertToStringSlice(data interface{}) []string {
224+
if data == nil {
225+
return nil
171226
}
227+
228+
interfaceSlice, ok := data.([]interface{})
229+
if !ok {
230+
return nil
231+
}
232+
233+
stringSlice := make([]string, len(interfaceSlice))
234+
for i, v := range interfaceSlice {
235+
str, ok := v.(string)
236+
if ok {
237+
stringSlice[i] = str
238+
}
239+
}
240+
241+
return stringSlice
172242
}

0 commit comments

Comments
 (0)