Execute Azure CLI commands when using Terraform Cloud

Hi! I am new to Terraform (and currently in “experiencing/learning mode”), but I am using terraform cloud to deploy resources in azure. However, to deploy a mysql replica, I understand that this cant be done by terraform directly, but has to be done by for example azure cli.

If I run a “local” terraform in a azure cloud shell, I can get the following code to work as expected:

resource “null_resource” “azure-cli” {

provisioner “local-exec” {

command = "az mysql server replica create --name $replicaserver --source-server $sourceserver --resource-group $rg_name --location westeurope"

However, when running the same code in terraform cloud, I get “exit status 127. Output: /bin/sh: 1: az: not found”.

Can someone point me in the right direction on how to run azure cli commands when I am using Terraform Cloud?

3 Likes

@Frank_Thingelstad Have you found any work around?

1 Like

I want this too. Any solutions? Please.

I tried to use the AZ bash install script, but that failed with ‘bash: line 42: /dev/tty: No such device or address’

resource "null_resource" "script-signalr-setappconfig" {
# Use this mechanism to always execute the script on 'terraform apply'
triggers = {
    build_number = "${timestamp()}"
}

provisioner "local-exec" {

    command = <<EOH
    curl -L https://aka.ms/InstallAzureCli | bash
    chmod 0755 az
    az appconfig kv set-keyvault <some extra stuff>
EOH
}
}

@rahulraj7-del: Sorry, didn’t find any. Ended up creating the replica manually.

This works pretty good using pipelines in Azure.

It seems to have the Azure CLI available natively. You probably need the Terraform Cloud team to make that available in the enviroment your running the scripts from.