I am trying to provision Azure resources using Terraform, but I’m encountering an authentication issue that I can’t seem to resolve. I’ve followed the Azure documentation to set up my credentials, and I’ve double-checked my subscription ID, client ID, client secret, and tenant ID. However, I keep getting the following error message:
Error: Authentication failed, please check your credentials for the
AzureRM providerError: Error building AzureRM Client: InvalidConfig: Error parsing
json result from the Azure CLI: Error loading the JSON file
‘C:UsersUser.azureaccessTokens.json’: open
C:UsersUser.azureaccessTokens.json: The system cannot find the
file specified.
main.tf
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "my-resource-group"
location = "East US"
}
variable.tf
variable "client_id" {}
variable "client_secret" {}
variable "tenant_id" {}
variable "subscription_id" {}
I’m running Terraform version 0.15.4. My operating system is Windows 10. I’ve ensured that my Azure CLI is updated to the latest version as well.
Can anyone help me understand why I’m encountering this authentication error and how to resolve it? I’ve spent a lot of time double-checking my credentials and searching for solutions, but nothing seems to work.
2
Answers
Terraform version 0.15.4
really, first I would highly recommend you to upgrade the Terraform version to the latest if possible or at least>=1.3
.It seems that you are having authentication issues.
Summary of the Guide
If you have az cli installed on your machine, please use the below command if you are able to authenticate yourself via az cli, it should automatically work for Terraform.
You could also use environment variables if
az cli
is a blocker.I would not recommend personally configuring your provider with secrets but you can do that as well if you are fine with that.
Normally, I would create a azure.environment.sh file within my terraform repo which has the line:
Before running my terraform, I will source the file, while I am in my terraform folder/repo: