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.34k stars 9.49k forks source link

Characters typed before confirmation prompt aren't echoed, however buffered #27778

Open luckerby opened 3 years ago

luckerby commented 3 years ago

Consider running terraform apply interactively. Before the "Do you want to perform these actions?" prompt comes up, type "yes". Once the confirmation prompt is eventually displayed, the previous typed characters aren't echoed to the screen, however typing "yes" followed by Enter results in Apply cancelled.

I suspect that the characters typed before the prompt shows up are buffered internally, which results in a value of "yesyes" to be recorded for the example above.

Running on Terraform v0.14.5 on Windows 10 x64 v2004.

jbardin commented 3 years ago

Hi @luckerby

Thanks for filing the issue. This happens to be the behavior of the terminal itself, and is shared by most cli applications. The characters may be echoed, but they appear further up in the stream, and the buffered characters are never seen by terraform, as they are held in the terminal input buffer.

Due to the need for cross-platform stability and scriptability, it's unlikely we will convert the cli to using a raw terminal, but if that happens at some point in the future, it would be possible to control the display of the characters directly.

luckerby commented 3 years ago

I might be misunderstanding your answer - apologies if that's the case. From my experience with Powershell, starting a shell that takes longer (e.g. the Exchange Online one) and typing a cmdlet while the respective module is loading will result in the text entered already displayed when the cursor becomes available (including any functionality such as auto-complete using Tab). It's the same with the Azure az command, particularly the new interactive mode: running a command that takes some time, and typing characters in the meanwhile, will result in the those characters to be echoed once the cursor returns.

jbardin commented 3 years ago

PowerShell tends to be the outlier in the computing world for cli behavior, so it's hard to base a generalized solution off of it. I'm not sure exactly how the az "interactive mode" is implemented, but the description sounds like they are handling the raw terminal input and display within the command itself, which is what I alluded to above.

Terraform tends to follow standard unix behavior for cli applications, and is currently working as designed. There may be room for improvements in the future, the az command providing an example of what is possible in that space, which is why I tagged this as an enhancement request.