Bulk delete from terraform state
Version your state file
Ensure that you have at least 2 backups of your state file, or at minimum have Versioning enabled on GCS! This has the possibility of deleting things you didn't mean to... ask me how I know
Why
When moving towards using terragrunt based approach, you will be migrating things to separate directories, and need to remove alot of things from the original state.
How
View the entries in the state
Create a grep string that targets what you want
In this case, we want to remove things with test
in their name
Example
Encapsulate everything in ''
We need to do this as passing google_folder_iam_member.test["roles/viewer"]
will have issues in BASH
Delete from state
Want to make this site better? Open a PR or help fund hosting costs