Handle AWS keypairs which no longer exist

When refreshing a keypair, update state appropriately rather than crash
if the keypair no longer exists on AWS.

Likely fixes #1851.
This commit is contained in:
Phil Frost 2015-05-18 16:19:51 -04:00
parent 883e2848c6
commit 9e2ecafc46
1 changed files with 5 additions and 0 deletions

View File

@ -65,6 +65,11 @@ func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error {
}
resp, err := conn.DescribeKeyPairs(req)
if err != nil {
awsErr, ok := err.(aws.APIError)
if ok && awsErr.Code == "InvalidKeyPair.NotFound" {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving KeyPair: %s", err)
}