Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: /hashicorp/terraform does not look like terraform #102

Closed
anthonycolon25 opened this issue Jun 24, 2019 · 9 comments
Closed

ERROR: /hashicorp/terraform does not look like terraform #102

anthonycolon25 opened this issue Jun 24, 2019 · 9 comments
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@anthonycolon25
Copy link

I am trying to use the 1.0.5 Docker image but I get the following error:

colon191818al:hashicorp abs123$ terraform-compliance -p /hashicorp/tc-test2/tf-template/plan.out -f /hashicorp/tc-test2/features -t /hashicorp/terraform
terraform-compliance v1.0.5 initiated

. Converting terraform plan file.
Using /hashicorp/terraform as terraform executable.
ERROR: /hashicorp/terraform does not look like terraform. Please give correct executable for "terraform".
[Errno 8] Exec format error: '/hashicorp/terraform'
colon191818al:hashicorp abs123$

I mapped the docker call to a function as follows:

colon191818al:hashicorp abs123$ function terraform-compliance { docker run -v $(pwd):/hashicorp -i -t eerkunt/terraform-compliance "$@"; }

Terraform was added to my .profile so I can execute from anywhere:

colon191818al:hashicorp abs123$ terraform -version
Terraform v0.12.2

colon191818al:hashicorp abs123$ ls -al
total 106056
drwxr-xr-x 9 abs123 COMPANY\Domain Users 288 Jun 24 17:28 .
drwxr-xr-x+ 39 abs123 COMPANY\Domain Users 1248 Jun 24 18:48 ..
drwxr-xr-x 5 abs123 COMPANY\Domain Users 160 Jun 24 17:58 tc-test2
-rwxrwxr-x@ 1 abs123 COMPANY\Domain Users 54228088 Jun 12 20:12 terraform

Is Terraform v0.12.2 supported?

Thanks in advance for your help.

@eerkunt
Copy link
Member

eerkunt commented Jun 25, 2019

Hello @anthonycolon25,

You have just found something that I haven't thought about. The document needs to be updated about this.

First of all, your function is not correct :) You are trying to mount a volume to a path in the docker image that doesn't exist (/hashicorp). Correct function should be within the document ;

function terraform-compliance { docker run --rm -v $(pwd):/target -i -t eerkunt/terraform-compliance "$@"; }

Normally this should work for you, assuming your terraform executable is living in /hashicorp/terraform in your local disk.

In the document, it is currently written that you need to pass absolute path of terraform executable when you use -t command. That is unfortunately wrong, if you are using a Docker image. You need to use relative path to your current pwd since you are mounting pwd to the docker image. One of the fallbacks about this method is, if the terraform executable lives on a parent directory of pwd then it will fail, since that parent directory won't exist in the Docker image.

POTENTIAL SOLUTIONS :

  1. Change the function like ;
function terraform-compliance { docker run --rm -v $(pwd):/target -v /path/to/terraform/executable/directory:/terraform -i -t eerkunt/terraform-compliance "$@"; }

and then run terraform compliance with ;

terraform-compliance -f /path/to/features -p /path/to/plan.out -t /terraform/terraform

since /terraform/terraform will be a file that is accessible within the Docker container.

  1. Do not change the function, move terraform executable to pwd, and run terraform-compliance with ;
terraform-compliance -f /path/to/features -p /path/to/plan.out -t /target/terraform

since /target/terraform will be accessible (due to -v $(pwd):/target directive in the function) within the Docker container.

I will find a better solution to this, meanwhile you can try one of these workarounds, or just install via pip install terraform-compliance to your local machine.

@anthonycolon25
Copy link
Author

Hi,

Sorry for the confusion. I had the function in exactly that format originally (copied from github page) and got the same error. What I pasted was one of the iterations trying to get it to work.

