Search code examples
terraformterraform-provider-azureterraform-cloud

azure cli $Path error running in terraform cloud


Setting up terraform cloud for the first time and getting this error. Not sure why as on my local machine azure CLI is installed and the path is set, but I think has something to do with setting it in the terraform cloud platform.

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.
with provider["registry.terraform.io/hashicorp/azurerm"]
on versions.tf line 21, in provider "azurerm":

provider "azurerm" {

My currently tf code

versions.tf

terraform {

  cloud {
    organization = "myorg"

    workspaces {
      name = "dev"
    }
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.10.0"
    }
  }

  required_version = ">= 1.2.3"
}

provider "azurerm" {
  features {}
}

variables.tf

variable "tenant_id" {
    description = "tenant id for azure subscription"
}

main.tf

resource "azurerm_resource_group" "testrg" {
  name     = "test-rg"
  location = "Central US"
}

not doing anything fancy, but not sure how to get past the azure CLI error. I know where variables can be set in the terraform cloud platform, but not specifically where to set a $Path for the azure cli or even how to install azure cli in terraform cloud. On my local machine, I am logging in with az login on an account with sufficient permissions to the subscription.


Solution

  • I'm trying to "boil down" kavya Saraboju's answer, which is formally correct, to a bare minimum that helped me.

    The Error message seems to be very confusing, if it has anything at all to do with the actual problem. I had to set the environment variables ARM_CLIENT_ID, ARM_TENANT_ID, ARM_CLIENT_SECRET and ARM_SUBSCRIPTION_ID in Terraform Cloud. Go to Terraform Cloud's web admin panel, choose your workspace, click on "Variables" and set all the required values:

    enter image description here

    Read here how to obtain the values for those variables.

    I'm a beginner as well on both Terraform and Azure, but I anyway hope this answer will help anybody who stumbles across this issue.

    And also, my solution is described comprehensively in this tutorial.