@@ -9,10 +9,11 @@ import (
99)
1010
1111const (
12- contextConfig = "config"
13- contextSecret = "secret"
14- contextYaml = "yaml"
15- contextSecretYaml = "secret-yaml"
12+ contextConfig = "config"
13+ contextSecret = "secret"
14+ contextYaml = "yaml"
15+ contextSecretYaml = "secret-yaml"
16+ contextGoogleStorage = "storage.gc"
1617)
1718
1819var supportedContextType = []string {
@@ -135,6 +136,43 @@ func resourceContext() *schema.Resource {
135136 },
136137 },
137138 },
139+ normalizeFieldName (contextGoogleStorage ): {
140+ Type : schema .TypeList ,
141+ Optional : true ,
142+ ForceNew : true ,
143+ MaxItems : 1 ,
144+ ConflictsWith : getConflictingContexts (contextGoogleStorage ),
145+ Elem : & schema.Resource {
146+ Schema : map [string ]* schema.Schema {
147+ "data" : {
148+ Type : schema .TypeList ,
149+ Required : true ,
150+ MaxItems : 1 ,
151+ Elem : & schema.Resource {
152+ Schema : map [string ]* schema.Schema {
153+ "auth" : {
154+ Type : schema .TypeList ,
155+ Required : true ,
156+ MaxItems : 1 ,
157+ Elem : & schema.Resource {
158+ Schema : map [string ]* schema.Schema {
159+ "type" : {
160+ Type : schema .TypeString ,
161+ Required : true ,
162+ },
163+ "json_config" : {
164+ Type : schema .TypeMap ,
165+ Required : true ,
166+ },
167+ },
168+ },
169+ },
170+ },
171+ },
172+ },
173+ },
174+ },
175+ },
138176 },
139177 },
140178 },
@@ -239,6 +277,8 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
239277 m [normalizeFieldName (currentContextType )] = flattenContextConfig (spec )
240278 case contextYaml , contextSecretYaml :
241279 m [normalizeFieldName (currentContextType )] = flattenContextYaml (spec )
280+ case contextGoogleStorage :
281+ m [normalizeFieldName (currentContextType )] = flattenStorageContextConfig (spec )
242282 default :
243283 log .Printf ("[DEBUG] Invalid context type = %v" , currentContextType )
244284 return nil
@@ -256,6 +296,40 @@ func flattenContextConfig(spec cfClient.ContextSpec) []interface{} {
256296 return res
257297}
258298
299+ func flattenStorageContextConfig (spec cfClient.ContextSpec ) []interface {} {
300+ //google.[0].data[0].auth[0].[type, json]
301+
302+ var res = make ([]interface {}, 0 )
303+ m := make (map [string ]interface {})
304+
305+ dataList := make ([]interface {}, 0 )
306+ data := make (map [string ]interface {})
307+
308+ auth := make (map [string ]interface {})
309+ auth ["json_config" ] = spec .Data ["auth" ].(map [string ]interface {})["jsonConfig" ]
310+ auth ["type" ] = spec .Data ["type" ]
311+
312+ authList := make ([]interface {}, 0 )
313+ authList = append (authList , auth )
314+
315+ data ["auth" ] = authList
316+
317+ dataList = append (dataList , data )
318+
319+ m ["data" ] = dataList
320+ res = append (res , m )
321+ return res
322+
323+ //contextData := context[0].(map[string]interface{})
324+ //contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{})
325+ //data := make(map[string]interface{})
326+ //auth := make(map[string]interface{})
327+ //auth["type"] = contextAuth["type"]
328+ //auth["jsonConfig"] = contextAuth["json_config"]
329+ //data["auth"] = auth
330+ //return data
331+ }
332+
259333func flattenContextYaml (spec cfClient.ContextSpec ) []interface {} {
260334 var res = make ([]interface {}, 0 )
261335 m := make (map [string ]interface {})
@@ -268,11 +342,25 @@ func flattenContextYaml(spec cfClient.ContextSpec) []interface{} {
268342 return res
269343}
270344
345+ func convertStorageContext (context []interface {}) map [string ]interface {} {
346+ contextData := context [0 ].(map [string ]interface {})
347+ contextAuth := contextData ["auth" ].([]interface {})[0 ].(map [string ]interface {})
348+ data := make (map [string ]interface {})
349+ auth := make (map [string ]interface {})
350+ auth ["type" ] = contextAuth ["type" ]
351+ auth ["jsonConfig" ] = contextAuth ["json_config" ]
352+ data ["auth" ] = auth
353+ return data
354+ }
355+
271356func mapResourceToContext (d * schema.ResourceData ) * cfClient.Context {
272357
273358 var normalizedContextType string
274359 var normalizedContextData map [string ]interface {}
275360
361+ spec := d .Get ("spec" )
362+ log .Println (spec )
363+
276364 if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextConfig ) + ".0.data" ); ok {
277365 normalizedContextType = contextConfig
278366 normalizedContextData = data .(map [string ]interface {})
@@ -285,6 +373,9 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
285373 } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextSecretYaml ) + ".0.data" ); ok {
286374 normalizedContextType = contextSecretYaml
287375 yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
376+ } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextGoogleStorage ) + ".0.data" ); ok {
377+ normalizedContextType = contextGoogleStorage
378+ normalizedContextData = convertStorageContext (data .([]interface {}))
288379 }
289380
290381 context := & cfClient.Context {
0 commit comments