Created
January 19, 2016 18:48
-
-
Save justinclayton/01f349f66e908a243709 to your computer and use it in GitHub Desktop.
Terraform: taint all resources from one module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Invading this gist with 😱 POWERSHELL!
~\source\terraform show | Select-String -Pattern "module.ingress.([\-\.\w]+)" | %{ $_.Matches[0].Groups[1].Value } | ?{ -Not $_.StartsWith("data.") } | %{ ~\source\terraform.exe taint "module.ingress.$_" }
For the lazy 1 liner crowd
for x in $(terraform state list | grep module.name_to_search); do terraform taint $x; done
A bit late, but this still pops up on google:
terraform state list | grep module.module_name | xargs -n1 terraform taint
| xargs -n1 terraform taint
Very nice, just want I was looking for. Thanks
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
terraform state list|grep <MODULE_FULL_PATH> | xargs terraform taint ; terraform plan -out plan; terraform apply plan -auto-approve
atlantis plan -p infrastructure-stage
rm -f terraform.tfstate*
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version that also allows for exceptions to what gets taint and some helpers to make the cmd a little nicer to deal with