Terraform v0.11.13中如何标记helm_release.redis-ha资源为taint?
Got it, since you can't upgrade to Terraform v0.12 and older versions don't support the bracket-based index syntax ([3]) from your terraform state list output, here's how to get the taint working:
Taint a Specific Instance
Your target resource shows up as module.abc.module.redis.helm_release.redis-ha[3], but pre-v0.12 Terraform uses dot notation instead of brackets for list indices. Use either of these commands:
Using the -module flag
terraform taint -module=abc.module.redis helm_release.redis-ha.3
Full resource path with dot index
terraform taint module.abc.module.redis.helm_release.redis-ha.3
The key here is swapping [3] for .3—that's the syntax older Terraform versions expect for indexed resources in nested modules.
Taint the Entire Redis-HA Deployment
If you want to mark all instances of the redis-ha release for recreation (instead of just index 3), you can automate this with a quick loop. This handles all matching resources without you having to list each index manually:
# Grab all matching resources, fix the syntax, and taint each one for resource in $(terraform state list | grep "module.abc.module.redis.helm_release.redis-ha"); do cleaned_resource=$(echo "$resource" | sed 's/\[/./g; s/\]$//') terraform taint "$cleaned_resource" done
Double-Check It Worked
Run terraform plan after tainting—you should see a line indicating the resource is tainted and will be recreated, like:
-/+ module.abc.module.redis.helm_release.redis-ha[3] (tainted)
That confirms the taint was applied successfully.
内容的提问来源于stack exchange,提问作者Frank

