user3423536
user3423536

Reputation: 87

What AWS Resources Does Terraform Know About

Recently, we had issues with tfstate being deleted on S3.

As a result, there are a number of EC2 instances still running (duplicates if you will)

Is there a way to query Terraform and list which EC2 instances (and other resources) Terraform has under its control? I want to delete the duplicate AWS resources without messing up Terraform state.

Upvotes: 0

Views: 59

Answers (1)

ydaetskcoR
ydaetskcoR

Reputation: 56849

Depending on whether you care about availability you could just delete everything and let Terraform recreate it all.

Or you could use terraform state list and then iterate through that with terraform state show (eg. terraform state list | xargs terraform state show) to show everything.

terraform import is for importing stuff that exists back in to your state which doesn't sound like what you want because it sounds like you've already recreated some things so have duplicates. If you had caught the loss of the resources from your state file before Terraform recreated it (for example by seeing an unexpected creation in the plan and seeing that the resource already existed in the AWS console) then you could have used that to import the resources back into the state file so that Terraform would then show an empty plan for these resources.

Iin the future make sure you use state locking to prevent this from happening again!

Upvotes: 1

Related Questions