Skip to content

Commit

Permalink
Handle AWS keypairs which no longer exist
Browse files Browse the repository at this point in the history
When refreshing a keypair, update state appropriately rather than crash
if the keypair no longer exists on AWS.

Likely fixes hashicorp#1851.
  • Loading branch information
Phil Frost committed May 18, 2015
1 parent db095e2 commit 8225727
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin/providers/aws/resource_aws_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 8225727

Please sign in to comment.