Skip to content

Commit 8f1219d

Browse files
authored
Fix data source crash when vm has no volumes (IBM-Cloud#6166)
This crash occurred because the vm has no volumes and we tried to list them. I think this changed within the last year, and it is now possible to have a vm with no volumes.
1 parent c08bace commit 8f1219d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ibm/service/power/data_source_ibm_pi_instance_volumes.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ func dataSourceIBMPIInstanceVolumesRead(ctx context.Context, d *schema.ResourceD
153153

154154
var clientgenU, _ = uuid.GenerateUUID()
155155
d.SetId(clientgenU)
156-
d.Set(Attr_BootVolumeID, *volumedata.Volumes[0].VolumeID)
156+
if len(volumedata.Volumes) > 0 {
157+
d.Set(Attr_BootVolumeID, *volumedata.Volumes[0].VolumeID)
158+
}
159+
157160
d.Set(Attr_InstanceVolumes, flattenVolumesInstances(volumedata.Volumes, meta))
158161

159162
return nil
@@ -162,7 +165,6 @@ func dataSourceIBMPIInstanceVolumesRead(ctx context.Context, d *schema.ResourceD
162165
func flattenVolumesInstances(list []*models.VolumeReference, meta interface{}) []map[string]interface{} {
163166
result := make([]map[string]interface{}, 0, len(list))
164167
for _, i := range list {
165-
166168
l := map[string]interface{}{
167169
Attr_Bootable: *i.Bootable,
168170
Attr_CreationDate: i.CreationDate.String(),
@@ -191,7 +193,6 @@ func flattenVolumesInstances(list []*models.VolumeReference, meta interface{}) [
191193
if len(i.ReplicationSites) > 0 {
192194
l[Attr_ReplicationSites] = i.ReplicationSites
193195
}
194-
195196
result = append(result, l)
196197
}
197198
return result

0 commit comments

Comments
 (0)