@@ -62,6 +62,7 @@ func resourceSumologicDashboard() *schema.Resource {
6262 Type : schema .TypeString ,
6363 Optional : true ,
6464 },
65+ // FIXME: topology_label_map doesn't work. Don't use it!
6566 "topology_label_map" : {
6667 Type : schema .TypeList ,
6768 Optional : true ,
@@ -135,10 +136,31 @@ func resourceSumologicDashboard() *schema.Resource {
135136}
136137
137138func getPanelSchema () map [string ]* schema.Schema {
139+ return map [string ]* schema.Schema {
140+ "sumo_search_panel" : {
141+ Type : schema .TypeList ,
142+ Optional : true ,
143+ MaxItems : 1 ,
144+ Elem : & schema.Resource {
145+ Schema : getSumoSearchPanelSchema (),
146+ },
147+ },
148+ "text_panel" : {
149+ Type : schema .TypeList ,
150+ Optional : true ,
151+ MaxItems : 1 ,
152+ Elem : & schema.Resource {
153+ Schema : getTextPanelSchema (),
154+ },
155+ },
156+ }
157+ }
158+
159+ func getPanelBaseSchema () map [string ]* schema.Schema {
138160 return map [string ]* schema.Schema {
139161 "id" : {
140162 Type : schema .TypeString ,
141- Optional : true ,
163+ Computed : true ,
142164 },
143165 "key" : {
144166 Type : schema .TypeString ,
@@ -157,37 +179,29 @@ func getPanelSchema() map[string]*schema.Schema {
157179 Optional : true ,
158180 Default : true ,
159181 },
160- // Need to be set for EventsOfInterestScatterPanel only
161- "panel_type" : {
182+ }
183+ }
184+
185+ func getTextPanelSchema () map [string ]* schema.Schema {
186+ panelSchema := getPanelBaseSchema ()
187+
188+ textPanelSchema := map [string ]* schema.Schema {
189+ "text" : {
162190 Type : schema .TypeString ,
163191 Optional : true ,
164192 },
165- "sumo_search_panel" : {
166- Type : schema .TypeList ,
167- Optional : true ,
168- MaxItems : 1 ,
169- Elem : & schema.Resource {
170- Schema : getSumoSearchPanelSchema (),
171- },
172- },
173- "text_panel" : {
174- Type : schema .TypeList ,
175- Optional : true ,
176- MaxItems : 1 ,
177- Elem : & schema.Resource {
178- Schema : map [string ]* schema.Schema {
179- "text" : {
180- Type : schema .TypeString ,
181- Optional : true ,
182- },
183- },
184- },
185- },
186193 }
194+ for k , v := range textPanelSchema {
195+ panelSchema [k ] = v
196+ }
197+
198+ return panelSchema
187199}
188200
189201func getSumoSearchPanelSchema () map [string ]* schema.Schema {
190- return map [string ]* schema.Schema {
202+ panelSchema := getPanelBaseSchema ()
203+
204+ searchPanelSchema := map [string ]* schema.Schema {
191205 "query" : {
192206 Type : schema .TypeList ,
193207 Optional : true ,
@@ -243,6 +257,12 @@ func getSumoSearchPanelSchema() map[string]*schema.Schema {
243257 },
244258 },
245259 }
260+
261+ for k , v := range searchPanelSchema {
262+ panelSchema [k ] = v
263+ }
264+
265+ return panelSchema
246266}
247267
248268func getSumoSearchPanelQuerySchema () map [string ]* schema.Schema {
@@ -687,92 +707,86 @@ func resourceToDashboard(d *schema.ResourceData) Dashboard {
687707}
688708
689709func getPanel (tfPanel map [string ]interface {}) interface {} {
690- if len (tfPanel ["text_panel" ].([]interface {})) == 1 {
691- return getTextPanel (tfPanel )
692- } else if len (tfPanel ["sumo_search_panel" ].([]interface {})) == 1 {
693- return getSumoSearchPanel (tfPanel )
710+ if val := tfPanel ["text_panel" ].([]interface {}); len (val ) == 1 {
711+ if tfTextPanel , ok := val [0 ].(map [string ]interface {}); ok {
712+ return getTextPanel (tfTextPanel )
713+ }
714+ } else if val := tfPanel ["sumo_search_panel" ].([]interface {}); len (val ) == 1 {
715+ if tfSearchPanel , ok := val [0 ].(map [string ]interface {}); ok {
716+ return getSumoSearchPanel (tfSearchPanel )
717+ }
694718 }
695719 return nil
696720}
697721
698- func getTextPanel (tfPanel map [string ]interface {}) interface {} {
722+ func getTextPanel (tfTextPanel map [string ]interface {}) interface {} {
699723 var textPanel TextPanel
700724 textPanel .PanelType = "TextPanel"
701725
702- if key , ok := tfPanel ["key" ].(string ); ok {
703- textPanel .Key = key
704- }
705- if title , ok := tfPanel ["title" ].(string ); ok {
726+ textPanel .Key = tfTextPanel ["key" ].(string )
727+ if title , ok := tfTextPanel ["title" ].(string ); ok {
706728 textPanel .Title = title
707729 }
708- if visualSettings , ok := tfPanel ["visual_settings" ].(string ); ok {
730+ if visualSettings , ok := tfTextPanel ["visual_settings" ].(string ); ok {
709731 textPanel .VisualSettings = visualSettings
710732 }
711- if consistentVisualSettings , ok := tfPanel ["keep_visual_settings_consistent_with_parent" ].(bool ); ok {
733+ if consistentVisualSettings , ok := tfTextPanel ["keep_visual_settings_consistent_with_parent" ].(bool ); ok {
712734 textPanel .KeepVisualSettingsConsistentWithParent = consistentVisualSettings
713735 }
714736
715737 // text panel specific properties
716- if val , ok := tfPanel ["text_panel" ].([]interface {}); ok {
717- if tfTextPanel , ok := val [0 ].(map [string ]interface {}); ok {
718- textPanel .Text = tfTextPanel ["text" ].(string )
719- }
720- }
738+ textPanel .Text = tfTextPanel ["text" ].(string )
721739 return textPanel
722740}
723741
724- func getSumoSearchPanel (tfPanel map [string ]interface {}) interface {} {
742+ func getSumoSearchPanel (tfSearchPanel map [string ]interface {}) interface {} {
725743 var searchPanel SumoSearchPanel
726744 searchPanel .PanelType = "SumoSearchPanel"
727745
728- if key , ok := tfPanel ["key" ].(string ); ok {
729- searchPanel .Key = key
730- }
731- if title , ok := tfPanel ["title" ].(string ); ok {
746+ searchPanel .Key = tfSearchPanel ["key" ].(string )
747+ if title , ok := tfSearchPanel ["title" ].(string ); ok {
732748 searchPanel .Title = title
733749 }
734- if visualSettings , ok := tfPanel ["visual_settings" ].(string ); ok {
750+ if visualSettings , ok := tfSearchPanel ["visual_settings" ].(string ); ok {
735751 searchPanel .VisualSettings = visualSettings
736752 }
737- if consistentVisualSettings , ok := tfPanel ["keep_visual_settings_consistent_with_parent" ].(bool ); ok {
753+ if consistentVisualSettings , ok := tfSearchPanel ["keep_visual_settings_consistent_with_parent" ].(bool ); ok {
738754 searchPanel .KeepVisualSettingsConsistentWithParent = consistentVisualSettings
739755 }
740756
741757 // search panel specific properties
742- if val , ok := tfPanel ["sumo_search_panel" ].([]interface {}); ok {
743- tfSearchPanel := val [0 ].(map [string ]interface {})
744- if description , ok := tfSearchPanel ["description" ].(string ); ok {
745- searchPanel .Description = description
746- }
747- if val , ok := tfSearchPanel ["time_range" ]; ok {
748- tfTimeRange := val .([]interface {})[0 ]
749- searchPanel .TimeRange = getTimeRange (tfTimeRange .(map [string ]interface {}))
750- }
758+ if description , ok := tfSearchPanel ["description" ].(string ); ok {
759+ searchPanel .Description = description
760+ }
761+ if val , ok := tfSearchPanel ["time_range" ]; ok {
762+ tfTimeRange := val .([]interface {})[0 ]
763+ searchPanel .TimeRange = getTimeRange (tfTimeRange .(map [string ]interface {}))
764+ }
751765
752- tfQueries := tfSearchPanel ["query" ].([]interface {})
753- var queries []SearchPanelQuery
754- for _ , tfQuery := range tfQueries {
755- query := getSearchPanelQuery (tfQuery .(map [string ]interface {}))
756- queries = append (queries , query )
757- }
758- searchPanel .Queries = queries
766+ tfQueries := tfSearchPanel ["query" ].([]interface {})
767+ var queries []SearchPanelQuery
768+ for _ , tfQuery := range tfQueries {
769+ query := getSearchPanelQuery (tfQuery .(map [string ]interface {}))
770+ queries = append (queries , query )
771+ }
772+ searchPanel .Queries = queries
759773
760- tfColoringRules := tfSearchPanel ["coloring_rule" ].([]interface {})
761- var rules []ColoringRule
762- for _ , tfQuery := range tfColoringRules {
763- rule := getColoringRule (tfQuery .(map [string ]interface {}))
764- rules = append (rules , rule )
765- }
766- searchPanel .ColoringRules = rules
774+ tfColoringRules := tfSearchPanel ["coloring_rule" ].([]interface {})
775+ var rules []ColoringRule
776+ for _ , tfQuery := range tfColoringRules {
777+ rule := getColoringRule (tfQuery .(map [string ]interface {}))
778+ rules = append (rules , rule )
779+ }
780+ searchPanel .ColoringRules = rules
767781
768- tfLinkedDashboards := tfSearchPanel ["linked_dashboard" ].([]interface {})
769- var linkedDashboards []LinkedDashboard
770- for _ , tfLinkedDashboard := range tfLinkedDashboards {
771- linkedDashboard := getLinkedDashboard (tfLinkedDashboard .(map [string ]interface {}))
772- linkedDashboards = append (linkedDashboards , linkedDashboard )
773- }
774- searchPanel .LinkedDashboards = linkedDashboards
782+ tfLinkedDashboards := tfSearchPanel ["linked_dashboard" ].([]interface {})
783+ var linkedDashboards []LinkedDashboard
784+ for _ , tfLinkedDashboard := range tfLinkedDashboards {
785+ linkedDashboard := getLinkedDashboard (tfLinkedDashboard .(map [string ]interface {}))
786+ linkedDashboards = append (linkedDashboards , linkedDashboard )
775787 }
788+ searchPanel .LinkedDashboards = linkedDashboards
789+
776790 return searchPanel
777791}
778792
@@ -1184,21 +1198,8 @@ func getTerraformPanels(panels []interface{}) []map[string]interface{} {
11841198 panel := val .(map [string ]interface {})
11851199
11861200 tfPanel := map [string ]interface {}{}
1187- tfPanel ["key" ] = panel ["key" ]
1188- if title , ok := panel ["title" ]; ok {
1189- tfPanel ["title" ] = title
1190- }
1191- if visualSettings , ok := panel ["visualSettings" ]; ok {
1192- tfPanel ["visual_settings" ] = visualSettings
1193- }
1194- if keepVisualSettingsConsistentWithParent , ok := panel ["keepVisualSettingsConsistentWithParent" ]; ok {
1195- tfPanel ["keep_visual_settings_consistent_with_parent" ] = keepVisualSettingsConsistentWithParent
1196- }
1197-
11981201 if panel ["panelType" ] == "TextPanel" {
1199- textPanel := makeTerraformObject ()
1200- textPanel [0 ]["text" ] = panel ["text" ]
1201- tfPanel ["text_panel" ] = textPanel
1202+ tfPanel ["text_panel" ] = getTerraformTextPanel (panel )
12021203 } else if panel ["panelType" ] == "SumoSearchPanel" {
12031204 tfPanel ["sumo_search_panel" ] = getTerraformSearchPanel (panel )
12041205 }
@@ -1208,9 +1209,38 @@ func getTerraformPanels(panels []interface{}) []map[string]interface{} {
12081209 return tfPanels
12091210}
12101211
1212+ func getTerraformTextPanel (textPanel map [string ]interface {}) TerraformObject {
1213+ tfTextPanel := makeTerraformObject ()
1214+
1215+ tfTextPanel [0 ]["key" ] = textPanel ["key" ]
1216+ if title , ok := textPanel ["title" ]; ok {
1217+ tfTextPanel [0 ]["title" ] = title
1218+ }
1219+ if visualSettings , ok := textPanel ["visualSettings" ]; ok {
1220+ tfTextPanel [0 ]["visual_settings" ] = visualSettings
1221+ }
1222+ if keepVisualSettingsConsistentWithParent , ok := textPanel ["keepVisualSettingsConsistentWithParent" ]; ok {
1223+ tfTextPanel [0 ]["keep_visual_settings_consistent_with_parent" ] = keepVisualSettingsConsistentWithParent
1224+ }
1225+ tfTextPanel [0 ]["text" ] = textPanel ["text" ]
1226+
1227+ return tfTextPanel
1228+ }
1229+
12111230func getTerraformSearchPanel (searchPanel map [string ]interface {}) TerraformObject {
12121231 tfSearchPanel := makeTerraformObject ()
12131232
1233+ tfSearchPanel [0 ]["key" ] = searchPanel ["key" ]
1234+ if title , ok := searchPanel ["title" ]; ok {
1235+ tfSearchPanel [0 ]["title" ] = title
1236+ }
1237+ if visualSettings , ok := searchPanel ["visualSettings" ]; ok {
1238+ tfSearchPanel [0 ]["visual_settings" ] = visualSettings
1239+ }
1240+ if keepVisualSettingsConsistentWithParent , ok := searchPanel ["keepVisualSettingsConsistentWithParent" ]; ok {
1241+ tfSearchPanel [0 ]["keep_visual_settings_consistent_with_parent" ] = keepVisualSettingsConsistentWithParent
1242+ }
1243+
12141244 tfSearchPanel [0 ]["query" ] = getTerraformSearchPanelQuery (searchPanel ["queries" ].([]interface {}))
12151245 if description , ok := searchPanel ["description" ]; ok {
12161246 tfSearchPanel [0 ]["description" ] = description
0 commit comments