Here is my current folder structure (I'll clean it up later once I get things working)

hashicorp
|-- terraform (executable)
|-- tc-test2
|---- features (feature files)
|---- tf-template
|------ (terraform tf files)
|------ plan.out

I believe -v $(pwd):/target will map my current directory to /target on the container. So once that is done the paths I pass to the -p and -f arguments should include /target in the path.

colon191818al:hashicorp abs123$ function terraform-compliance { docker run -v $(pwd):/target -i -t eerkunt/terraform-compliance "$@"; }

colon191818al:hashicorp abs123$ terraform-compliance -p /target/tc-test2/tf-template/plan.out -f /target/tc-test2/features -t /target/terraform
terraform-compliance v1.0.5 initiated

. Converting terraform plan file.
Using /target/terraform as terraform executable.
ERROR: /target/terraform does not look like terraform. Please give correct executable for "terraform".
[Errno 8] Exec format error: '/target/terraform'

Also, if I put a bogus path to the terraform file I get a "No such file or directory" error.

colon191818al:hashicorp abs123$ terraform-compliance -p /target/tc-test2/tf-template/plan.out -f /target/tc-test2/features -t /target/notthere/terraform
terraform-compliance v1.0.5 initiated

. Converting terraform plan file.
Using /target/notthere/terraform as terraform executable.
ERROR: /target/notthere/terraform does not exist. Please give correct executable for "terraform".
[Errno 2] No such file or directory: '/target/notthere/terraform': '/target/notthere/terraform'

This leads me to believe that it is indeed finding the terraform file in /target/terraform but somehow is not able to use it.

@eerkunt
Copy link
Member

eerkunt commented Jun 25, 2019

Ah of course. Possibly the operating systems compared with the Docker container and the host machine is different and the terraform that you use within your host machine is not compiled for the OS running in Docker container.

I will embed different terraform versions within the Docker and also add into the $PATH within the Docker for avoiding this problem. Thanks a lot debugging this!

As a workaround, you can convert your plan to json manually by running

terraform show -json plan.out > plan.out.json

and give plan.out.json (without using -t since you won't need terraform anymore) to terraform-compliance

@anthonycolon25
Copy link
Author

anthonycolon25 commented Jun 25, 2019

I see. That makes perfect sense. I am running on a Mac, so the terraform executable may not be compatible with Docker image OS.

I have converted the output to the json format. It got further but now I get FATAL ERROR: Unsupported terraform version (0.12.2).

$ terraform-compliance -p /target/tc-test2/tf-template/plan.out.json -f /target/tc-test2/features
terraform-compliance v1.0.5 initiated

  • Features : /target/tc-test2/features
  • Plan File : /target/tc-test2/tf-template/plan.out.json

. Running tests.
Feature: Resources should be properly tagged # /target/tc-test2/features/tags.feature
In order to keep track of resource ownership
As engineers
We'll enforce tagging on all resources

FATAL ERROR: Unsupported terraform version (0.12.2).

2 features (0 passed)
6 scenarios (0 passed)
17 steps (0 passed)
Run 1561468441 finished within a moment

I get the same error on terraform 0.12.3.

@eerkunt
Copy link
Member

eerkunt commented Jun 25, 2019

ah yes, I already tested that with those versions.

#104 has this fix.

@eerkunt
Copy link
Member

eerkunt commented Jun 25, 2019

Can you try with 1.0.7 please ?

@anthonycolon25
Copy link
Author

With 1.0.7 I am now able to run tests based on the json output.

@eerkunt
Copy link
Member

eerkunt commented Jun 28, 2019

Thanks to @wp-davisona, terraform is added into the Docker containers within 1.0.12, could you please try when you have time ? Thanks!

@eerkunt eerkunt added waiting for confirmation Workaround/Fix applied, waiting for confirmation and removed documentation enhancement labels Jun 28, 2019
@eerkunt
Copy link
Member

eerkunt commented Jul 8, 2019

Assuming this is fixed, please re-open the issue if this is not working for you.

@eerkunt eerkunt closed this as completed Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants