skip to Main Content

I get this error running a "terraform plan". I authenticated terraform to Azure via CLI. I have set up an account subscription. How can I solve this problem?

Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing JSON result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in %PATH%.

2

Answers


  1. The error says that az is not found. So for this type of error simple way out is logging-in into Azure like below:

    az login
    

    enter image description here

    Then the error goes:

    enter image description here

    And then you can check your subscriptions once like below:

     az account list
    

    And following login step i got resolved my problem.
    And also check if you are using latest Azure Cli version.
    And also try the below command:

    az account get-access-token
    

    enter image description here

    References taken from:

    Login or Signup to reply.
  2. Terraform cloud needs an Azure access since your plan is running on the cloud.

    First, you need to create a service principal for azure

    az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/SUBSCRIPTION_ID"
    

    See this tutorial: https://developer.hashicorp.com/terraform/tutorials/azure-get-started/azure-build

    After service principal is created, you get this in response:

    {
      "appId": "...", - client_id
      "displayName": "...",
      "password": "...", - client_secret
      "tenant": "..."  - tenant_id
    }
    

    Then you can provide azure access for terraform using one of these methods:

    1. Add Workspace variables via terraform cloud GUI. They will be treated as environment variables.
    ARM_CLIENT_ID="..."
    ARM_CLIENT_SECRET="..."
    ARM_SUBSCRIPTION_ID="..."
    ARM_TENANT_ID="..."
    
    1. Or include them into your .tf file.
    provider "azurerm" {
      features {}
        
      subscription_id = '...'
      client_id       = '...'
      client_secret   = '...'
      tenant_id       = '...'
    }
    

    Hovever it’s not a good idea to sotre sensitive data in config.
    That’s why you may use method #3:

    1. Declare variables in your .tf file and pass them via command line
    provider "azurerm" {
      features {}
        
      subscription_id = var.subscription-id
      client_id       = var.client-id
      client_secret   = var.secret
      tenant_id       = var.tenant-id
    }
    
    terraform apply -var client-id='...' -var tenant-id='...' -var...
    

    See this answer for details:
    https://discuss.hashicorp.com/t/using-the-azure-provider-with-terraform-cloud/18177/2

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search