-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Parse terraform files #18269
Comments
Hi @zunlihu! Can you please describe in a little more detail what you are trying to achieve? Terraform does not currently have a general API for external programs to parse configurations, but if you can describe your use-case we may be able to add some features to help you in a later release. Thanks! |
I want to collect all reousrce/data/modules types used in the .tf files. For examples, given a tf file as follows, I can get that there is one resource and one data source in the file, and data type is "archive_file", resource type is "aws_lambda_permission". data "archive_file" "lambda_zip" { resource "aws_lambda_permission" "allow_bucket" { |
Thanks for sharing the use-case, @zunlihu! We don't currently have a mechanism in place to easily extract that sort of information, but we are planning to add new commands to Terraform to inspect configurations and plans in a machine-readable way (JSON, most likely) that I think will give you what you need. Unfortunately I can't say at the moment when such a feature would be implemented, but we can hopefully work on a first version of it once we're finished our current project to replace the old HCL implementation with the new, as we'd discussed over in hashicorp/hcl#250. |
Does the various 3rd party tools under #3170 help in the interim? For me, this is also an issue of interest. At the moment, I'd like to extract out fields in a variable in *.tf file like
getting both the variable name & the default value |
I also have a similar use case. I want to parse the resource file to get what the map out of the Resource Schema for fields. My go file should take a resource file as input and generate something like following.
Should output
I am looking forward to parse using a regular expression. Is there a better way to do that. I am new to terraform and does not have a deep knowledge about the same. |
Hi @rvsingh011 , @zunlihu, if this is something you are still working with, terraform 0.12 has a new Terraform Enterprise customers also have access to Sentinel which has some features for inspecting configuration. |
In the meantime since my original reply, we open-sourced the terraform-config-inspect library, which is the component that does the shallow config parsing to generate docs for Terraform Registry. It's intentionally only exporting a shallow description of the top-level objects in the configuration, but that should be sufficient for @zunlihu's needs, at least. There's some more documentation about it in its GitHub repository. |
@apparentlymart Do you have any tool to parse terraform file that is contatins variables and their values, and convert it to Json or objects? |
@AKozintsov did you take a look at terraform-config-inspect, which @apparentlymart suggested in the comment above? |
I'm going to close this issue; terraform's json output (from both |
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. |
Hi,
I am trying to parse terraform files(.tf) to extract Terraform-related information such as resources, module calls, etc.
Can you give me some instructions for that?
Thanks!
The text was updated successfully, but these errors were encountered: