Merge pull request #1000 from hashicorp/b-root-not-being-set

providers/aws: root block device not being set properly
This commit is contained in:
Mitchell Hashimoto 2015-02-18 15:15:09 -08:00
commit 3a0d88ed73
1 changed files with 14 additions and 6 deletions

View File

@ -454,25 +454,33 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
} }
nonRootBlockDevices := make([]map[string]interface{}, 0) nonRootBlockDevices := make([]map[string]interface{}, 0)
rootBlockDevice := make([]interface{}, 0, 1)
for _, vol := range volResp.Volumes { for _, vol := range volResp.Volumes {
volSize, err := strconv.Atoi(vol.Size) volSize, err := strconv.Atoi(vol.Size)
if err != nil { if err != nil {
return err return err
} }
blockDevice := make(map[string]interface{}) blockDevice := make(map[string]interface{})
blockDevice["device_name"] = blockDevices[vol.VolumeId].DeviceName blockDevice["device_name"] = blockDevices[vol.VolumeId].DeviceName
blockDevice["snapshot_id"] = vol.SnapshotId
blockDevice["volume_type"] = vol.VolumeType blockDevice["volume_type"] = vol.VolumeType
blockDevice["volume_size"] = volSize blockDevice["volume_size"] = volSize
blockDevice["delete_on_termination"] = blockDevices[vol.VolumeId].DeleteOnTermination blockDevice["delete_on_termination"] =
blockDevice["encrypted"] = vol.Encrypted blockDevices[vol.VolumeId].DeleteOnTermination
// If this is the root device, save it. We stop here since we
// can't put invalid keys into this map.
if blockDevice["device_name"] == instance.RootDeviceName { if blockDevice["device_name"] == instance.RootDeviceName {
d.Set("root_block_device", []interface{}{blockDevice}) rootBlockDevice = []interface{}{blockDevice}
} else { continue
nonRootBlockDevices = append(nonRootBlockDevices, blockDevice)
} }
blockDevice["snapshot_id"] = vol.SnapshotId
blockDevice["encrypted"] = vol.Encrypted
nonRootBlockDevices = append(nonRootBlockDevices, blockDevice)
} }
d.Set("block_device", nonRootBlockDevices) d.Set("block_device", nonRootBlockDevices)
d.Set("root_block_device", rootBlockDevice)
return nil return nil
} }