Pluralith / pluralith-cli

A tool for Terraform state visualisation and automated generation of infrastructure documentation
https://www.pluralith.com
Mozilla Public License 2.0
787 stars 54 forks source link

Error: building AzureRM Client: obtain subscription() 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. #105

Closed teddimitrov closed 1 year ago

teddimitrov commented 1 year ago

Unable to run pluralith graph (linux) - it results in the error below. Terraform plan and apply have no issues.

I am logged into Azure and have default subscription set (screenshot).

Screenshot_302

⠿ Initiating Graph ⇢ Posting Diagram To Pluralith Dashboard

→ Authentication
  ✔ API key is valid, you are authenticated!

→ Plan
  ✘ Couldn't Generate Local Execution Plan

Error: building AzureRM Client: obtain subscription() 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 main.tf line 10, in provider "azurerm":
  10: provider "azurerm" {

running terraform plan failed -> GenerateGraph: RunPlan: exit status 1
DanThePutzer commented 1 year ago

Hm, this is very odd. We also simply execute terraform plan under the hood, so if regular terraform works Pluralith should as well. Will have to do some digging here 👍

teddimitrov commented 1 year ago

Not sure if it helps but pluralith with the same exact terraform config (I copy pasted it) runs fine and generates a graph on Windows 11.

Attaching the output of the

az account tenant list az account list --query "[?isDefault]"

commands.

Pluralith version:

→ CLI Version: 0.2.2 → Graph Module Version: 0.2.1

2023-03-26_10-41 2023-03-26_10-40

DanThePutzer commented 1 year ago

We haven't been able to reproduce this issue so far. Are there any other differences between the linux and Win11 environments and how things are set up that might be relevant/cause the issue?

The error message from your first post is something that does come from Terraform. It isn't a message coming from an error in the CLI itself, but something the CLI gets from Terraform under the hood and pipes right through to the terminal. This makes me suspect there might be some slight difference in the way the Linux and Win11 environments are configured that might cause this. I'm no Azure expert unfortunately. Is there anything like that that comes to mind?

teddimitrov commented 1 year ago

Thank you for still looking at this. I will try to compare environments but they should be identical (I tried targeting a completely different Azure tenant and subscription with the same result).

I also attempted with a really simple terraform config on linux, this time instead of Azure I used AWS. Generated an animated gif for better visualization.

pluralith graph errors out but terraform plan succeeds without any issues.

pluralith

teddimitrov commented 1 year ago

Figured it out. The AWS error about credentials clued me in. Although I had defined the AWS credentials as environment variables, since I was running pluralith graph under a different account context (for whatever reason I had pluralith installed under /usr/local/bin with owner root and not the user) it was not able to use the AWS creds. As soon as I changed to owner /usr/local/bin/Pluralith to the local user it worked like a charm.

Long story short, I am an idiot :) ... That also explains why the Azure error message was complaining that I had not signed into Azure and why you were unable to reproduce it.

Thank you to you and your team for looking at this and apologies that you had to sink so much time into a non-issue because of my oversight.

DanThePutzer commented 1 year ago

@teddimitrov thanks for digging into it that far and reporting back! Glad you got it to work after all :)