Merge pull request #9023 from Jonnymcc/destroying-detached-vol-attch-res

provider/aws: Skip DetachVolume if volume is not attached
This commit is contained in:
Clint 2016-10-03 09:56:49 -05:00 committed by GitHub
commit f1c5f848e9
1 changed files with 6 additions and 1 deletions

View File

@ -136,7 +136,7 @@ func resourceAwsVolumeAttachmentRead(d *schema.ResourceData, meta interface{}) e
},
}
_, err := conn.DescribeVolumes(request)
vols, err := conn.DescribeVolumes(request)
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVolume.NotFound" {
d.SetId("")
@ -144,6 +144,11 @@ func resourceAwsVolumeAttachmentRead(d *schema.ResourceData, meta interface{}) e
}
return fmt.Errorf("Error reading EC2 volume %s for instance: %s: %#v", d.Get("volume_id").(string), d.Get("instance_id").(string), err)
}
if len(vols.Volumes) == 0 || *vols.Volumes[0].State == "available" {
d.SetId("")
}
return nil
}