ARM Deployment Failure - StorageAccountAlreadyTaken
Cmdlet(s)
PowerShell Version
Name Value
---- -----
PSVersion 5.1.14393.1715
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1715
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Module Version
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 5.0.1 AzureRM
OS Version
Instructions: to get OS version, type $PSversionTable and look for value associated with BuildVersion
Description
We are redeploying an existing AppService depending on a storage account template:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string"
},
"environmentName": {
"type": "string"
},
"appInsightsInstrumentationKey": {
"type": "string"
},
"appServiceRenewalManagerWebApi": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"appServiceResourceGroup": {
"type": "string"
},
"appServicePlanId": {
"type": "string"
},
"appServiceRenewalManagerWebApiHostName": {
"type": "string"
},
"appServiceSSLThumbprint": {
"type": "string"
},
"hostnamesRenewalManagerWebApi": {
"type": "array"
},
"enabledHostnamesRenewalManagerWebApi": {
"type": "array"
},
"allowedOrigins": {
"type": "array"
},
"websiteLoadCertificates": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"name": "[parameters('storageAccountName')]",
"apiVersion": "2017-06-01",
"location": "[resourceGroup().location]",
"tags": {},
"scale": null,
"properties": {
"encryption": {
"keySource": "Microsoft.Storage",
"services": {
"blob": {
"enabled": true
}
}
},
"networkAcls": {
"bypass": "AzureServices",
"defaultAction": "Allow",
"ipRules": [],
"virtualNetworkRules": []
},
"supportsHttpsTrafficOnly": false
},
"dependsOn": []
},
{
"comments": "Generalized from resource: '/subscriptions/91819a1c-c7d3-4b89-bc9f-39f85bff4666/resourceGroups/nltapp0040rgp-test-risk-RenewalManager/providers/Microsoft.Web/sites/nltapp0040api-test-risk-RenewalManager-web-api'.",
"type": "Microsoft.Web/sites",
"name": "[parameters('appServiceRenewalManagerWebApi')]",
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"tags": {},
"properties": {
"name": "[parameters('appServiceRenewalManagerWebApi')]",
"hostNames": "[parameters('hostnamesRenewalManagerWebApi')]",
"enabledHostNames": "[parameters('enabledHostnamesRenewalManagerWebApi')]",
"hostNameSslStates": [
{
"name": "[concat(parameters('appServiceRenewalManagerWebApi'),'.azurewebsites.net')]",
"sslState": 0,
"thumbprint": null,
"ipBasedSslState": 0
},
{
"name": "[concat(parameters('appServiceRenewalManagerWebApi'),'.scm.azurewebsites.net')]",
"sslState": 0,
"thumbprint": null,
"ipBasedSslState": 0
}
],
"serverFarmId": "[resourceId(parameters('subscriptionId'), parameters('appServiceResourceGroup'), 'Microsoft.Web/serverfarms', parameters('appServicePlanId'))]",
"siteConfig": {
"AlwaysOn": true,
"appSettings": [
{
"name": "ASPNETCORE_ENVIRONMENT",
"value": "[parameters('environmentName')]"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[parameters('appInsightsInstrumentationKey')]"
},
{
"name": "WEBSITE_LOAD_CERTIFICATES",
"value": "[parameters('websiteLoadCertificates')]"
},
{
"name": "Pyra:AzureAd:Authentication:CodeName",
"value": "RENEWALMANAGERAPIPUB"
},
{
"name": "Pyra:AzureAd:Authentication:ApplicationId",
"value": "[parameters('pyraAzureAdAuthApplicationId')]"
},
{
"name": "Pyra:AzureAd:Authentication:CertificateThumbprint",
"value": "[parameters('pyraAzureAdCertificateThumbprint')]"
},
{
"name": "Pyra:AzureAd:Authentication:CertificateSource",
"value": "[parameters('pyraAzureAdAuthCertificateSource')]"
}
],
"cors": {
"allowedOrigins": "[parameters('allowedOrigins')]"
}
}
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "RedirectHttpToHttps",
"type": "siteextensions",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('appServiceRenewalManagerWebApi'))]"
],
"properties": {}
},
{
"apiVersion": "2015-08-01",
"name": "staging",
"type": "slots",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('appServiceRenewalManagerWebApi'))]"
],
"properties": {
"serverFarmId": "[resourceId(parameters('subscriptionId'), parameters('appServiceResourceGroup'), 'Microsoft.Web/serverfarms', parameters('appServicePlanId'))]",
"siteConfig": {
"AlwaysOn": true,
"appSettings": [
{
"name": "ASPNETCORE_ENVIRONMENT",
"value": "[parameters('environmentName')]"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[parameters('appInsightsInstrumentationKey')]"
},
{
"name": "WEBSITE_LOAD_CERTIFICATES",
"value": "[parameters('websiteLoadCertificates')]"
}
],
"cors": {
"allowedOrigins": "[parameters('allowedOrigins')]"
}
}
}
}
],
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
]
},
{
"name": "[concat(parameters('appServiceRenewalManagerWebApi'), '/', parameters('appServiceRenewalManagerWebApiHostName'))]",
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites/hostNameBindings",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('appServiceRenewalManagerWebApi'))]"
],
"properties": {
"siteName": "[concat(parameters('appServiceRenewalManagerWebApiHostName'))]",
"domainId": null,
"hostNameType": "Verified",
"sslState": "SniEnabled",
"thumbprint": "[parameters('appServiceSSLThumbprint')]"
}
}
]
}
During deployment, we are using the New-AzureRmResourceGroupDeployment commandlet. The template appears not to pass the validation stage, with a StorageAccountAlreadyTaken error.
Debug Output
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id : 6a4df36e-44dd-4552-9175-cdd607e96477
x-ms-correlation-request-id : 6a4df36e-44dd-4552-9175-cdd607e96477
x-ms-routing-request-id : UKSOUTH:20171207T155737Z:6a4df36e-44dd-4552-9175-cdd607e96477
Strict-Transport-Security : max-age=31536000; includeSubDomains
Cache-Control : no-cache
Date : Thu, 07 Dec 2017 15:57:36 GMT
Body:
{
"error": {
"code": "InvalidTemplateDeployment",
"message": "The template deployment 'renewal-manager-test' is not valid according to the validation procedure. The
tracking id is '6a4df36e-44dd-4552-9175-cdd607e96477'. See inner errors for details. Please see
https://aka.ms/arm-deploy for usage details.",
"details": [
{
"code": "PreflightValidationCheckFailed",
"message": "Preflight validation failed. Please refer to the details for the specific errors.",
"details": [
{
"code": "StorageAccountAlreadyTaken",
"target": "nltapp0137sda",
"message": "The storage account named nltapp0137sda is already taken."
}
]
}
]
}
}
New-AzureRmResourceGroupDeployment : 16:57:37 - Error: Code=InvalidTemplateDeployment; Message=The template deployment
'renewal-manager-test' is not valid according to the validation procedure. The tracking id is '6a4df36e-44dd-4552-9175-
cdd607e96477'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details.
At C:\Checkout\ops-arm-templates\area404\Deploy-Template.ps1:76 char:5
+ New-AzureRmResourceGroupDeployment -Name $parameters.Get_Item("De ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDep
loymentCmdlet
Please advise - why is it not possible to redeploy a template with a storage account inside? The storage account is not being modified in any way, so in an incremental delployment, the ARM engine should ignore the redeployment of this resource. Correct?
@vivsriaus Can you take a look?
@ravbhatnagar to comment since this is the expected behavior per ARM pre flight validation.
@ravbhatnagar @Tiano2017 would you mind taking a look?
You can vote on it here:
https://feedback.azure.com/forums/217298-storage/suggestions/37981573-don-t-throw-storageaccountalreadytaken-for-incre
Its 2020 and I'm struggling with this same issue. I have got gotten so far with automating my arm..hopefully I don't have to go to terraform but is there an eta? Its been two years and doesn't seem to have gottn much traction based on this thread.
One option in meantime I have found to be helpful is to use conditional deployments ie create a parameter for exitisting or new storage accounts inside the rresource json
"condition": "[equals(parameters('newOrExisting'),'new')]", https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/conditional-resource-deployment
Thanks all.
I tried to deploy exactly the same storage account payload as in this issue, but I couldn't repro it. @raisingcode how do you repro this issue?
@mmisztal1980 can you help provide more details? I couldn't repro the issue.
@Tiano2017 Just deploy it twice with incremental. Don't delete anything.
@Tiano2017 I ran my arm deployment again, I could not generate. I can share my arm with you if that will help.
@Tiano2017 I ran my arm deployment again, I could not generate. I can share my arm with you if that will help.
@raisingcode sure. you can attach your template in your reply. Please mask out the sensitive information.
Closing the issue as I'm unable to get a repro. Please open a new issue with repro steps, if you see this happens.