Credential-free authentication for Azure VMs and Container Instances
The Microsoft 365 provider can use Azure managed identities to authenticate to Microsoft 365 services. This authentication method eliminates the need for secrets when Terraform is running on Azure resources.
Environment RequirementThis authentication method only works when Terraform is executing on an Azure Virtual Machine or Container Instance with managed identity enabled. It cannot be used for local development environments unless using Azure CLI as a fallback authentication method.
# Get the principal ID of the managed identityPRINCIPAL_ID=$(az vm identity show --name myVM --resource-group myResourceGroup --query principalId -o tsv)# Make the managed identity an owner of the app registrationaz ad app owner add --id $APP_ID --owner-object-id $PRINCIPAL_ID
provider "microsoft365" { auth_method = "managed_identity" tenant_id = "00000000-0000-0000-0000-000000000000" entra_id_options = { # Specify either client ID or resource ID managed_identity_id = "00000000-0000-0000-0000-000000000000" # Client ID # OR # managed_identity_id = "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP/providers/Microsoft.ManagedIdentity/userAssignedIdentities/IDENTITY_NAME" }}
export M365_TENANT_ID="00000000-0000-0000-0000-000000000000"export M365_AUTH_METHOD="managed_identity"# For user-assigned identity (optional)export M365_MANAGED_IDENTITY_ID="00000000-0000-0000-0000-000000000000"# Or using Azure SDK variableexport AZURE_CLIENT_ID="00000000-0000-0000-0000-000000000000"