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

cli/init.go:42 failed to initialize terrascan. error : failed to download policies. error: 'repository already exists' #1728

Open
zoezhangmattr opened this issue Mar 17, 2025 · 0 comments

Comments

@zoezhangmattr
Copy link

zoezhangmattr commented Mar 17, 2025

we are using pre-commit, with terrascan
pre-commit version 4.1.0
terrascan version 1.19.9
terraform version 1.11.1

pre-commit config

repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.97.4
    hooks:
    - id: terrascan
      args:
          - >
            --args=--severity High --non-recursive

when running precommit in github workflow.
we dont specify any terrascan extra configs. or policy configs.
the error occurs
cli/init.go:42 failed to initialize terrascan. error : failed to download policies. error: 'repository already exists'

what i tried,
remove ~/.terrascan folder (even though nothing is there) just make sure there is no such folder in the github runner.
ls -all ~/.terrascan || true
ls -all ~/.config/terrascan || true
ls -all /tmp/terrascan || true
rm -rf ~/.terrascan
rm -rf ~/.config/terrascan
rm -rf /tmp/terrascan
ls: cannot access '/home/runner/.terrascan': No such file or directory
ls: cannot access '/home/runner/.config/terrascan': No such file or directory
ls: cannot access '/tmp/terrascan': No such file or directory

nothing works

i enabled debug logs, found something weird,

it tried to download policy twice? could this be the cause for repository already exist.

also absolute rego_subdir path, /opt/actions-runner/_work/my-repo/my-repo/terraform/oidc/pkg/policies/opa/rego, does not fall under base repo path's /home/runner/.terrascan directory structure
we dont have any policy config under the repo. folder terraform/oidc, why it will show this?

debug	cli/register.go:66	TERRASCAN_CONFIG:
2025-03-17T03:04:03.949Z	debug	cli/register.go:66	TERRASCAN_CONFIG:
2025-03-17T03:04:03.949Z	debug	config/config-reader.go:55	no config file specified
2025-03-17T03:04:03.949Z	debug	config/config-reader.go:55	no config file specified
2025-03-17T03:04:03.949Z	debug	utils/policy.go:43	absolute rego_subdir path, `/opt/actions-runner/_work/my-repo/my-repo/terraform/oidc/pkg/policies/opa/rego`, does not fall under base repo path's `/home/runner/.terrascan` directory structure
2025-03-17T03:04:03.949Z	debug	utils/policy.go:43	absolute rego_subdir path, `/opt/actions-runner/_work/my-repo/my-repo/terraform/oidc_second/pkg/policies/opa/rego`, does not fall under base repo path's `/home/runner/.terrascan` directory structure
2025-03-17T03:04:03.949Z	debug	utils/policy.go:44	appending rego_subdir path: `pkg/policies/opa/rego` to the policy base path: `/home/runner/.terrascan`. checking ...
2025-03-17T03:04:03.949Z	debug	utils/policy.go:44	appending rego_subdir path: `pkg/policies/opa/rego` to the policy base path: `/home/runner/.terrascan`. checking ...
2025-03-17T03:04:03.949Z	debug	config/global.go:126	global config loaded
2025-03-17T03:04:03.949Z	debug	config/global.go:126	global config loaded
2025-03-17T03:04:03.949Z	debug	initialize/run.go:52	initializing terrascan
2025-03-17T03:04:03.949Z	debug	initialize/run.go:52	initializing terrascan
2025-03-17T03:04:03.949Z	debug	initialize/run.go:68	downloading policies
2025-03-17T03:04:03.950Z	debug	initialize/run.go:68	downloading policies
2025-03-17T03:04:03.951Z	debug	initialize/run.go:69	base directory path : /home/runner/.terrascan
2025-03-17T03:04:03.951Z	debug	initialize/run.go:69	base directory path : /home/runner/.terrascan
2025-03-17T03:04:04.219Z	debug	initialize/run.go:225	policy directory path : https://github.com/tenable/terrascan.git
2025-03-17T03:04:04.219Z	debug	initialize/run.go:226	policy repo url : https://github.com/tenable/terrascan.git
2025-03-17T03:04:04.219Z	debug	initialize/run.go:227	policy repo git branch : master
2025-03-17T03:04:04.219Z	debug	initialize/run.go:228	cloning terrascan repo at /home/runner/.terrascan
2025-03-17T03:04:04.220Z	debug	initialize/run.go:225	policy directory path : https://github.com/tenable/terrascan.git
2025-03-17T03:04:04.220Z	debug	initialize/run.go:226	policy repo url : https://github.com/tenable/terrascan.git
2025-03-17T03:04:04.220Z	debug	initialize/run.go:227	policy repo git branch : master
2025-03-17T03:04:04.220Z	debug	initialize/run.go:228	cloning terrascan repo at /home/runner/.terrascan
2025-03-17T03:04:04.222Z	error	cli/init.go:42	failed to initialize terrascan. error : failed to download policies. error: 'repository already exists'

could you help please

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

No branches or pull requests

1 participant