provider/aws: bad AMI won't block LC refresh [GH-1901]

This commit is contained in:
Mitchell Hashimoto 2015-05-13 20:28:36 -07:00
parent ad62be8642
commit e7c6cb22c5
2 changed files with 13 additions and 0 deletions

View File

@ -487,6 +487,12 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
}
if dn, err := fetchRootDeviceName(d.Get("ami").(string), conn); err == nil {
if dn == nil {
return fmt.Errorf(
"Expected 1 AMI for ID: %s, got none",
d.Get("ami").(string))
}
blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
DeviceName: dn,
EBS: ebs,
@ -874,6 +880,8 @@ func fetchRootDeviceName(ami string, conn *ec2.EC2) (*string, error) {
if res, err := conn.DescribeImages(req); err == nil {
if len(res.Images) == 1 {
return res.Images[0].RootDeviceName, nil
} else if len(res.Images) == 0 {
return nil, nil
} else {
return nil, fmt.Errorf("Expected 1 AMI for ID: %s, got: %#v", ami, res.Images)
}

View File

@ -487,6 +487,11 @@ func readBlockDevicesFromLaunchConfiguration(d *schema.ResourceData, lc *autosca
if err != nil {
return nil, err
}
if rootDeviceName == nil {
// We do this so the value is empty so we don't have to do nil checks later
var blank string
rootDeviceName = &blank
}
for _, bdm := range lc.BlockDeviceMappings {
bd := make(map[string]interface{})
if bdm.EBS != nil && bdm.EBS.DeleteOnTermination != nil {