I’d like to parse a terraform root module and extract the details of all of the variables used within.
I expected to find a straightforward command like terraform variables -json which would provide a nice summary, but I haven’t spotted it yet.
Does it exist?
Use case is a wrapper application which interactively collects variable values from a human, then runs terraform plan with confidence that all of the required values are set in the environment.
I don’t know of any such package, but there is the github.com/hashicorp/terraform-config-inspect package which can still read a subset of current configuration (though it’s not updated for all features).
While not complete, it can at least list all variables and their defaults:
Maybe not exactly what you were looking for, especially since your use case is an application, but terraform-docs is a great tool which can generate docs for a terraform module. It’s intended more for a module that other things are consuming, but it’s pretty customizable and templatable, and can support a bunch of output formats.
It will also document the types and descriptions of those variables in a pretty useful way.