I'm running a very lightweight GitLab Pipeline which executes a number of Terraform configuration. However, I have hit an absolute roadblock as the pipeline throws an Azure CLI error (screenshot below) when it attempts to run a Terraform init and I simply can't seem to resolve this. Any ideas?
This error happens at the pipeline stage: validate
.
Prior to that however, I have another pipeline stage: deploy
where I am able to install Azure CLI successfully, using the below commands:
deploy:
stage: deploy
image: mcr.microsoft.com/dotnet/core/sdk:3.1
script:
- curl -sL https://aka.ms/InstallAzureCLIDeb | bash
So after some further investigation, it turns out that this error only occurs when I include my terraform backend.tf
file which configures an Azure backend for storing my terraform state file. Exclude this file and everything runs smoothly. I'm at a complete loss, as I definitely require that state file in Azure.
It does appear to me that the Azure CLI successful install at the pipeline deploy
stage (above) isn't picked up by the Backend.tf configuration.
Below is the content of my Backend.tf file
terraform {
backend "azurerm" {
resource_group_name = "rg_xxx"
storage_account_name = "stxxxxtfstate"
container_name = "terraform"
key = "terraform.tfstate"
}
}
And below is the YAML snippet from the pipeline deploy
stage of my .gitlab-ci.yml
file where I call terraform init
and apply
.
deploy:
stage: deploy
script:
- terraform init
- terraform plan -var-file=dev-settings.tfvars -out=plan.out
- terraform apply -auto-approve plan.out