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

Add support for private terraform repos #631

Closed
jlk opened this issue Mar 27, 2021 · 8 comments · Fixed by #658
Closed

Add support for private terraform repos #631

jlk opened this issue Mar 27, 2021 · 8 comments · Fixed by #658
Assignees

Comments

@jlk
Copy link
Contributor

jlk commented Mar 27, 2021

  • terrascan version 1.4.0
  • Operating System: MacOS

Description

A terrascan user posted on Accurics Community that when using terraform modules stored on Terraform Cloud, terrascan fails at downloading the private module.

While terraform will make use of the token stored in ~/.terraformrc as documented here, terrascan doesn't seem to know of this...yet.

What I Did

I cloned the aws tf module over to a private tf.io repo for testing, along with a basic main.tf that references it. Scanning that project dies as seen below:

$ terrascan scan . 
2021-03-26T16:25:10.465-0700	error	downloader/module-download.go:113	error while fetching available modules for module: app.terraform.io/widgetswest/vpc/aws, at registry: app.terraform.io
2021-03-26T16:25:10.465-0700	error	commons/load-dir.go:100	failed to download remote module "app.terraform.io/widgetswest/vpc/aws". error: 'error looking up module versions: 401 Unauthorized'
2021-03-26T16:25:10.465-0700	error	commons/load-dir.go:121	failed to build unified config. errors: <nil>: Failed to read module directory; Module directory  does not exist or cannot be read.

2021-03-26T16:25:10.465-0700	error	cli/run.go:107	scan run failed{error 26 0  failed to build terraform allResourcesConfig}
@jlk
Copy link
Contributor Author

jlk commented Mar 27, 2021

Looks like terraform cloud auth is done via bearer token, so just need to see if we can add support for that. Think I see how to do so, will tinker over the weekend.

@jlk jlk self-assigned this Mar 27, 2021
@devang-gaur
Copy link
Contributor

@jlk you mean private terraform repos ?

@MrMickS
Copy link

MrMickS commented Apr 10, 2021

Is there any progress on this?

@jlk
Copy link
Contributor Author

jlk commented Apr 12, 2021

hey @MrMickS yep - a little longer than my "over the weekend" comment, sorry. :)

Wasn't quite as easy as I first thought - we can't just replace the http client, so I had to figure out some of terraform's data structures, plus I've got a few other things going on.

I've got something working POC late last week - adding in ability to read that from .terraformrc and doing testing, should have a PR in today or tomorrow.

@jlk jlk changed the title Add support for private terrascan repos Add support for private terraform repos Apr 12, 2021
@jlk
Copy link
Contributor Author

jlk commented Apr 12, 2021

@jlk you mean private terraform repos ?

doh - thanks @dev-gaur

@MrMickS
Copy link

MrMickS commented Apr 12, 2021

That sounds great. Thanks very much.

@jlk
Copy link
Contributor Author

jlk commented Apr 15, 2021

@MrMickS - Just merged in support for this. if you're eager, you can try with the latest version of the master branch, otherwise we should be cutting a new release in the next week or two. It should Just Work - light mention in the docs at https://github.com/accurics/terrascan/blob/master/docs/usage.md#private-terraform-module-repositories

If there's an issue, let's address in a new GH issue (this was auto-closed when I merged the PR). Hope it meets your needs!

@MrMickS
Copy link

MrMickS commented Apr 16, 2021

The downloading from TF Cloud works well. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants