terraform
terraform copied to clipboard
Replace multiple resource instances with a single -replace=... planning argument
Hey guys,
I've got an AWS instance resource for my workers in a module (mymodule):
resource "aws_instance" "worker" {
count = "12"
...
}
Is it possible to taint all 12 resources? I've tried the following:
❯ terraform taint -module=mymodule "aws_instance.worker.*"
The resource aws_instance.worker.* couldn't be found in the module root.mymodule.
Rather than having to do this:
❯ terraform taint -module=mymodule "aws_instance.worker.0"
The resource aws_instance.worker.0 in the module root.mymodule has been marked as tainted!
❯ terraform taint -module=mymodule "aws_instance.worker.1"
The resource aws_instance.worker.1 in the module root.mymodule has been marked as tainted!
...
Cheers, Alex
+1
+1
+1
+1
+1
This seems like it wouldn't be too hard to implement.
The code that finds the resource to taint is here: https://github.com/hashicorp/terraform/blob/6f9a358cc432e1b29da00ff364f741293743ff75/command/taint.go#L94
If there were a rule that the wildcard can only be a * and it may only be the entirety of the last part of the resource path (so e.g. no aws_instance.foo* or *.baz) then this would just entail iterating over the mod.Resources map looking for keys that have the right prefix.
+1
+1
+1
#2444 is similar to this and would be awesome!
has there been any progress on this? this would be very helpful for us at Box.
+1
+1
+1
+1
+1
+1
+1
this would be really needed for resources created using count :)
+1
Very useful, especially with count.
+1
+1
+1
+1
+1
+1
+1
If wildcard is difficult to implement, then an intermediate improvement would be to allow taint on multiple resource at a time. This would let us take advantage of shell expansion and do stuff like
terraform taint aws_instance.worker.{1..12} <- does not work
+1, this would be very useful