Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Unable to parse terraform variables #127

Closed
BalakrishnanKumaravel opened this issue Aug 13, 2019 · 4 comments
Closed

Unable to parse terraform variables #127

BalakrishnanKumaravel opened this issue Aug 13, 2019 · 4 comments

Comments

@BalakrishnanKumaravel
Copy link

Hi,

I tried to parse the below in a terraform file and the parser fails to parse it.

I used the method ParseHCL in the file (https://github.com/hashicorp/hcl2/blob/master/hclparse/parser.go) by converting the below input to byte[]. Should I be calling a different method to parse?

variable "NumInstances" {
default = "3"
}

Thanks,
Bala

@apparentlymart
Copy link
Contributor

Hi @BalakrishnanKumaravel,

In order to know what's going on here, could you please share the exact error messages you got when attempting to parse that input?

Depending on what your goal is, you might find it easier to use terraform-config-inspect, which is a higher-level library designed specifically for extracting declaration metadata from Terraform modules.

@BalakrishnanKumaravel
Copy link
Author

BalakrishnanKumaravel commented Aug 14, 2019 via email

@BalakrishnanKumaravel
Copy link
Author

BalakrishnanKumaravel commented Aug 14, 2019 via email

@apparentlymart
Copy link
Contributor

Hi @BalakrishnanKumaravel,

For Terraform, files must be named .tf.json in order to be parsed in JSON syntax. A file named .tf will always be parsed in the native syntax. It's also invalid to mix both native syntax and JSON syntax in the same file, which I think is what you are doing here, and why the output from terraform-config-inspect was able to parse one variable but then failed to parse the following content.

This has become a Terraform question rather than an HCL question, so I'm going to close this issue here, but if you have more questions I'm happy to continue talking about it in a new topic in the Terraform community forum. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants