terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Replace multiple resource instances with a single -replace=... planning argument

Open alexlouden opened this issue 10 years ago • 70 comments

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

alexlouden avatar May 01 '15 07:05 alexlouden

+1

ketzacoatl avatar May 08 '15 04:05 ketzacoatl

+1

jamiemoore avatar May 13 '15 02:05 jamiemoore

+1

tomwilkie avatar Aug 13 '15 16:08 tomwilkie

+1

meson10 avatar Aug 18 '15 04:08 meson10

+1

JorritSalverda avatar Sep 02 '15 08:09 JorritSalverda

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.

apparentlymart avatar Sep 02 '15 15:09 apparentlymart

+1

listenrightmeow avatar Nov 11 '15 00:11 listenrightmeow

+1

jmahowald avatar Nov 14 '15 23:11 jmahowald

+1

levenaux avatar Jan 28 '16 15:01 levenaux

#2444 is similar to this and would be awesome!

jonapich avatar Feb 17 '16 13:02 jonapich

has there been any progress on this? this would be very helpful for us at Box.

jseaidou avatar Apr 06 '16 22:04 jseaidou

+1

Kuberchaun avatar Jun 15 '16 06:06 Kuberchaun

+1

noresjo avatar Jun 16 '16 08:06 noresjo

+1

igormoochnick avatar Jun 29 '16 12:06 igormoochnick

+1

JohnDzialo avatar Jun 29 '16 16:06 JohnDzialo

+1

dabdine-r7 avatar Jul 11 '16 04:07 dabdine-r7

+1

ghost avatar Jul 28 '16 23:07 ghost

+1

nicusX avatar Aug 13 '16 10:08 nicusX

this would be really needed for resources created using count :)

sachincab avatar Aug 18 '16 08:08 sachincab

+1

ghost avatar Sep 06 '16 09:09 ghost

Very useful, especially with count.

abadyan-vonage avatar Sep 15 '16 12:09 abadyan-vonage

+1

onlyanegg avatar Oct 18 '16 22:10 onlyanegg

+1

ryanrapp avatar Oct 19 '16 20:10 ryanrapp

+1

ilijaljubicic avatar Oct 24 '16 08:10 ilijaljubicic

+1

benglewis avatar Dec 05 '16 08:12 benglewis

+1

dayglojesus avatar Dec 12 '16 18:12 dayglojesus

+1

xvillanuOM avatar Dec 15 '16 03:12 xvillanuOM

+1

ChristopheSchmitz avatar Dec 22 '16 05:12 ChristopheSchmitz

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

ChristopheSchmitz avatar Dec 22 '16 05:12 ChristopheSchmitz

+1, this would be very useful

mattkenn4545 avatar Apr 18 '17 19:04 mattkenn4545