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:
parent
883e2848c6
commit
9e2ecafc46
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue