3

I have a simple step with Gitlab CI to install Terraform on an Alpine based image:

step_1:
  stage: stage_x
  image: alpine/doctl:latest
  script:
    - wget https://releases.hashicorp.com/terraform/1.2.8/terraform_1.2.8_linux_amd64.zip
    - unzip terraform_1.2.8_linux_amd64.zip
    - mv terraform /usr/bin/terraform
    - terraform version

When executed, I have this error from the unzip command:

unzip: 'terraform' exists but is not a regular file

I tried this command over the same image in my machine and it works fine.
Any ideas?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Deoxyseia
  • 1,359
  • 18
  • 29
  • 1
    What happens if you use the destination option of unzip: `unzip terraform_1.2.8_linux_amd64.zip -d /usr/bin` and drop the `mv` totally? – β.εηοιτ.βε Aug 29 '22 at 19:05
  • 1
    But basically what the error there is telling you is that there is already a `terraform` in that container, and that It is not a regular file, so, probably a folder or a symlink – β.εηοιτ.βε Aug 29 '22 at 19:08
  • @β.εηοιτ.βε, I checked if in my local with there are a folder or symlink but it doesn't exist. And, the commands work well here with the same image. Over unzip in destination folder solved finlally the problem. – Deoxyseia Aug 29 '22 at 23:12

2 Answers2

1

One way to overcome your issue is to use the -d option of unzip in order to unzip Terraform in the folder /usr/bin directly:

-d DIR Extract into DIR

Source: unzip --help

This way, you can also drop the mv line totally.

So, your step becomes:

step_1:
  stage: stage_x
  image: alpine/doctl:latest
  script:
    - wget https://releases.hashicorp.com/terraform/1.2.8/terraform_1.2.8_linux_amd64.zip
    - unzip terraform_1.2.8_linux_amd64.zip -d /usr/bin
    - terraform version
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
0

The problem is that in CI, the Gitlab runner is checking out your code which already has a terraform folder. This makes the call to unzip to fail because it already finds the folder with the same name terraform pre-existing.

p.matsinopoulos
  • 7,655
  • 6
  • 44
  • 92