hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.73k stars 9.55k forks source link

Add a parameter to taint to target everything except for specified resources #31718

Open insanedefaults opened 2 years ago

insanedefaults commented 2 years ago

Terraform Version

Terraform v1.2.8
on darwin_amd64

Use Cases

I often build many resources to test architecture configurations. Some of these take a long time to be provisioned. It is often the case that "chunks" of these resources are tied up together and need to be completely rebuilt together while others do not.

For instance, let's say that I am building an EC2 cluster backed by an Aurora DB. The Aurora DB can be stood up on its own while the EC2 cluster typically has several associated resources. As a database is a relatively simple piece of the infrastructure, there is typically no need to have it torn down, but everything else might need to be.

Attempted Solutions

This operation can be achieved through parsing a state file, feeding everything to taint, and then using untaint for the smaller subset that you do not wish to affect. Indeed, a standalone tool could be created following this logic.

Another option could be to do a similar parsing of a state file, negating the resources you want to keep in the process, and then submitting the difference to taint.

By no means is it impossible to do this or conceive of how to do this without modifying Terraform. On the other hand, it is cumbersome, subjectively.

Proposal

grep has an invert match flag that will match all text that does not satisfy the expression passed. That looks something like this:

❯ seq 3 | grep --invert-match 2
1
3

My proposal is to add a similar --invert-match flag to taint where the resources specified will be the only resources that are not tainted.

References

No response

kmoe commented 2 years ago

Thanks for the feature request and for including the analogy to grep --invert-match.