@@ -24,6 +24,10 @@ func dataSourceSumoLogicApps() *schema.Resource {
2424 Type : schema .TypeString ,
2525 Optional : true ,
2626 },
27+ "id" : {
28+ Type : schema .TypeString ,
29+ Computed : true ,
30+ },
2731 "apps" : {
2832 Type : schema .TypeList ,
2933 Computed : true ,
@@ -44,9 +48,33 @@ func dataSourceSumoLogicApps() *schema.Resource {
4448 "installs" : {Type : schema .TypeInt , Computed : true },
4549 "app_type" : {Type : schema .TypeString , Computed : true },
4650 "attributes" : {
47- Type : schema .TypeMap ,
48- Computed : true ,
49- Elem : & schema.Schema {Type : schema .TypeList , Elem : & schema.Schema {Type : schema .TypeString }},
51+ Type : schema .TypeList ,
52+ Optional : true ,
53+ Elem : & schema.Resource {
54+ Schema : map [string ]* schema.Schema {
55+ "category" : {
56+ Type : schema .TypeList ,
57+ Optional : true ,
58+ Elem : & schema.Schema {
59+ Type : schema .TypeString ,
60+ },
61+ },
62+ "use_case" : {
63+ Type : schema .TypeList ,
64+ Optional : true ,
65+ Elem : & schema.Schema {
66+ Type : schema .TypeString ,
67+ },
68+ },
69+ "collection" : {
70+ Type : schema .TypeList ,
71+ Optional : true ,
72+ Elem : & schema.Schema {
73+ Type : schema .TypeString ,
74+ },
75+ },
76+ },
77+ },
5078 },
5179 "family" : {Type : schema .TypeString , Computed : true },
5280 "installable" : {Type : schema .TypeBool , Computed : true },
@@ -58,25 +86,29 @@ func dataSourceSumoLogicApps() *schema.Resource {
5886 }
5987}
6088
61- func dataSourceSumoLogicAppsRead (d * schema.ResourceData , m interface {}) error {
62- c := m .(* Client )
89+ func dataSourceSumoLogicAppsRead (d * schema.ResourceData , meta interface {}) error {
90+ c := meta .(* Client )
6391
6492 // Read apps from the API
65- id , apps , err := c .getApps (d .Get ("name" ).(string ), d .Get ("author" ).(string ))
93+ id , fapps , err := c .getApps (d .Get ("name" ).(string ), d .Get ("author" ).(string ))
6694 if err != nil {
6795 return err
6896 }
6997
70- if err := d .Set ("apps" , flattenApps (apps )); err != nil {
71- return err
72- }
98+ // if err := d.Set("apps", flattenApps(apps)); err != nil {
99+ // return err
100+ // }
73101
102+ //fmt.Printf("%v\n", apps)
74103 d .SetId (id )
104+ fmt .Printf ("%v\n " , fapps )
105+ d .Set ("apps" , fapps )
106+ fmt .Printf ("%v\n " , d .Get ("apps" ))
75107
76108 return nil
77109}
78110
79- func (s * Client ) getApps (name string , author string ) (string , []App , error ) {
111+ func (s * Client ) getApps (name string , author string ) (string , []interface {} , error ) {
80112 // Construct the base URL
81113 baseURL := "v2/apps"
82114
@@ -102,14 +134,15 @@ func (s *Client) getApps(name string, author string) (string, []App, error) {
102134
103135 apps := AppsResponse {}
104136 err = json .Unmarshal (data , & apps )
137+ //fmt.Printf("%v\n", apps)
105138 if err != nil {
106139 return "" , nil , err
107140 }
108141
109142 // Generate a unique ID for this data source
110143 id := generateDataSourceId (name , author , apps .Apps )
111144
112- return id , apps .Apps , nil
145+ return id , flattenApps ( apps .Apps ) , nil
113146}
114147
115148func generateDataSourceId (name string , author string , apps []App ) string {
@@ -136,6 +169,16 @@ func generateDataSourceId(name string, author string, apps []App) string {
136169func flattenApps (apps []App ) []interface {} {
137170 var flattenedApps []interface {}
138171 for _ , app := range apps {
172+
173+ //attributes := make([]interface{}, 1)
174+ internalAttributes := make (map [string ]interface {})
175+ internalAttributes ["category" ] = app .Attributes .Category
176+ internalAttributes ["use_case" ] = app .Attributes .UseCase
177+ internalAttributes ["collection" ] = app .Attributes .Collection
178+ attributes := []interface {}{
179+ internalAttributes ,
180+ }
181+
139182 flattenedApp := map [string ]interface {}{
140183 "uuid" : app .UUID ,
141184 "name" : app .Name ,
@@ -147,7 +190,7 @@ func flattenApps(apps []App) []interface{} {
147190 "beta" : app .Beta ,
148191 "installs" : app .Installs ,
149192 "app_type" : app .AppType ,
150- "attributes" : app . Attributes ,
193+ "attributes" : attributes ,
151194 "family" : app .Family ,
152195 "installable" : app .Installable ,
153196 "show_on_marketplace" : app .ShowOnMarketplace ,
@@ -157,23 +200,37 @@ func flattenApps(apps []App) []interface{} {
157200 return flattenedApps
158201}
159202
203+ // Helper function to convert []string to []interface{}
204+ func convertStringSliceToInterfaceSlice (input []string ) []interface {} {
205+ result := make ([]interface {}, len (input ))
206+ for i , v := range input {
207+ result [i ] = v
208+ }
209+ fmt .Printf ("%v\n " , result )
210+ return result
211+ }
212+
160213type AppsResponse struct {
161214 Apps []App `json:"apps"`
162215}
163216
164217type App struct {
165- UUID string `json:"uuid"`
166- Name string `json:"name"`
167- Description string `json:"description"`
168- LatestVersion string `json:"latestVersion"`
169- Icon string `json:"icon"`
170- Author string `json:"author"`
171- AccountTypes []string `json:"accountTypes"`
172- Beta bool `json:"beta"`
173- Installs int `json:"installs"`
174- AppType string `json:"appType"`
175- Attributes map [string ]interface {} `json:"attributes"`
176- Family string `json:"family"`
177- Installable bool `json:"installable"`
178- ShowOnMarketplace bool `json:"showOnMarketplace"`
218+ UUID string `json:"uuid"`
219+ Name string `json:"name"`
220+ Description string `json:"description"`
221+ LatestVersion string `json:"latestVersion"`
222+ Icon string `json:"icon"`
223+ Author string `json:"author"`
224+ AccountTypes []string `json:"accountTypes"`
225+ Beta bool `json:"beta"`
226+ Installs int `json:"installs"`
227+ AppType string `json:"appType"`
228+ Attributes struct {
229+ Category []string `json:"category"`
230+ UseCase []string `json:"useCase"`
231+ Collection []string `json:"collection"`
232+ } `json:"attributes"`
233+ Family string `json:"family"`
234+ Installable bool `json:"installable"`
235+ ShowOnMarketplace bool `json:"showOnMarketplace"`
179236}
0 commit comments