Extract a summary of variables used in the root module?

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.

Thanks!

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:

terraform-config-inspect --json . | jq .variables
3 Likes

This looks like exactly what I was hoping to find.

Thank you!

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.

Hi @wyardley, thank you for the pointer. This looks promising as well.

It’s intended more for a module

The root module is a module, right? I think it might be appropriate for my use case :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.