How It Works
This authentication method leverages the Azure CLI authentication, which stores tokens in a local credential cache:Benefits
- Eliminates the need to create and manage separate app registrations
- Removes the need to handle sensitive client secrets or certificates
- Uses the same authentication context as your other Azure CLI operations
- Supports automatic token renewal when tokens expire
Prerequisites
- Azure CLI (az) installed
- Successfully authenticated with
az login - A Microsoft Entra ID tenant
Use Cases
Local Development
Quick setup for development environments
Service Account
Run Terraform with a dedicated service account logged into Azure CLI
Prototyping
Rapidly test Terraform configurations without overhead
Cross-service Dev
Maintain consistent auth when working with Azure and M365 resources
Setup
Install Azure CLI
Follow the Azure CLI installation guide for your operating system. Verify installation:Authenticate
No additional app registration setup is required for this authentication method.
Provider Configuration
- Environment Variables (Recommended)
- Terraform Configuration
VS Code Integration
Create a.vscode/tasks.json file to streamline your workflow:
- Press
Ctrl+Shift+P(orCmd+Shift+Pon macOS) - Type “Tasks: Run Task”
- Select your desired task
Switching Between Auth Methods
Create a shell script to easily switch profiles:Limitations
Security Considerations
- Azure CLI stores tokens in a local credential cache, which is encrypted
- Actions performed will be attributable to the logged-in identity
- Ensure your user account follows the principle of least privilege
- For shared or public computers, be cautious of leaving authenticated sessions active
- Log out when finished:
az logout - For production environments, use dedicated service principal authentication
Troubleshooting
Azure CLI not found
Azure CLI not found
Error:
Failed to create credential strategy: azure cli not found in PATHEnsure that az is installed and available in your system PATH. Verify with:Authentication expired
Authentication expired
Error:
Failed to get token: azure cli not authenticatedRun az login to authenticate before using Terraform.Multiple tenant scenarios
Multiple tenant scenarios
Error:
Failed to get token: tenant ID mismatchIf you work with multiple tenants, authenticate to the specific tenant:Permission errors
Permission errors
Error:
Insufficient privileges to complete the operationThe authenticated identity must have the necessary permissions for Microsoft Graph operations. Check your user permissions in the Microsoft Entra admin center.