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
terraform apply does not list -replace option #30194
Comments
This does seem to be an oversight that persists into terraform 1.1.2. I am wondering if this flag was also deprecated? We should either document |
I tried to use the flag and as far as I could tell it seemed to be calling taint in the end. I also couldn't figure out how to replace multiple resources at once. terraform apply would not accept multiple replace flags but putting multiple resources separated by comma didn't work either. |
Hi @jason-swissre thank you for submitting this! I'm talking to engineering and working on getting the docs updated so that the usage of the |
Update - the PR that is now linked to this ticket contains some documentation changes (and the rationale behind them!) that will hopefully make this a bit clearer for future users. Thank you again for pointing this out to us! After a bit more investigation, I'll open another PR to clarify the issue surrounding replacing multiple resources at once. |
Thanks for following up on this. I looked at the PR and it didn't actually address the issues I was having. If I type |
Hello! Thank you for checking out the PR. Let me provide some more background about why we took this approach. The We completely agree with you that ideally it would be documented on In the meantime, our approach has been to tell users in a few separate places on the We also have a note in the CLI output for
This is why I left the content on the Once we learn more about your issues using the flag multiple times to replace multiple resources at once, I plan to open another PR with more improvements. I just want to batch the rest of the edits for this issue together. Would you mind providing us with the command you used to replace multiple resources at once? I'd like to pass that along to engineering so they can take a look. Once we understand what's going on there, the second PR will:
Hopefully this is helpful - thank you again for bringing this to our attention! Let me know if you have other thoughts, questions, or ideas. 😄 |
Ok, thanks for the update. That makes sense. Unfortunately I cannot find the commands anymore that I used to run the replace. We have a setup where only our build system actually has access to run terraform so the logs were in the CI/CD system but I can't find the entries where I was trying to use replace. What I know is that I tried once with comma (e.g. |
Hi @jason-swissre, Unfortunately PowerShell is rather notorious for corrupting command lines when running external programs (that is, anything other than a real PowerShell cmdlet), particularly on Windows where the command line quoting/escaping rules are unique to each program. While I've not heard about problems with I believe PowerShell/PowerShell#14692 is an PowerShell PR intended to address these problems, but it works by introducing a new opt-in setting to turn on better command line parsing for external programs, since it's a breaking change that may affect existing PowerShell scripts. The issue PowerShell/PowerShell#1995 describes the broader problems here, including some details about some classes of external programs that PowerShell cannot support even with that PR, but thankfully Terraform fits in to the category of "those programs that adhere to the quoting and escaping conventions used by Microsoft's C/C++ runtime" as discussed in PowerShell/PowerShell#15143, and so should work better with that new option enabled. Because of all of this additional configuration complexity with PowerShell, we typically recommend that folks on Windows use the Windows Command Prompt instead of PowerShell, because that then avoids the incorrect parsing/escaping that PowerShell performs in that case and passes the entered command line more faithfully to Terraform. With the weird PowerShell command line corruption aside, the correct way to force replacing multiple resource instances at once is to specify the
|
Hi @apparentlymart, thanks for the tips. In my case I'm certain it has nothing to do with the powershell script because to get our system working I took the exact same interpolations and created |
Hi @jason-swissre, If you are able to reproduce it, it can be helpful to run Terraform with the environment variable
The "CLI args:" one is the relevant one, because it shows how the command line options got tokenized into a list of separate strings per argument. In previous situations where we've seen problems related to PowerShell, it's been visible here due to there being extra elements of the list which don't make sense. For example, for the
...whereas Terraform is expecting to see the
Likewise for the example command like I shared the expected tokenization (if run outside of PowerShell) would be the following:
If your reproduction shows there being more than four elements in that rendered array then that would suggest incorrect tokenization by the shell. On the other hand, if you do see exactly four elements like the above and yet Terraform still fails to accept the command then that'd suggest a new bug we've not seen before, and so we'd love to hear more about it. |
Hi both - I've created a final PR that I think should close out this issue. :-) Let me know if you have feedback! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Expected Behavior
terraform apply documentation and terraform apply -help should talk about the -replace option
Actual Behavior
Neither the documentation for the apply command nor the command itself mention the -replace options. The only location this is mentioned is in the documentation for the terraform taint command where it says this option has been deprecated since Terraform v0.15.2.
Steps to Reproduce
Check terraform apply documentation or run terraform -apply -help
Links
https://www.terraform.io/cli/commands/taint
https://www.terraform.io/cli/commands/apply
The text was updated successfully, but these errors were encountered: