diff --git a/builtin/providers/aws/resource_aws_key_pair.go b/builtin/providers/aws/resource_aws_key_pair.go index b9c406467..036c35fe8 100644 --- a/builtin/providers/aws/resource_aws_key_pair.go +++ b/builtin/providers/aws/resource_aws_key_pair.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws/awserr" "github.com/awslabs/aws-sdk-go/service/ec2" ) @@ -65,6 +66,11 @@ func resourceAwsKeyPairRead(d *schema.ResourceData, meta interface{}) error { } resp, err := conn.DescribeKeyPairs(req) if err != nil { + awsErr, ok := err.(awserr.Error) + if ok && awsErr.Code() == "InvalidKeyPair.NotFound" { + d.SetId("") + return nil + } return fmt.Errorf("Error retrieving KeyPair: %s", err) }