Git Product home page Git Product logo

Comments (8)

vrbcntrl avatar vrbcntrl commented on May 24, 2024

I think I found root cause for the above error...

The below code in terraform_files.py returns None for terraform_executable
def convert_terraform_plan_to_json(terraform_plan_file, terraform_executable=None):
print('. Converting terraform plan file.')
if terraform_executable is None:
terraform_executable = which('terraform')

hence its failing when the code tries to convert the plan file to json

so, next instead of testing the terraform plan file, I created the terraform state file and then ran the terraform-compliance tests, it worked properly..

Question : has anybody tested terraform-compliance 1.0.1 in windows with out any issues?
it looks like to me that in windows, the python which function not working hence returning None when executed the code: terraform_executable = which('terraform')

Please let me know. Thanks!

from cli.

eerkunt avatar eerkunt commented on May 24, 2024

Thanks for the issue!

I haven't tested the code on Windows, unfortunately. This might be an OS specific bug, too.

Found the problem, fixing.

from cli.

eerkunt avatar eerkunt commented on May 24, 2024

Before I release the fix, to have a workaround, after you create your plan.out, convert it with terraform like terraform show -json plan.out > plan.out.json. Then you can pass plan.out.json (or whatever file you created) to terraform-compliance

I will also fix the convertion part where it won't require to do this.

from cli.

eerkunt avatar eerkunt commented on May 24, 2024

Can you try the same behaviour with 1.0.2 please ?

from cli.

vrbcntrl avatar vrbcntrl commented on May 24, 2024

Hi @eerkunt ,

Thanks for the quick response!

  1. First I have tried your workaround, i.e. convert plan.out with terraform like terraform show -json plan.out > plan.out.json. Then pass plan.out.json (or whatever file you created) to terraform-compliance
    and it worked :)

  2. I installed v 1.0.3 then tried with plan.out, but still it failed with below error

`C:\Users\vrb.cntrl>terraform-compliance -f C:\Training\cloud\terraform-compliance\1.0.3\terraform-compliance-master\terraform-compliance-master\example\example_01\aws -p C:\Training\AWS\Terraform-Examples\intro-to-terraform-master\single-web-server\plan.out
terraform-compliance v1.0.3 initiated

. Converting terraform plan file.
ERROR: Could not find "terraform" executable in PATH. Please either use "-t" parameter or add terraform executable to your PATH.`

then I added the -t parameter and the terraform.exe path as shown below but it also failed

**C:\Users\vrb.cntrl>terraform-compliance -f C:\Training\cloud\terraform-compliance\1.0.3\terraform-compliance-master\terraform-compliance-master\example\example_01\aws -p C:\Training\AWS\Terraform-Examples\intro-to-terraform-master\single-web-server\plan.out -t C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64
terraform-compliance v1.0.3 initiated

. Converting terraform plan file.
ERROR: Could not find "terraform" executable in PATH. Please either use "-t" parameter or add terraform executable to your PATH.**

I think you still need to fix the convert_terraform_plan_to_json() function add a thrird parameter to it i.e. -t parameter value from CLI and assign that value to terraform_executable variable in the else condition?

else:
print('Using {} as terraform executable.'.format(terraform_file))
terraform_executable = terraform_file

Please let me know.Thanks!

from cli.

eerkunt avatar eerkunt commented on May 24, 2024

It looks like -t parameter could not be initialised. Fixed the problem.

1.0.4 is being released right now, please let me know if it is still failing for you.

Just a hint, better to add C:\Training\cloud\terraform\ to your %PATH% not to pass -t all the time :)

from cli.

vrbcntrl avatar vrbcntrl commented on May 24, 2024

thanks for the fix.
I have the terraform.exe file path i.e. C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64 in my %PATH% from the beginning, not sure why it is not able to read that path.

So, I have tested 1.0.4 with out -t parameter and with terraform executable path in %PATH%, but it still failed

Tested 1.0.4 with -t parameter with its value as C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64 but it still failed with below error

`C:\WINDOWS\system32>terraform-compliance -f C:\Training\cloud\terraform-compliance\1.0.4\terraform-compliance-master\example\example_01\aws -p C:\Training\AWS\Terraform-Examples\intro-to-terraform-master\single-web-server\plan.out -t C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64
terraform-compliance v1.0.4 initiated

. Converting terraform plan file.
Using C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64 as terraform executable.
ERROR: C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64 is not executable. Please give correct executable for "terraform".
[WinError 5] Access is denied`

so, I added the terrform.exe to the end of the path in -t parameter and it worked

`C:\WINDOWS\system32>terraform-compliance -f C:\Training\cloud\terraform-compliance\1.0.4\terraform-compliance-master\example\example_01\aws -p C:\Training\AWS\Terraform-Examples\intro-to-terraform-master\single-web-server\plan.out -t C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64\terraform.exe
terraform-compliance v1.0.4 initiated

. Converting terraform plan file.
Using C:\Training\cloud\terraform\terraform_0.12.1_windows_amd64\terraform.exe as terraform executable.

  • Features : C:\Training\cloud\terraform-compliance\1.0.4\terraform-compliance-master\example\example_01\aws
  • Plan File : C:\Training\AWS\Terraform-Examples\intro-to-terraform-master\single-web-server\plan.out.json

. Running tests.
Feature: Credentials should not be within the code # C:\Training\cloud\terraform-compliance\1.0.4\terraform-compliance-master\example\example_01\aws\credentials.feature
In order to prevent any credentials leakage
As engineers
We'll enforce credentials will not be hardcoded
.....................................................`

so, I think I'm good now. Thanks!

from cli.

eerkunt avatar eerkunt commented on May 24, 2024

Thanks for the re-test, yes, you need to give terraform executable with -t parameter instead of just the path. I will change the wording on -h describing the parameter.

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.