From 9e2ecafc4640fe9cfc4eb2bc23b6baaff646dbba Mon Sep 17 00:00:00 2001 From: Phil Frost Date: Mon, 18 May 2015 16:19:51 -0400 Subject: [PATCH] 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. --- builtin/providers/aws/resource_aws_key_pair.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/aws/resource_aws_key_pair.go b/builtin/providers/aws/resource_aws_key_pair.go index b9c4064675..cf4d82c548 100644 --- a/builtin/providers/aws/resource_aws_key_pair.go +++ b/builtin/providers/aws/resource_aws_key_pair.go @@ -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) }