mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-25 10:02:16 -04:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user