Fix EBS block device hashing in spot fleet requests.
When computing the set key for an EBS block device, we were using the wrong function; we had hashEphemeralBlockDevice instead of hashEbsBlockDevice. This caused a panic by trying to access the virtual_name attribute that will never be set for EBS block devices. To fix this, I switched to the hashEbsBlockDevice function, which is already being used to compute a Set key in the Schema. But in the default case, where the snapshot_id attribute isn't specified, this also caused a panic. I updated the way the string to hash is generated to check for the existence of the device_name and snapshot_id attributes before we use them, to avoid panics when these optional attributes aren't set.
This commit is contained in:
parent
24dd4273c7
commit
7d06ea8449
|
@ -805,7 +805,7 @@ func launchSpecToMap(
|
||||||
}
|
}
|
||||||
|
|
||||||
func ebsBlockDevicesToSet(bdm []*ec2.BlockDeviceMapping, rootDevName *string) *schema.Set {
|
func ebsBlockDevicesToSet(bdm []*ec2.BlockDeviceMapping, rootDevName *string) *schema.Set {
|
||||||
set := &schema.Set{F: hashEphemeralBlockDevice}
|
set := &schema.Set{F: hashEbsBlockDevice}
|
||||||
|
|
||||||
for _, val := range bdm {
|
for _, val := range bdm {
|
||||||
if val.Ebs != nil {
|
if val.Ebs != nil {
|
||||||
|
@ -1009,7 +1009,11 @@ func hashLaunchSpecification(v interface{}) int {
|
||||||
func hashEbsBlockDevice(v interface{}) int {
|
func hashEbsBlockDevice(v interface{}) int {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
m := v.(map[string]interface{})
|
m := v.(map[string]interface{})
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
|
if name, ok := m["device_name"]; ok {
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["snapshot_id"].(string)))
|
buf.WriteString(fmt.Sprintf("%s-", name.(string)))
|
||||||
|
}
|
||||||
|
if id, ok := m["snapshot_id"]; ok {
|
||||||
|
buf.WriteString(fmt.Sprintf("%s-", id.(string)))
|
||||||
|
}
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue