Closed Gaurang033 closed 2 months ago
The output from converting a .tf
file is not a Terraform plan, the structure is different. If you're writing your Rego against the Terraform plan structure, you must provide a plan for the test input. See https://github.com/open-policy-agent/conftest/blob/master/examples/hcl2/policy/deny.rego as an example of Rego written to test against .tf
files.
https://github.com/open-policy-agent/conftest/blob/master/examples/hcl2/policy/deny.rego
I agree those I two different thing. my understanding is opa doesn't support tf. correct me if I am wrong. and so I covert my plan to json and write test for it. however, i so in documentation that unit test can. which is weird. does that mean my actual test can support terraform as well ?
Conftest uses the OPA engine, but is not OPA. Conftest can accept and parse Terraform files or JSON, but the structure for these is not the same, so you need to write your Rego accordingly.
Closing due to inactivity, feel free to reopen if needed.
I am writing a unit test for my conftest and I was looking into the following documention, which suggest that parse_config_file would parse the terraform file. https://www.conftest.dev/
However, if my understanding is correct. Conftest doesn't yet support terraform code and so you need to convvert terraform plan file to json file and write a test for json.
Which I did. something like this and it works when I run on terraform json plan.
However, unit tests. are not working for the same terraform file.
The reason being parse_config_file won't convert the terraform file to a json on which I have write policy. seems like the document is mis leading. or am I missing something. ?
This is the trace from
conftest verify