-
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
Add terraform console
for REPL
#10093
Conversation
The readline library doesn't support Solaris. For now, we'll just not support console there.
Heh... when I was writing the new HIL parser I was thinking about whether I should add in a mode where it parses as if it were already inside This would just be polish that could be handled separately, but might be worth considering using the new entry point I added to HIL that allows the caller to specify the start position, so you can set it to be something like "line 1, column -1" so that the user-entered expression ends up starting at line 1, column 1. Though probably easier to wait to do that until Terraform's interpolator itself is able to pass config positions into the HIL parser, since this layer can't "see" the HIL interface at all. |
@apparentlymart Yeah I thought about both of those options too, but there are a couple things holding me back: 1.) Parsing 'interpolation mode' first would require significant refactors of TF since 2.) ast.Pos is blocked by above too. :) |
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. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Fixes #9750
This PR adds a new command
terraform console
that opens an interactive console for experimenting with interpolations. I forsee in the future the console being much more powerful and being to invoke Terraform, modify state, etc. But, for v1 of this feature, it is only used for interacting with interpolations.The
console
command will read your state so you can access resources from the console. If you configure a remote state, it can read that as well.There are a few use cases for this:
Learning: You can use the console to learn and play with interpolations.
Testing: You can try interpolations before you use them, or verify that they're working correctly.
Scripting: You can use interpolations to read values and transform them from the state in a Unix-friendly way. This is especially true for remote state.
Demo Gif
Interactive mode:
Piped input:
PR Contents
helper/wrappedreadline
: New helper library for gaining access to the original standard streams and not the wrappers given to us by panicwrap. This is important forreadline
to work properly.repl
: New core Terraform library for REPL-behavior. This extraction allows us to unit test it very well instead of it all being stuffed in core. Also, by being a separate library there exists a future where we may be able to drop a REPL in scenarios where Terraform fails at runtime (with a debug flag or something). Maybe.command/console
: The console command.terraform/interpolation.go
changes: Improving the error messages that are now possible due to the REPL. This file continues to be a primary target for refactor and change in the future.vendor update
panicwrap
: panicwrap needed to be updated to pass through raw standard streams.Future
The following are some ideas I have for the future of this that won't be included in this PR or targeted even for 0.8:
Tab-completion: we get this from the readline library we use, but we need to complete the completer.
Setting variables
Listing resources
Actual resource configuration
Operations such as plan/apply