0

providers.tf

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

provider "azurerm" {
  features {}
}

terraform version: Terraform v1.1.7

terraform command: terraform plan

CLI Error:

Error: building AzureRM Client: obtain subscription(XXXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXXXX) from Azure CLI: parsing json result from the Azure CLI: waiting for the Azure CLI: exit status 1: ERROR: Please run 'az login' to setup account.

 
   with provider["registry.terraform.io/hashicorp/azurerm"],
   on providers.tf line 10, in provider "azurerm":
   10: provider "azurerm" {

I did run az login and signed into my Azure account.


Question:

I can't find out what I'm doing wrong?

  • does your account have access to that tenant and the subscription? What rights do you have on that subscription? If you run az account list what account are you in? Also why are you putting the tenant and sub values in the provider it’s not really needed to the CLI commands only when your using a service principle. – Jason Apr 06 '22 at 11:06
  • Hi @Jason Yes it does. I've got owner rights. az account list - I'm connected to a bunch of accounts. I can confirm however I'm connected to the correct account with matching sub and tenant id. – Kalin-the-Builder Apr 06 '22 at 11:10
  • So comment out the tenant I’d and subscription part then run all the terraform commands. Terraform Init. Let me know what happens. – Jason Apr 06 '22 at 12:35
  • I've done so. Same result. – Kalin-the-Builder Apr 06 '22 at 13:03
  • Have you considered the solution of [Error waiting for the Azure CLI: exit status 1](https://stackoverflow.com/a/60838569/846163) by executing `az ad signed-in-user show`? To gather more information, you can run Terraform with `TF_LOG=DEBUG` environment variable. – sschmeck Apr 06 '22 at 16:19
  • Have you tried running "az logout" multiple times until you see "There are no active accounts", running "az login", "az account set -s ", then re-running "terraform init" and finally, "terraform plan"? – cdub Apr 06 '22 at 20:04

1 Answers1

0

Tested in my environment getting the same error when i haven't connected with any active account.

enter image description here

As Suggested by cdub is correct , Tried running az logout multiple times until you see There are no active accounts, running az login, az account set -s <your-subscription-name>, then re-running terraform init and finally, terraform plan

#get the current default subscription using show
az account show --output table

enter image description here

RahulKumarShaw
  • 4,192
  • 2
  • 5
  • 11