@@ -96,6 +96,10 @@ func (client IBMCloudClient) isResourceReady(resourceID string, resourceType str
96
96
if resourceType == "instances" {
97
97
options := vpcService .NewGetInstanceOptions (resourceID )
98
98
instance , _ , err := vpcService .GetInstance (options )
99
+ if err != nil {
100
+ err := fmt .Errorf ("[ERROR] Error occurred while getting instance information. Error: %s" , err )
101
+ return false , fmt .Errorf (err .Error ())
102
+ }
99
103
status := * instance .Status
100
104
if status == "failed" {
101
105
err := fmt .Errorf ("[ERROR] Instance return with failed status. Status Reason - %s: %s" , status , * instance .StatusReasons [0 ].Message )
@@ -106,20 +110,35 @@ func (client IBMCloudClient) isResourceReady(resourceID string, resourceType str
106
110
} else if resourceType == "floating_ips" {
107
111
options := vpcService .NewGetFloatingIPOptions (resourceID )
108
112
floatingIP , _ , err := vpcService .GetFloatingIP (options )
113
+ if err != nil {
114
+ err := fmt .Errorf ("[ERROR] Error occurred while getting floating ip information. Error: %s" , err )
115
+ return false , fmt .Errorf (err .Error ())
116
+ }
109
117
status := * floatingIP .Status
110
118
ready = status == "available"
111
119
return ready , err
112
120
} else if resourceType == "subnets" {
113
121
options := vpcService .NewGetSubnetOptions (resourceID )
114
122
subnet , _ , err := vpcService .GetSubnet (options )
123
+ if err != nil {
124
+ err := fmt .Errorf ("[ERROR] Error occurred while getting subnet information. Error: %s" , err )
125
+ return false , fmt .Errorf (err .Error ())
126
+ }
115
127
status := * subnet .Status
116
128
ready = status == "available"
117
129
return ready , err
118
130
} else if resourceType == "images" {
119
131
options := vpcService .NewGetImageOptions (resourceID )
120
132
image , _ , err := vpcService .GetImage (options )
133
+ if err != nil {
134
+ err := fmt .Errorf ("[ERROR] Error occurred while getting image information. Error: %s" , err )
135
+ return false , fmt .Errorf (err .Error ())
136
+ }
121
137
status := * image .Status
122
138
ready = status == "available"
139
+ if status == "failed" {
140
+ err = fmt .Errorf ("[ERROR] Image went into failed state" )
141
+ }
123
142
return ready , err
124
143
}
125
144
return ready , nil
@@ -181,6 +200,7 @@ func (client IBMCloudClient) waitForResourceDown(resourceID string, resourceType
181
200
func (client IBMCloudClient ) isResourceDown (resourceID string , resourceType string , state multistep.StateBag ) (bool , error ) {
182
201
var down bool
183
202
203
+ ui := state .Get ("ui" ).(packer.Ui )
184
204
var vpcService * vpcv1.VpcV1
185
205
if state .Get ("vpcService" ) != nil {
186
206
vpcService = state .Get ("vpcService" ).(* vpcv1.VpcV1 )
@@ -189,6 +209,12 @@ func (client IBMCloudClient) isResourceDown(resourceID string, resourceType stri
189
209
options := & vpcv1.GetInstanceOptions {}
190
210
options .SetID (resourceID )
191
211
instance , _ , err := vpcService .GetInstance (options )
212
+ if err != nil {
213
+ err := fmt .Errorf ("[ERROR] Failed retrieving resource information. Error: %s" , err )
214
+ ui .Error (err .Error ())
215
+ log .Println (err .Error ())
216
+ return false , err
217
+ }
192
218
status := * instance .Status
193
219
down = status == "stopped"
194
220
return down , err
0 commit comments