The right way to Take away a Useful resource from Terraform State


Terraform state displays the freshest reference of the infrastructure.

Typically you might must take away a useful resource from the Terraform state manually. That is useful if a useful resource has been deleted or modified manually and the useful resource definition has been eliminated in your Terraform code. This fashion you possibly can re-run your Terraform plan and apply with out deleting the distant infra useful resource that you simply faraway from the state.

Step 1 – Discover the useful resource you wish to delete

Working this command will place all sources managed by Terraform in an inventory kind, all sources separated by line breaks.

terraform state listing

Step 2 – Take away the useful resource in query

As soon as you realize the useful resource you want to take away from the state, move it’s Terraform reference identify to the rm command under:

terraform state rm <resource_name>

Instance:

terraform state rm module.kms_key.aws_kms_key.default[0]
See also  Easy methods to mock community request in Jest | by Sabesan Sathananthan | Geek Tradition

Leave a Reply