terraform-compliance / cli

a lightweight, security focused, BDD test framework against terraform.
https://terraform-compliance.com
MIT License
1.36k stars 151 forks source link

Additional state file detection for terraform state pull cases #235

Open eerkunt opened 4 years ago

eerkunt commented 4 years ago

Feature Request

Feature description : While running against state files instead of plan files, terraform-compliance runs if the state file is created via ;

terraform show -json > state.out.json or terraform state pull > state.out && terraform show -json state.out > state.out.json

Since the latter could be a functionality within the tool, it would be nice if we just implement it.

The issue is also described in #223

kjr247 commented 4 years ago

I'm getting an error running against both of these right now.

Macos Catalina terraform-compliance v1.2.7

$ terraform-compliance -p state.out
# ERROR: state.out is not a valid terraform plan json output.
$ terraform-compliance -p state.out.json
# ERROR: state.out.json is not a valid terraform plan json output.
eerkunt commented 4 years ago

Can I have your state file if possible @kjr247 ?

jantman commented 4 years ago

I believe this and #305 are describing the same issue.

For my use case at least, it would be really helpful if TC could run directly on state files instead of needing to pass them through terraform show.

andr9184 commented 3 years ago

Terraform 0.13.5 terrafrom-compliance 1.3.8

For some reason helped to use:

terraform plan -out plan.out
terraform show -json plan.out > plan.out.json
terraform-compliance -f tests -p plan.out.json

instead of terraform state pull > state.out && terraform show -json state.out > state.out.json

nwsparks commented 2 years ago

in the meantime i think it would help to update the docs here to indicate to use terraform show -json > state.out.json instead of terraform state pull https://terraform-compliance.com/pages/usage/#-p--planfile

related here too https://github.com/terraform-compliance/cli/issues/305