Fix: Azure AKS Cluster - ServicePrincipalNotFound
Fix Azure AKS service principal errors in Terraform. Covers expired credentials, managed identity migration, RBAC configuration, and SP recreation.
Troubleshooting
Fix Azure Cosmos DB global name conflicts in Terraform. Handle unique naming, DNS resolution, and account restoration after soft deletion.
Cosmos DB account names are globally unique across all Azure tenants (they become DNS names). Choose a different name, import the existing account, or wait for a recently deleted account's name to be released.
Error: creating Cosmos DB Account "mydb-prod":
The name 'mydb-prod' is not available. Please choose a different name.Cosmos DB accounts create a {name}.documents.azure.com DNS entry — the name must be unique across all of Azure, not just your subscription.
Azure Cosmos DB supports soft delete. A recently deleted account with the same name may still be in recovery mode (up to 30 days).
A different environment or team is already using this name in the same or different subscription.
resource "random_id" "cosmos" {
byte_length = 4
}
resource "azurerm_cosmosdb_account" "main" {
name = "myapp-${var.environment}-${random_id.cosmos.hex}"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
offer_type = "Standard"
kind = "GlobalDocumentDB"
consistency_policy {
consistency_level = "Session"
}
geo_location {
location = azurerm_resource_group.main.location
failover_priority = 0
}
}# Check if the account exists in your subscription
az cosmosdb show --name mydb-prod --resource-group my-rg
# Import into Terraform
terraform import azurerm_cosmosdb_account.main \
/subscriptions/SUB_ID/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/mydb-prod# If the DNS resolves, the name is taken
nslookup mydb-prod.documents.azure.com
# Check via Azure CLI
az cosmosdb check-name-exists --name mydb-prod# List deleted accounts in your subscription
az cosmosdb restorable-database-account list --query "[?accountName=='mydb-prod']"
# If you own it, you can restore it instead of creating newnslookup {name}.documents.azure.com)az cosmosdb show)random_id to generate unique suffixes automaticallyaz cosmosdb check-name-existsManagedBy = "terraform" for easy discoveryCosmos DB account names are globally unique DNS names. Use random suffixes in your naming convention, check availability before applying, and import existing accounts rather than trying to recreate them.
Fix Azure AKS service principal errors in Terraform. Covers expired credentials, managed identity migration, RBAC configuration, and SP recreation.
Fix Azure Container Registry SKU errors in Terraform. Covers feature availability per tier, geo-replication, private endpoints, and in-place upgrades.
Fix Azure subnet in use errors when modifying VNets in Terraform. Covers resource dependencies, NSG dissociation, delegation conflicts, and force deletion.
Resolve Azure resource group not found errors in Terraform. Fix subscription context, naming issues, and dependency ordering for Azure deployments.