Open ialidzhikov opened 1 year ago
Voting for Prioritization
Volunteering to Work on This Issue
@ialidzhikov Did you check whether the key has been created in your AWS account or not?
When the key pair creation fails with InvalidKeyPair.Duplicate: The keypair already exists
, it obviously gets created in AWS..
Agree with your point but the thing here is if the state file is having an entry of key pair and when you interrupt the terraform action then it is obvious that the state file won't delete the entry of the key pair right?
Obviously it is not saved in the terraform state due to the interrupt and that's why it tries to create it again.
This error InvalidKeyPair.Duplicate: The keypair already exists indicates that the key's identity is present in the state file
Are you sure? I think that this is the error returned by the AWS API.
I am sure about that, you can check the state file.
I don't think so. If it is present in the state file, it should not try to create it again. Anyways, I already provided detailed enough steps to reproduce. You can also reproduce on your side to confirm/reject your assumption.
Sure, I'll try to reproduce it.
Terraform Core Version
v1.3.9
AWS Provider Version
v4.55.0
Affected Resource(s)
Expected Behavior
terraform/terraform-provider-aws to be resilient to interrupts and to do not leak terraform state when interrupt is received. We run terraform in quite automated manner without human interaction. Everytime state leaks, a human operator has to analyse it and fix it manually.
Actual Behavior
terraform/terraform-provider-aws leaks state when first terraform apply (that creates the resources) is interrupted.
Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
main.tf
variables.if
Steps to Reproduce
terraform apply -auto-approve
and interrupt the terraform process (Ctrl + C) when it start creating the key pair.terraform apply -auto-approve
again. Make sure that state for some security group rules is not saved in the terraform state but they actually exist in AWS.Any subsequent
terraform apply
run fails with the above errorInvalidKeyPair.Duplicate: The keypair already exists
.Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
Would you like to implement a fix?
None