Search code examples
gitlabterraformgitlab-cigitlab-ci-runner

terraform: command not found in gitlab CI environment


I have following CI configurations:

variables:
  TF_ROOT: ${CI_PROJECT_DIR}
  TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}
  TF_CLI_CONFIG_FILE: $CI_PROJECT_DIR/.terraformrc

default:
  image: hashicorp/terraform:light

cache:
  key: ${CI_PROJECT_NAME}
  paths:
    - ${TF_ROOT}/.terraform


before_script:
  - echo -e "credentials \"$CI_SERVER_HOST\" {\n  token = \"$CI_JOB_TOKEN\"\n}" > $TF_CLI_CONFIG_FILE
  - cd ${TF_ROOT}
  - export TF_LOG_CORE=TRACE
  - export TF_LOG_PATH=terraform_logs.txt

stages:
  - prepare

init:
  stage: prepare
  script:
    - terraform -v
    - terraform init

But at prepare stage i get:

$ terraform -v
bash: line 135: terraform: command not found

My understanding is by using hashicorp/terraform:light as base image, i get terraform available throughout the runner environment but that doesn't seems to be the case.

Can anyone correct me what am i doing wrong?


Solution

  • the issue was the gitlab-runner was configured to be a shell executor. Which makes the whole image: hashicorp/terraform:light part redundant and terraform should be installed on the host machine itself where runner is being executed.