Having an issue running any Terraform through Azure CLI Authentication local. I can use Azure CLI to login, set default subscription, and even create a resource group using the CLI syntax fine. When I try to so the same through terraform, I keep getting the same error below:
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: unable to build authorizer for Resource Manager API: could not configure AzureCli Authorizer: could not parse Azure CLI version: unmarshaling the output of Azure CLI: invalid character ‘C’ looking for beginning of value
│
│ with provider[“Terraform Registry”],
│ on main2.tf line 10, in provider “azurerm”:
│ 10: provider “azurerm” {
The error suggests an issue with parsing Azure CLI output in Terraform. Try updating both Terraform and Azure CLI to their latest versions, check for any special characters in your configurations, and ensure your environment variables are set correctly. If the issue persists, consider running Terraform with TF_LOG=DEBUG for more detailed error messages and consult the Terraform community for similar cases.
I found that this happens whenever the Azure CLI notices that there’s an updated version available. Looking at the Terraform logs with TF_LOG=DEBUG, I can see that the command that it is failing on is az version -o=json. When I run this command manually, I see warnings emitted to STDERR stating that a new version of the Azure CLI is available, while the JSON gets emitted to STDOUT.
I think that Terraform sees that STDERR is not empty when the command finishes, so it assumes that the command failed.
Installing the Azure CLI update solves the problem, as the warnings are no longer emitted to STDERR.