Teraform Gitlab image - no azure cli

I started to try to do this, and ran into the same issue. I wasn’t sure whether to file a bug or come here, but if this isn’t getting any attention …

I’m using the Terraform.latest.gitlab-ci.yml template (because I’m a slave to code reuse), which uses the same base image as the OP. It doesn’t have any obvious hooks for adding extra content to the image before the jobs run, so I’ve overridden the build and deploy jobs by copying in their definitions from the template, and adding a before_script:

.install_azure: &install_azure
  - apk add --no-cache python3 py3-pip
  - apk add --no-cache gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
  - pip install azure-cli

build:
  extends: .terraform:build
  before_script:
    - *install_azure

deploy is more annoying, since it’s more than a simple wrapper around .terraform:deploy, but it’s the same idea.

Adding python3 isn’t a big deal, and that’s needed for az anyway. But the second apk add invocation adds about a gig to the image, and the azure-cli install, which ends up building a handful of wheels, took about ten minutes to complete. I’ll try to work out the caching necessary for that.

This is a bit nuts, though most of the nuttiness is due to Microsoft not just providing an APK for az. I’ve added a question about that to Install Azure CLI on Alpine Linux · Issue #19591 · Azure/azure-cli · GitHub.

But it would be nice to have a more elegant, DRY-compatible way to install extra software or otherwise prep the image before getting to the build and deploy stages. I’ve been thinking about that as having some way to “inject” a before_script into an existing job description, but maybe it’s just a matter of doing what I’ve done here, with a more generic name, integrated into the existing YAML files, but I’m struggling to figure out what that would look like (not being super familiar with all that YAML has to offer).