@@ -211,8 +211,11 @@ func (client IBMCloudClient) isResourceDown(resourceID string, resourceType stri
211211 instance , response , err := vpcService .GetInstance (options )
212212 if err != nil {
213213 xRequestId := response .Headers ["X-Request-Id" ][0 ]
214- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
215- err := fmt .Errorf ("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
214+ xCorrelationId := ""
215+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
216+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
217+ }
218+ err := fmt .Errorf ("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
216219 ui .Error (err .Error ())
217220 log .Println (err .Error ())
218221 return false , err
@@ -241,8 +244,11 @@ func (client IBMCloudClient) manageInstance(resourceID string, action string, st
241244 response , res , err := vpcService .CreateInstanceAction (options )
242245 if err != nil {
243246 xRequestId := res .Headers ["X-Request-Id" ][0 ]
244- xCorrelationId := res .Headers ["X-Correlation-Id" ][0 ]
245- err := fmt .Errorf ("[ERROR] Failed to perform %s action over instance. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , action , err , xRequestId , xCorrelationId )
247+ xCorrelationId := ""
248+ if len (res .Headers ["X-Correlation-Id" ]) != 0 {
249+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , res .Headers ["X-Correlation-Id" ][0 ])
250+ }
251+ err := fmt .Errorf ("[ERROR] Failed to perform %s action over instance. Error: %s \n X-Request-Id : %s %s" , action , err , xRequestId , xCorrelationId )
246252 ui .Error (err .Error ())
247253 log .Println (err .Error ())
248254 return "" , err
@@ -267,8 +273,11 @@ func (client IBMCloudClient) retrieveResource(resourceID string, state multistep
267273
268274 if err != nil {
269275 xRequestId := response .Headers ["X-Request-Id" ][0 ]
270- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
271- err := fmt .Errorf ("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
276+ xCorrelationId := ""
277+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
278+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
279+ }
280+ err := fmt .Errorf ("[ERROR] Failed retrieving resource information. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
272281 ui .Error (err .Error ())
273282 log .Println (err .Error ())
274283 return nil , err
@@ -306,8 +315,11 @@ func (client IBMCloudClient) createFloatingIP(state multistep.StateBag) (*vpcv1.
306315 floatingIP , response , err := vpcService .CreateFloatingIP (options )
307316 if err != nil {
308317 xRequestId := response .Headers ["X-Request-Id" ][0 ]
309- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
310- err := fmt .Errorf ("[ERROR] Failed creating Floating IP Request. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
318+ xCorrelationId := ""
319+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
320+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
321+ }
322+ err := fmt .Errorf ("[ERROR] Failed creating Floating IP Request. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
311323 ui .Error (err .Error ())
312324 log .Println (err .Error ())
313325 return nil , err
@@ -327,8 +339,11 @@ func (client IBMCloudClient) GrabCredentials(instanceID string, state multistep.
327339 instanceCredentials , response , err := vpcService .GetInstanceInitialization (options )
328340 if err != nil {
329341 xRequestId := response .Headers ["X-Request-Id" ][0 ]
330- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
331- err := fmt .Errorf ("[ERROR] Failed getting instance initialization data. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
342+ xCorrelationId := ""
343+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
344+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
345+ }
346+ err := fmt .Errorf ("[ERROR] Failed getting instance initialization data. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
332347 ui .Error (err .Error ())
333348 log .Println (err .Error ())
334349 return "" , "" , err
@@ -413,8 +428,11 @@ func (client IBMCloudClient) createSSHKeyVPC(state multistep.StateBag) (*vpcv1.K
413428 key , response , err := vpcService .CreateKey (options )
414429 if err != nil {
415430 xRequestId := response .Headers ["X-Request-Id" ][0 ]
416- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
417- err := fmt .Errorf ("[ERROR] Error sending the HTTP request that creates the SSH Key for VPC. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
431+ xCorrelationId := ""
432+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
433+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
434+ }
435+ err := fmt .Errorf ("[ERROR] Error sending the HTTP request that creates the SSH Key for VPC. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
418436 ui .Error (err .Error ())
419437 log .Println (err .Error ())
420438 return nil , err
@@ -432,8 +450,11 @@ func (client IBMCloudClient) getSecurityGroup(state multistep.StateBag, security
432450 securityGroup , response , err := vpcService .GetSecurityGroup (& securityGroupData )
433451 if err != nil {
434452 xRequestId := response .Headers ["X-Request-Id" ][0 ]
435- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
436- err := fmt .Errorf ("[ERROR] Error getting the Security Group. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
453+ xCorrelationId := ""
454+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
455+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
456+ }
457+ err := fmt .Errorf ("[ERROR] Error getting the Security Group. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
437458 ui .Error (err .Error ())
438459 log .Println (err .Error ())
439460 return nil , err
@@ -451,8 +472,11 @@ func (client IBMCloudClient) createSecurityGroup(state multistep.StateBag, secur
451472 securityGroup , response , err := vpcService .CreateSecurityGroup (& securityGroupData )
452473 if err != nil {
453474 xRequestId := response .Headers ["X-Request-Id" ][0 ]
454- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
455- err := fmt .Errorf ("[ERROR] Error creating the Security Group. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
475+ xCorrelationId := ""
476+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
477+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
478+ }
479+ err := fmt .Errorf ("[ERROR] Error creating the Security Group. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
456480 ui .Error (err .Error ())
457481 log .Println (err .Error ())
458482 return nil , err
@@ -473,8 +497,11 @@ func (client IBMCloudClient) createRule(rule vpcv1.CreateSecurityGroupRuleOption
473497
474498 if err != nil {
475499 xRequestId := response .Headers ["X-Request-Id" ][0 ]
476- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
477- err := fmt .Errorf ("[ERROR] Error sending the HTTP request that creates a Security Group's rule. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
500+ xCorrelationId := ""
501+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
502+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
503+ }
504+ err := fmt .Errorf ("[ERROR] Error sending the HTTP request that creates a Security Group's rule. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
478505 ui .Error (err .Error ())
479506 log .Println (err .Error ())
480507 return nil , err
@@ -495,8 +522,11 @@ func (client IBMCloudClient) addNetworkInterfaceToSecurityGroup(securityGroupID
495522 securityGroupTargetReferenceIntf , response , err := vpcService .CreateSecurityGroupTargetBinding (options )
496523 if err != nil {
497524 xRequestId := response .Headers ["X-Request-Id" ][0 ]
498- xCorrelationId := response .Headers ["X-Correlation-Id" ][0 ]
499- err := fmt .Errorf ("[ERROR] Error sending the HTTP request that Add the VSI's network interface to the Security Group. Error: %s \n X-Request-Id : %s \n X-Correlation-Id : %s" , err , xRequestId , xCorrelationId )
525+ xCorrelationId := ""
526+ if len (response .Headers ["X-Correlation-Id" ]) != 0 {
527+ xCorrelationId = fmt .Sprintf ("\n X-Correlation-Id : %s" , response .Headers ["X-Correlation-Id" ][0 ])
528+ }
529+ err := fmt .Errorf ("[ERROR] Error sending the HTTP request that Add the VSI's network interface to the Security Group. Error: %s \n X-Request-Id : %s %s" , err , xRequestId , xCorrelationId )
500530 ui .Error (err .Error ())
501531 log .Println (err .Error ())
502532 return nil , err
0 commit comments