I am trying to implement a CI/CD pipeline for Terraform, however I need to change the pwd before running any further commands.
It appears the Terraform container only accepts Terraform commands, so cd/ls/echo $PATH are unrecognised. Do I need build an image which supports this and use that, or can I use the maintained Terraform images?
I tried changing the ENTRYPOINT but appears only a minimal install is available due to the Alpine image.
Build Directory GitLab Runner clones the repository to a path that exists under a base path better known as the Builds Directory. The default location of this base directory depends on the executor. For: Kubernetes, Docker and Docker Machine executors, it is /builds inside of the container.
From version 7.12, GitLab CI uses a YAML file ( . gitlab-ci. yml ) for the project configuration. It is placed in the root of your repository and contains definitions of how your project should be built.
GitLab CI/CD fits in a common development workflow. You can start by discussing a code implementation in an issue and working locally on your proposed changes. Then you can push your commits to a feature branch in a remote repository that's hosted in GitLab. The push triggers the CI/CD pipeline for your project.
You can change the entrypoint to /usr/bin/env
in order to run a cd command. Example with gitlab-ci:
validate_terraform:
image:
name: hashicorp/terraform:light
entrypoint: ["/usr/bin/env"]
stage: test
script:
- cd infrastructure/
- terraform init
- terraform validate
You could just use a generic image like alpine
in your .gitlab-ci.yml
and get the Terraform inside your script like:
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_386.zip
unzip terraform*
and use it like:
./terraform [...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With