-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace multiple resource instances with a single -replace=... planning argument #1768
Comments
+1 |
4 similar comments
+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: Line 94 in 6f9a358
If there were a rule that the wildcard can only be a |
+1 |
2 similar comments
+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 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
this would be really needed for resources created using count :) |
+1 |
Very useful, especially with count. |
+1 |
2 similar comments
+1 |
+1 |
This implementation of wildcard functionality enables the following: Given resources: - test_instance.foo.a - test_instance.foo.b - test_instance.bar.a Matches: `test_instance.*` - test_instance.foo.a - test_instance.foo.b - test_instance.bar.a `test_instance.*.a` - test_instance.foo.a - test_instance.bar.a `test_instance.foo.*` - test_instance.foo.a - test_instance.foo.b `test_instance.foo*` - Doesn't match anything
This implementation of wildcard functionality enables the following: Given resources: - test_instance.foo.a - test_instance.foo.b - test_instance.bar.a Matches: `test_instance.*` - test_instance.foo.a - test_instance.foo.b - test_instance.bar.a `test_instance.*.a` - test_instance.foo.a - test_instance.bar.a `test_instance.foo.*` - test_instance.foo.a - test_instance.foo.b `test_instance.foo*` - Doesn't match anything
+1 |
+1 for the ability to taint a whole module or multiple resources I just got absolutely crushed by not having this ability to taint multiple resources. I was tainting an instance, and not realising that the downstream null resource file provisioners weren't working because they weren't tainted. face palm. |
Is there a workaround for this in the meanwhile? edit: in #23023 (comment) I found a suggestion to do a 'state rm' on all nodes. We can change that to do a taint on all elements. |
I needed to taint a whole module, and this function can help here too: terraform-taint-all () {
resource_prefix=$1
for resource in $(terraform state list | grep -oP "$resource_prefix.*"); do
terraform taint $resource;
done
} So if you want to taint all resources created with count, lets say a
|
@apparentlymart – In 2016, I implemented this feature. My PR was closed because–although it worked–it added tech debt to Terraform, because there was secret state work going on behind the scenes and my PR wouldn't blend well. Given that it's 4 years later, has the situation changed? If I were to implement this today, would my PR be closed again? |
My use case is to taint the elements of the array, given its base name Also, the "state rm" sub-command supports it, so the code to do this would be somewhere in core already, me-thinks! :) $ /opt/terraform-0.12/bin/terraform state list
aws_launch_configuration.worker[0]
aws_launch_configuration.worker[1]
aws_launch_configuration.worker[2] Try to taint it ... no joy $ /opt/terraform-0.12/bin/terraform taint aws_launch_configuration.worker
Error: No such resource instance
There is no resource instance in the state with the address
aws_launch_configuration.worker. If the resource configuration has just been
added, you must run "terraform apply" once to create the corresponding
instance(s) before they can be tainted. But $ /opt/terraform-0.12/bin/terraform state rm aws_launch_configuration.worker
Removed aws_launch_configuration.worker[0]
Removed aws_launch_configuration.worker[1]
Removed aws_launch_configuration.worker[2]
Successfully removed 3 resource instance(s). |
could you grep and filter from - |
I've updated the title of the issue here to clarify the goal of tainting multiple resource instances at once, without specifying a particular solution (wildcard, or multiple addresses as proposed in #22117). This is not any declaration of intent on the part of the Core team, but some issue consolidation on our side. |
Taint by tag? |
Here, we use In some cases, it's actually fastest to convert from S3 backend to local, apply the taint commands, then convert back again since it's so much faster. We're using S3 backend + DynamoDB in our setup |
as taint is deprecated , should we update this ticket to expect the same kind of behavior with "-replace" when performing a plan/apply ? |
While But I did a quick test with multiple |
+1 |
It would be really nice to be able to use a splat expression in |
it's still an annoying solution to do multiple Would've been so much easier with a single command but no... $ AWS_PROFILE=dev terraform apply -target=module.my_test -replace=module.my_test
Acquiring state lock. This may take a few moments...
module.my_test[0]: Refreshing state... [id=xxx]
module.my_test[1]: Refreshing state... [id=xxx]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
╷
│ Warning: Incompletely-matched force-replace resource instance
│
│ Your force-replace request for module.my_test doesn't match any resource instances because it lacks an instance key.
│
│ To force replacement of particular instances, use one or more of the following options instead:
│ -replace="module.my_test[0]"
│ -replace="module.my_test[1]"
╵
╷
Releasing state lock. This may take a few moments...
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. |
I don't know the reasoning why this wildcard use is an error instead of a feature. Anyway, it's pretty straightforward to patch terraform code to use it. Obviously, it's a workaround, not a solid solution. Just to modify the file terraform/internal/terraform/node_resource_plan.go, expanding the "replace" array with the expansion list. |
Any news on this ? I need to replace multiple instances that depend on a "count" variable. For now with my_instances.* I get doesn't match any resource instances because it lacks an instance key using Terraform 1.2.7 |
You have to do e.g.
Ugly but effective. |
@jbg solution works great for terraform plan, but for terraform apply i had to use this to avoid printing a newline when seq completes.
|
It's 2023 and still no updates :( |
+1 |
Checking if you have updates on this. |
+1 |
Thanks for your interest in this issue! This is just a reminder to please avoid "+1" comments, and to use the upvote mechanism (click or add the 👍 emoji to the original post) to indicate your support for this issue. This helps avoid notification spam for issues with high numbers of participants while enabling the maintainers to prioritize issues. We do not have any update to share at this time. We maintain a list of top 25 community upvoted issues (you can see a basic version of this with this issue search). Issues on this list get reviewed and discussed frequently, especially when we are planning new releases. This issue is just off the list at 28, however after the next few releases, the top 25 should have a bit more room as we close some of those other issues. This issue also has a similar theme to #2182, which is sitting at #7 as of this post. Issues that have been open for many, many years such as this one are often still open because their implementation is not as trivial or obvious as it may at first appear. Thanks again for the feedback! |
Since the title of this issue has changed, issue #22117, which was closed in favor of this one, should be reopened. |
Hey guys,
I've got an AWS instance resource for my workers in a module (
mymodule
):Is it possible to taint all 12 resources? I've tried the following:
Rather than having to do this:
Cheers,
Alex
The text was updated successfully, but these errors were encountered: