Azure Storage Account names must be 3-24 characters using only lowercase letters and numbers, and must be globally unique. This error occurs when your Terraform configuration violates these naming rules.
Azure Storage Accounts require globally unique names that follow strict naming conventions. The AccountNameInvalid error means your storage account name violates these requirements. The name is used as part of the DNS endpoint (e.g., mystorageaccount.blob.core.windows.net), so Azure validates it before creating the resource. Common violations include uppercase letters, hyphens, underscores, special characters, or names shorter than 3 characters or longer than 24 characters.
Check your Terraform apply output carefully. The error message should specify which rule was violated. Look for clues about character restrictions or length limits.
Update your Terraform configuration to remove uppercase letters. Azure Storage Account names must be entirely lowercase.
# Incorrect
resource "azurerm_storage_account" "example" {
name = "MyStorageAccount" # Invalid: contains uppercase
}
# Correct
resource "azurerm_storage_account" "example" {
name = "mystorageaccount" # Valid: all lowercase
}Storage account names cannot contain hyphens, underscores, or special characters. Update your name to use only alphanumeric characters.
# Incorrect
resource "azurerm_storage_account" "example" {
name = "my-storage-account" # Invalid: contains hyphens
name = "my_storage_account" # Invalid: contains underscores
}
# Correct
resource "azurerm_storage_account" "example" {
name = "mystorageaccount" # Valid: only lowercase letters
}Ensure your storage account name meets the length requirement. Count the characters carefully.
# Incorrect
resource "azurerm_storage_account" "example" {
name = "ab" # Invalid: only 2 characters (minimum is 3)
name = "mystorageaccount12345678901" # Invalid: 32 characters (maximum is 24)
}
# Correct
resource "azurerm_storage_account" "example" {
name = "mystorageaccount" # Valid: 15 characters
}Since storage account names must be globally unique across all of Azure, use the uniqueString() function to generate a name that includes a hash based on your resource group.
resource "azurerm_storage_account" "example" {
name = "st${substr(lower(replace(azurerm_resource_group.example.name, "-", "")), 0, 11)}${lower(uniqueString(azurerm_resource_group.example.id))}"
# Results in: st{prefix}{uniquehash} - all lowercase, no special chars
}If using a variable for the storage account name, ensure it's not quoted as a string literal. Variables should be referenced without quotes.
# Incorrect
resource "azurerm_storage_account" "example" {
name = "var.storage_account_name" # Invalid: treats as literal string
}
# Correct
resource "azurerm_storage_account" "example" {
name = var.storage_account_name # Valid: references the variable
}Storage account names directly form part of the Azure Storage endpoint URL (e.g., https://accountname.blob.core.windows.net/). This is why names must be globally unique and follow strict naming rules - they must be valid DNS hostnames. If you need to rename a storage account after creation, you cannot do this in-place. You must create a new storage account with the correct name and migrate your data. Always validate storage account names during planning to catch naming issues early in your Terraform workflow. Consider using naming conventions and prefixes (like 'st' for storage, 'stg' for staging) to ensure consistency across your infrastructure.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform