GitLab Variables for Credentials – ACI Lab

In my previous ACI automation post, I used Terraform and the credentials were in plain text inside the main.tf file.

I have updated this, so the credentials are stored in GitLab environment variables, which is a much more secure method. The process of the credentials from GitLab to Terraform are as follows;

Create Environment Variables

The environment variables are key/value pairs located under: <Project> >> Settings >> CI/CD >> Variables

Import Variables to GitLab CI File

The .gitlab-ci.yml file will have the variables imported. It will then pass them to each stage by default.

Each variable must be prefixed with TF_VAR_. When passed to Terraform, it will ignore this and just keep the value name.

Stages can ignore the variables provided by using a blank variables key. Documentation reference.

Import Variables in Terraform

To import the variables into Terraform, the prefixed TF_VAR_ must be removed and a variable must be declared in terraform.

Leave a Comment

Your email address will not be published. Required fields are marked *