Skip to content

Commit a531368

Browse files
authored
Merge pull request #336 from SumoLogic/vishal-fix-topology-label
2 parents cc379df + 64a5773 commit a531368

File tree

6 files changed

+177
-175
lines changed

6 files changed

+177
-175
lines changed

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
## 2.12.0 (Unreleased)
22

3-
BUG FIXES:
4-
5-
* sumologic_cse_log_mapping split_index as int (GH-333)
6-
* Gcp Metrics Source (GH-329, 332)
3+
FEATURES:
4+
* **New Resource:** Gcp Metrics Source `sumologic_gcp_metrics_source` (GH-329, 332)
75

86
ENHANCEMENTS:
9-
107
* Add backoff on http 429s (GH-338)
118

9+
BUG FIXES:
10+
* Fix to allow more than one topology_label for Dashboard resource (GH-336)
11+
* sumologic_cse_log_mapping split_index as int (GH-333)
12+
1213
## 2.11.5 (December 14, 2021)
1314

1415
BUG FIXES:

sumologic/resource_sumologic_dashboard.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func resourceSumologicDashboard() *schema.Resource {
6969
Elem: &schema.Resource{
7070
Schema: map[string]*schema.Schema{
7171
"data": {
72-
Type: schema.TypeList,
72+
Type: schema.TypeSet,
7373
Required: true,
7474
Elem: &schema.Resource{
7575
Schema: map[string]*schema.Schema{
@@ -132,7 +132,7 @@ func resourceSumologicDashboard() *schema.Resource {
132132
ValidateFunc: validation.StringInSlice([]string{"Light", "Dark"}, true),
133133
Default: "Light",
134134
},
135-
// TODO Do we need this field in terraform?
135+
// TODO: This field is NOT supported. Remove it.
136136
"coloring_rule": {
137137
Type: schema.TypeList,
138138
Optional: true,
@@ -948,9 +948,9 @@ func getTimeRangeBoundary(tfRangeBoundary map[string]interface{}) interface{} {
948948
}
949949

950950
func getTopologyLabel(tfTopologyLabel map[string]interface{}) *TopologyLabel {
951-
if items := tfTopologyLabel["data"].([]interface{}); len(items) == 1 {
951+
if items := tfTopologyLabel["data"].(*schema.Set); items.Len() >= 1 {
952952
labelMap := make(map[string][]string)
953-
for _, item := range items {
953+
for _, item := range items.List() {
954954
dataItem := item.(map[string]interface{})
955955
key := dataItem["label"].(string)
956956
itemValues := dataItem["values"].([]interface{})
@@ -960,6 +960,7 @@ func getTopologyLabel(tfTopologyLabel map[string]interface{}) *TopologyLabel {
960960
}
961961
labelMap[key] = values
962962
}
963+
963964
return &TopologyLabel{
964965
Data: labelMap,
965966
}

sumologic/resource_sumologic_dashboard_test.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1212
)
1313

14+
var firstLabelKey = "service"
15+
var secondLabelKey = "env"
16+
var topologyLabel = TopologyLabel{
17+
Data: map[string][]string{
18+
firstLabelKey: {"collection-proxy"},
19+
secondLabelKey: {"dev", "prod"},
20+
},
21+
}
22+
1423
func TestAccSumologicDashboard_basic(t *testing.T) {
1524
testNameSuffix := acctest.RandString(16)
1625
title := "terraform_test_dashboard_" + testNameSuffix
@@ -41,8 +50,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
4150
description := "Test dashboard description"
4251
theme := "Dark"
4352
refreshInterval := 120
44-
topologyLabel := "service"
45-
topologyLabelValue := "collection-proxy"
53+
4654
literalRangeName := "today"
4755
textPanel := TextPanel{
4856
Key: "text-panel-001",
@@ -77,7 +85,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
7785
Steps: []resource.TestStep{
7886
{
7987
Config: dashboardCreateConfig(title, description, theme, refreshInterval,
80-
topologyLabel, topologyLabelValue, literalRangeName, textPanel, layout, variable),
88+
topologyLabel, literalRangeName, textPanel, layout, variable),
8189
Check: resource.ComposeTestCheckFunc(
8290
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
8391
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -89,9 +97,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
8997
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
9098
"theme", theme),
9199
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
92-
"topology_label_map.0.data.0.label", topologyLabel),
93-
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
94-
"topology_label_map.0.data.0.values.0", topologyLabelValue),
100+
"topology_label_map.0.data.#", "2"),
95101
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
96102
"time_range.#", "1"),
97103
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -124,8 +130,6 @@ func TestAccSumologicDashboard_update(t *testing.T) {
124130
description := "Test dashboard description"
125131
theme := "Dark"
126132
refreshInterval := 120
127-
topologyLabel := "service"
128-
topologyLabelValue := "collection-proxy"
129133
literalRangeName := "today"
130134
textPanel := TextPanel{
131135
Key: "text-panel-001",
@@ -155,7 +159,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
155159
// updated config
156160
newTheme := "Light"
157161
newRefreshInterval := 300
158-
newTopologyLabelValue := "collection-cluster"
162+
newFirstLabelValue := "collection-cluster"
159163
newLiteralRangeName := "week"
160164
searchPanel := SumoSearchPanel{
161165
Key: "search-panel-001",
@@ -207,7 +211,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
207211
Steps: []resource.TestStep{
208212
{
209213
Config: dashboardCreateConfig(title, description, theme, refreshInterval,
210-
topologyLabel, topologyLabelValue, literalRangeName, textPanel, layout, csvVariable),
214+
topologyLabel, literalRangeName, textPanel, layout, csvVariable),
211215
Check: resource.ComposeTestCheckFunc(
212216
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
213217
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -217,7 +221,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
217221
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
218222
"theme", theme),
219223
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
220-
"topology_label_map.0.data.0.values.0", topologyLabelValue),
224+
"topology_label_map.0.data.#", "2"),
221225
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
222226
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
223227
literalRangeName),
@@ -237,7 +241,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
237241
},
238242
{
239243
Config: dashboardUpdateConfig(title, description, newTheme, newRefreshInterval,
240-
topologyLabel, newTopologyLabelValue, newLiteralRangeName, textPanel, searchPanel,
244+
firstLabelKey, newFirstLabelValue, newLiteralRangeName, textPanel, searchPanel,
241245
newLayout, newVariables),
242246
Check: resource.ComposeTestCheckFunc(
243247
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
@@ -248,7 +252,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
248252
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
249253
"theme", newTheme),
250254
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
251-
"topology_label_map.0.data.0.values.0", newTopologyLabelValue),
255+
"topology_label_map.0.data.#", "1"),
252256
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
253257
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
254258
newLiteralRangeName),
@@ -391,8 +395,8 @@ func dashboardImportConfig(title string) string {
391395
}
392396

393397
func dashboardCreateConfig(title string, description string, theme string, refreshInterval int,
394-
topologyLabel string, topologyLabelValue string, rangeName string, textPanel TextPanel,
395-
layout GridLayout, variable Variable) string {
398+
topologyLabel TopologyLabel, rangeName string, textPanel TextPanel, layout GridLayout,
399+
variable Variable) string {
396400

397401
return fmt.Sprintf(`
398402
data "sumologic_personal_folder" "personalFolder" {}
@@ -407,6 +411,10 @@ func dashboardCreateConfig(title string, description string, theme string, refre
407411
label = "%s"
408412
values = ["%s"]
409413
}
414+
data {
415+
label = "%s"
416+
values = ["%s", "%s"]
417+
}
410418
}
411419
time_range {
412420
begin_bounded_time_range {
@@ -448,8 +456,9 @@ func dashboardCreateConfig(title string, description string, theme string, refre
448456
hide_from_ui = false
449457
}
450458
}`,
451-
title, description, refreshInterval, theme, topologyLabel, topologyLabelValue, rangeName,
452-
textPanel.Key, textPanel.Title, textPanel.Text,
459+
title, description, refreshInterval, theme, firstLabelKey, topologyLabel.Data[firstLabelKey][0],
460+
secondLabelKey, topologyLabel.Data[secondLabelKey][0], topologyLabel.Data[secondLabelKey][1],
461+
rangeName, textPanel.Key, textPanel.Title, textPanel.Text,
453462
layout.LayoutStructures[0].Key, variable.Name, variable.DisplayName, variable.DefaultValue,
454463
variable.SourceDefinition.(CsvVariableSourceDefinition).Values,
455464
)

0 commit comments

Comments
 (0)