Create a temporal resource

Greetings I am looking for a temporal resource during apply
E.g. I would like to:

  1. create a keypair
  2. create ec2 with it
  3. provision ec2 using the key
  4. destroy keypair

Is it somehow possible?

I don’t think this is all possible during an apply. Terraform being declarative means you describe the desired state so an apply and a destroy are two different API calls. The way you have described it in this post sounds imperative which goes against the nature of Terraform