This template run on the same resource group produced the error StorageAccountAlreadyTaken
but it is expected to do incremental deployment, ie. not to create any new resources. How to fix this?
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('prodSaName')]",
"tags": { "displayName": "Storage account" },
"apiVersion": "2016-01-01",
"location": "[parameters('location')]",
"sku": { "name": "Standard_LRS" },
"kind": "Storage",
"properties": {}
},
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[ge.saName(parameters('brn'), parameters('environments')[copyIndex()])]",
"tags": { "displayName": "Storage account" },
"apiVersion": "2016-01-01",
"location": "[parameters('location')]",
"sku": { "name": "Standard_LRS" },
"kind": "Storage",
"copy": {
"name": "EnvStorageAccounts",
"count": "[length(parameters('environments'))]"
},
Run New-AzureRmResourceGroupDeployment @args -debug
with this template and it outputs:
New-AzureRmResourceGroupDeployment : 15:03:38 - Error: Code=StorageAccountAlreadyTaken; Message=The storage account named
UNIQUENAMEOFTHERESOURCE is already taken.
At C:\coding\gameo\gameoemergency\provision.run.ps1:101 char:9
+ New-AzureRmResourceGroupDeployment @args -debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdle
t
PS. Somehow running from VSTS doesn't have this result. That run from local machine. Also there is no such error in Activity Log, strangely.
Update.
If I don't do these selects of a subscription as below but only for RM there are no errors.
Select-AzureRmSubscription -SubscriptionID $Cfg.subscriptionId > $null
# this seems to be the reason of the error, if removed - works:
Select-AzureSubscription -SubscriptionId $Cfg.subscriptionId > $null
# ... in order to run:
exec { Start-AzureWebsiteJob @startArgs | out-null }
Not sure if its a help but I had this issue with APIs prior to 2016-01-01 as there was a known bug. I updated to 2016-12-01 as this was the latest at the time and it worked for me.
Have you tried updating the api to the latest and trying again? The latest is 2018-02-01
A good thing to do before performing a deployment is to validate the resources that if it can be created with the name provided. For EventHub and Storage Account there are built in cmdlets that allows you to check it.
For EventHub
For Storage Account
This will prevent deployment errors by validating before deployment and asking the user to enter a valid name again if the entered one is not present.
This is the result of selecting a subscription twice for Resource Manager cmdlets and using
Select-AzureSubscription
as below:To avoid old cmdlets (before RM) we can use
Invoke-AzureRmResourceAction
. See example at https://stackoverflow.com/a/51712321/511144