Terraform cloud needs an Azure access since your plan is running on the cloud.
First, you need to create a service principal for azure
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/SUBSCRIPTION_ID"
See this tutorial: https://developer.hashicorp.com/terraform/tutorials/azure-get-started/azure-build
After service principal is created, you get this in response:
{
"appId": "...", - client_id
"displayName": "...",
"password": "...", - client_secret
"tenant": "..." - tenant_id
}
Then you can provide azure access for terraform using one of these methods:
- Add Workspace variables via terraform cloud GUI. They will be treated as environment variables.
ARM_CLIENT_ID="..."
ARM_CLIENT_SECRET="..."
ARM_SUBSCRIPTION_ID="..."
ARM_TENANT_ID="..."
- Or include them into your .tf file.
provider "azurerm" {
features {}
subscription_id = '...'
client_id = '...'
client_secret = '...'
tenant_id = '...'
}
Hovever it's not a good idea to sotre sensitive data in config.
That's why you may use method #3:
- Declare variables in your .tf file and pass them via command line
provider "azurerm" {
features {}
subscription_id = var.subscription-id
client_id = var.client-id
client_secret = var.secret
tenant_id = var.tenant-id
}
terraform apply -var client-id='...' -var tenant-id='...' -var...
See this answer for details:
https://discuss.hashicorp.com/t/using-the-azure-provider-with-terraform-cloud/18177/2