open-policy-agent / conftest

Write tests against structured configuration data using the Open Policy Agent Rego query language
https://conftest.dev
Other
2.82k stars 298 forks source link

Terraform 0.12 not supported #78

Closed carsonoid closed 4 years ago

carsonoid commented 4 years ago

It looks like the Terraform 0.12 syntax isn't supported.

.tf snippet:

resource "aws_vpc" "vpc" {
  cidr_block           = var.cidr
...
}

Error:

FATA[0000] Problem running evaluation: load terraform config failed: Error parsing JSON document as HCL: At 2:26: Unknown token: 2:26 IDENT var.cidr
boranx commented 4 years ago

Hi,

I did a little research about this. From what I understand about this is:

With Terraform 0.12 they started to use HCL2. HCL2 has some differences from classic HCl(expressions, static-analysis, etc..).Therefore, converting it to JSON can be tricky and I think the parser for classic HCL and HCL2 should be different parsers in order to keep current functionality. Maybe, we can use this: hcl2json to convert newly added syntax to classic JSON.

@Salamandastron1 What do you think about this issue? Maybe, you can add both HCl and HCL2 implementations to your PR!

Salamandastron1 commented 4 years ago

Hi @boranx! I definitely think it would be a great addition. The diff on my PR is pretty big though so I'm hesitant to add any more. If the PR gets accepted I'd be happy to look further into this :)

boranx commented 4 years ago

I'm making a PR about this feature.

carsonoid commented 4 years ago

Awesome! Thanks for your work @boranx