Skip to content

[Bug] Failed to run terraform destroy in the first time when you have vms with sshkey #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LipingMao opened this issue Nov 14, 2019 · 4 comments
Labels

Comments

@LipingMao
Copy link

I get issue when I run terraform destroy, in the case I have two vms with sshkey.

Terraform Version

# terraform -v
Terraform v0.12.13
+ provider.tencentcloud v1.22.0

Affected Resource(s)

  • tencentcloud_key_pair

Terraform Configuration Files

create two CVM with sshkey, then run terraform destroy

Expected Behavior

Destroy success.

Actual Behavior

CVM can be destroy, but sshkey destroy failed with the following error:

Error: [TencentCloudSDKError] Code=InvalidInstanceId.NotFound, Message=The specified instance ID `['ins-imyqycsv', 'ins-2o89fojz']` is not found., RequestId=457cd512-2d34-45e9-99df-376c67f9ad8b

if you run terraform destroy again, it can success.

Steps to Reproduce

Write a tf which create 2 CVM with sshkey, then terraform apply, terraform destroy can 100% reproduce this issue.

There is work around which can avoid this issue with limit parallelism to 1 when destroy.

The issue seems like when the code in destroy key pair try to unbind with CVM, but the VM has been deleted. Seems like something wrong here:
https://github.com/terraform-providers/terraform-provider-tencentcloud/blob/master/tencentcloud/resource_tc_key_pair.go#L185-L196

@oliverpei
Copy link
Contributor

This issue has been fixed in V1.23.0, please upgrade and have a try.

@LipingMao
Copy link
Author

LipingMao commented Nov 15, 2019

@oliverpei , thanks for update , but I still get issue, here is a part of log:

[root@43036342e3a9 CENTRAL_BJ01]# terraform destroy
...
module.bj01_central_cluster.tencentcloud_vpc.pano_vpc: Destruction complete after 1s
module.bj01_central_cluster.tencentcloud_placement_group.dbstore: Destruction complete after 16s

Error: [TencentCloudSDKError] Code=InvalidKeyPair.NotSupported, Message=The request does not support the key pair `skey-4gc6261f` which associastes with instance., RequestId=c6fa3ee1-0e3e-447f-8540-1a062d43baa6


[root@43036342e3a9 CENTRAL_BJ01]# terraform state list
module.bj01_central_cluster.tencentcloud_key_pair.sshkey
[root@43036342e3a9 CENTRAL_BJ01]# terraform destroy
module.bj01_central_cluster.data.tencentcloud_image.pano_image: Refreshing state...
module.bj01_central_cluster.tencentcloud_key_pair.sshkey: Refreshing state... [id=skey-4gc6261f]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # module.bj01_central_cluster.tencentcloud_key_pair.sshkey will be destroyed
  - resource "tencentcloud_key_pair" "sshkey" {
      - id         = "skey-4gc6261f" -> null
      - key_name   = "pano_ssh_key" -> null
      - project_id = 0 -> null
      - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCLGAgrXY7G3HwO8voNKokyiAaUFtLgrSi6SuIfuvySddhTrCa0/oN+ro88j+pW8LS2zUWz12d8tqp/0Qmd8jhNVf6ITZwrgc+9gTX+sQWrrpx5jGGnrv9ISDD3NCMJVhJ514VWfH6sa5YKmYIQ49/DS/Iak88AmVbQAxKZHShvFlBS/xZ4QEkQy1731QmhK4t1As/ICfla2Qiv/rI7VxWPT21kVT4dH2Y1coqCmXymRgtU8zj4nVRi3XjgVSYIbqZFLH7aBjkeIE0Wpg8WOY7zZNOcPcGYZk/vIqyZdPUTy3S/jBcUJLqYUZvxeJYK+sKeAEFN+q5PnwGQ54nTOLaj" -> null
    }

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

module.bj01_central_cluster.tencentcloud_key_pair.sshkey: Destroying... [id=skey-4gc6261f]
module.bj01_central_cluster.tencentcloud_key_pair.sshkey: Destruction complete after 1s

Destroy complete! Resources: 1 destroyed.


[root@43036342e3a9 CENTRAL_BJ01]# terraform --version
Terraform v0.12.13
+ provider.tencentcloud v1.23.0

Your version of Terraform is out of date! The latest version
is 0.12.15. You can update by downloading from www.terraform.io/downloads.html

@oliverpei
Copy link
Contributor

@LipingMao Sorry for the trouble, we have fixed in V1.24.0, please have a try.
Thank you.

@LipingMao
Copy link
Author

OK for me to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants