Using the Azure Provider with Terraform Cloud

Hi

I’m trying to follow the Terraform documentation in order to deploy resources using the Azure Provider and Terraform Cloud.

I believe I have mirrored the example in the docs exactly, and I can certainly apply the terraform perfectly before I added the backend config.

This is the example from the documentation, which errors when I run it. With a bit of reading around I think the backend config should be placed inside the terraform block.

So I have changed the code to the below:

This certainly gets further when I run and initializing the terraform works perfectly. However when I go to plan/apply the changes, it errors with the below:

Error: Error building AzureRM Client: obtain subscription() from Azure CLI: Error parsing json result from the Azure CLI: Error launching Azure CLI: exec: “az”: executable file not found in $PATH

I have logged into the Azure tenant using az login, and I have successfully logged into Terraform using terraform login. I have also tried re-authenticating both at the point of this error appearing.

Would someone be able to help out a newbie please? Have I messed up the config here or am I missing something?

Thanks very much.

3 Likes

Hi @Immune, welcome to the forum!

Thanks for pointing out the backend bug in the documentation, I’ve reported it to the Learn team.

On the second issue, the problem looks like you haven’t set up authentication from Terraform Cloud to Azure. When you log in locally using az login, this only works for local Terraform runs. When using the remote backend, you need to use Terraform Cloud workspace variables to authenticate.

Here’s how to do that:

Sorry that this wasn’t made clear in the guides! It’s quite an involved process, but I hope this helps.

5 Likes

Hi @alisdair

Thanks so much for your clear reply. That’s got me up and running nicely. It makes complete sense now you’ve explained it! Always the way :slightly_smiling_face:

4 Likes

That error sent me for a loop for nearly an entire work day. Tore apart various shell .*rc files and homebrew trying to figure out why a subshell seemingly had a different $PATH. Dumb luck I came across this post.

Can we get this output changed?

Error launching Azure CLI: exec: “az”: executable file not found in $PATH

2 Likes

You might not assign the role to AD user so please check role assignment has been done or not if no so please assign and then check you will get solution.

thank you so much for documentation . it very helpful !