Skip to content

Instantly share code, notes, and snippets.

@justinclayton
Created January 19, 2016 18:48
  • Star 22 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Terraform: taint all resources from one module
#!/bin/bash
module=$1
for resource in `terraform show -module-depth=1 | grep module.${module} | tr -d ':' | sed -e 's/module.${module}.//'`; do
terraform taint -module ${module} ${resource}
done
@deadanon
Copy link

deadanon commented Sep 8, 2020

For the lazy 1 liner crowd

for x in $(terraform state list | grep module.name_to_search); do terraform taint $x; done

@Console32
Copy link

A bit late, but this still pops up on google:

terraform state list | grep module.module_name | xargs -n1 terraform taint

@Arlington1985
Copy link

| xargs -n1 terraform taint

Very nice, just want I was looking for. Thanks

@dmitry-mightydevops
Copy link

For those who needs a makefile recipe:

taint_module: ## Recreate entire module `MODULE="module.cassandra-cluster" make taint_module`
	for resource in `terraform state list | grep module.${MODULE}`; do terraform taint $$resource; done

@devtech0101
Copy link

terraform state list|grep <MODULE_FULL_PATH> | xargs terraform taint ; terraform plan -out plan; terraform apply plan -auto-approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment