@@ -149,29 +149,28 @@ func parseServiceChainingId(id string) (string, string, string, error) {
149149
150150func buildServiceChainingPayload (name , nodeFilter string , serviceNodes []interface {}) map [string ]interface {} {
151151 serviceNodesPayload := make ([]interface {}, 0 , len (serviceNodes ))
152- for i , sn := range serviceNodes {
153- node := sn .(map [string ]interface {})
154- idx := i + 1
152+ for i , serviceNode := range serviceNodes {
153+ node := serviceNode .(map [string ]interface {})
155154
156155 nodePayload := map [string ]interface {}{
157156 "name" : node ["name" ].(string ),
158157 "deviceType" : node ["device_type" ].(string ),
159158 "deviceRef" : node ["device_ref" ].(string ),
160- "index" : idx ,
159+ "index" : i + 1 ,
161160 }
162161
163- if ccList , ok := node ["consumer_connector" ].([]interface {}); ok && len (ccList ) > 0 {
164- cc := ccList [0 ].(map [string ]interface {})
162+ if consConnectorList , ok := node ["consumer_connector" ].([]interface {}); ok && len (consConnectorList ) > 0 {
163+ consConnector := consConnectorList [0 ].(map [string ]interface {})
165164 nodePayload ["consumerConnector" ] = map [string ]interface {}{
166- "interfaceName" : cc ["interface_name" ].(string ),
167- "isRedirect" : cc ["is_redirect" ].(bool ),
165+ "interfaceName" : consConnector ["interface_name" ].(string ),
166+ "isRedirect" : consConnector ["is_redirect" ].(bool ),
168167 }
169168 }
170- if pcList , ok := node ["provider_connector" ].([]interface {}); ok && len (pcList ) > 0 {
171- pc := pcList [0 ].(map [string ]interface {})
169+ if provConnectorList , ok := node ["provider_connector" ].([]interface {}); ok && len (provConnectorList ) > 0 {
170+ provConnector := provConnectorList [0 ].(map [string ]interface {})
172171 nodePayload ["providerConnector" ] = map [string ]interface {}{
173- "interfaceName" : pc ["interface_name" ].(string ),
174- "isRedirect" : pc ["is_redirect" ].(bool ),
172+ "interfaceName" : provConnector ["interface_name" ].(string ),
173+ "isRedirect" : provConnector ["is_redirect" ].(bool ),
175174 }
176175 }
177176
@@ -300,19 +299,19 @@ func setServiceChainingFromSchema(d *schema.ResourceData, schemaCont *container.
300299 }
301300
302301 var contractDetails map [string ]interface {}
303- for _ , t := range templates .([]interface {}) {
304- tm := t .(map [string ]interface {})
305- if tm ["name" ].(string ) == templateName {
302+ for _ , template := range templates .([]interface {}) {
303+ templateMap := template .(map [string ]interface {})
304+ if templateMap ["name" ].(string ) == templateName {
306305 d .Set ("template_name" , templateName )
307- contracts , ok := tm ["contracts" ].([]interface {})
306+ contracts , ok := templateMap ["contracts" ].([]interface {})
308307 if ! ok || len (contracts ) == 0 {
309308 return fmt .Errorf ("no contracts found in template %s" , templateName )
310309 }
311- for _ , c := range contracts {
312- cm := c .(map [string ]interface {})
313- if cm ["name" ].(string ) == contractName {
310+ for _ , contract := range contracts {
311+ contractMap := contract .(map [string ]interface {})
312+ if contractMap ["name" ].(string ) == contractName {
314313 d .Set ("contract_name" , contractName )
315- contractDetails = cm
314+ contractDetails = contractMap
316315 break
317316 }
318317 }
@@ -325,30 +324,30 @@ func setServiceChainingFromSchema(d *schema.ResourceData, schemaCont *container.
325324 return fmt .Errorf ("contract %s not found in template %s" , contractName , templateName )
326325 }
327326
328- scIface , ok := contractDetails ["serviceChaining" ]
329- if ! ok || scIface == nil {
327+ serviceChainingIface , ok := contractDetails ["serviceChaining" ]
328+ if ! ok || serviceChainingIface == nil {
330329 d .SetId ("" )
331330 return fmt .Errorf ("serviceChaining not found in contract %s" , contractName )
332331 }
333332
334- sc , ok := scIface .(map [string ]interface {})
333+ serviceChain , ok := serviceChainingIface .(map [string ]interface {})
335334 if ! ok {
336335 d .SetId ("" )
337336 return fmt .Errorf ("invalid serviceChaining structure in contract %s" , contractName )
338337 }
339338
340- if nameVal , ok := sc ["name" ].(string ); ok {
339+ if nameVal , ok := serviceChain ["name" ].(string ); ok {
341340 d .Set ("name" , nameVal )
342341 }
343342
344- if nf , ok := sc ["nodeFilter" ].(string ); ok {
345- d .Set ("node_filter" , nf )
343+ if nodeFilter , ok := serviceChain ["nodeFilter" ].(string ); ok {
344+ d .Set ("node_filter" , nodeFilter )
346345 }
347346
348- if sns , ok := sc ["serviceNodes" ].([]interface {}); ok {
349- out := make ([]interface {}, 0 , len (sns ))
350- for _ , sn := range sns {
351- nodeMap := sn .(map [string ]interface {})
347+ if serviceNodes , ok := serviceChain ["serviceNodes" ].([]interface {}); ok {
348+ out := make ([]interface {}, 0 , len (serviceNodes ))
349+ for _ , serviceNode := range serviceNodes {
350+ nodeMap := serviceNode .(map [string ]interface {})
352351 item := map [string ]interface {}{
353352 "name" : nodeMap ["name" ],
354353 "device_type" : nodeMap ["deviceType" ],
@@ -357,19 +356,19 @@ func setServiceChainingFromSchema(d *schema.ResourceData, schemaCont *container.
357356 "uuid" : nodeMap ["uuid" ],
358357 }
359358
360- if cc , ok := nodeMap ["consumerConnector" ].(map [string ]interface {}); ok {
359+ if consConnector , ok := nodeMap ["consumerConnector" ].(map [string ]interface {}); ok {
361360 item ["consumer_connector" ] = []interface {}{
362361 map [string ]interface {}{
363- "interface_name" : cc ["interfaceName" ],
364- "is_redirect" : cc ["isRedirect" ],
362+ "interface_name" : consConnector ["interfaceName" ],
363+ "is_redirect" : consConnector ["isRedirect" ],
365364 },
366365 }
367366 }
368- if pc , ok := nodeMap ["providerConnector" ].(map [string ]interface {}); ok {
367+ if provConnector , ok := nodeMap ["providerConnector" ].(map [string ]interface {}); ok {
369368 item ["provider_connector" ] = []interface {}{
370369 map [string ]interface {}{
371- "interface_name" : pc ["interfaceName" ],
372- "is_redirect" : pc ["isRedirect" ],
370+ "interface_name" : provConnector ["interfaceName" ],
371+ "is_redirect" : provConnector ["isRedirect" ],
373372 },
374373 }
375374 }
0 commit comments