Merge pull request #1960 from hashicorp/b-lc-ami

provider/aws: bad AMI won't block LC refresh [GH-1901]
This commit is contained in:
Mitchell Hashimoto 2015-05-14 09:58:58 -07:00
commit 32f6eb77f3
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 {