Skip to content

Commit 705ce7e

Browse files
authored
Merge pull request #197 from oliverpei/master
Fix key pair destroy
2 parents 2ae4900 + 2924a93 commit 705ce7e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

tencentcloud/extension_cvm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const (
3131

3232
ZONE_STATE_AVAILABLE = "AVAILABLE"
3333
ZONE_STATE_UNAVAILABLE = "UNAVAILABLE"
34+
35+
CVM_NOT_FOUND_ERROR = "InvalidInstanceId.NotFound"
3436
)
3537

3638
var CVM_CHARGE_TYPE = []string{

tencentcloud/resource_tc_key_pair.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/hashicorp/terraform/helper/resource"
2828
"github.com/hashicorp/terraform/helper/schema"
29+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
2930
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
3031
)
3132

@@ -186,6 +187,11 @@ func resourceTencentCloudKeyPairDelete(d *schema.ResourceData, meta interface{})
186187
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
187188
errRet := cvmService.UnbindKeyPair(ctx, keyId, keyPair.AssociatedInstanceIds)
188189
if errRet != nil {
190+
if sdkErr, ok := errRet.(*errors.TencentCloudSDKError); ok {
191+
if sdkErr.Code == CVM_NOT_FOUND_ERROR {
192+
return nil
193+
}
194+
}
189195
return retryError(errRet)
190196
}
191197
return nil

0 commit comments

Comments
 (0)