增量部署时出现StorageAccountAlreadyTaken错误



在同一资源组上运行的此模板产生错误StorageAccountAlreadyTaken,但它应该进行增量部署,即不创建任何新资源。如何解决此问题?

{
"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'))]"
},

用这个模板运行New-AzureRmResourceGroupDeployment @args -debug,它输出:

New-AzureRmResourceGroupDeployment : 15:03:38 - Error: Code=StorageAccountAlreadyTaken; Message=The storage account named
UNIQUENAMEOFTHERESOURCE is already taken.
At C:codinggameogameoemergencyprovision.run.ps1:101 char:9
+         New-AzureRmResourceGroupDeployment @args -debug
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdle
t

PS。不知怎么的,从VSTS运行并没有这个结果。从本地机器运行。奇怪的是,活动日志中也没有这样的错误。

更新。

如果我不按以下方式选择订阅,但仅针对RM,则不会出现错误。

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 }

不确定这是否有帮助,但我在2016-01-01之前就遇到了API问题,因为有一个已知的错误。我更新到2016-12-01,因为这是当时最新的,它对我有效。

您是否尝试将api更新为最新版本并重试?最近的是2018-02-01

这是为Resource Manager cmdlet选择两次订阅并使用Select-AzureSubscription的结果,如下所示:

Select-AzureRmSubscription -SubscriptionID $Cfg.subscriptionId > $null
# this seems to be the reason of the error, if removed - works:
# Select-AzureSubscription -SubscriptionId $Cfg.subscriptionId > $null

为了避免旧的cmdlet(在RM之前(,我们可以使用Invoke-AzureRmResourceAction。请参阅上的示例https://stackoverflow.com/a/51712321/511144

在执行部署之前,要做的一件好事是验证资源是否可以使用提供的名称创建。对于EventHub和存储帐户,有内置的cmdlet允许您进行检查。

对于EventHub

Test-AzureRmEventHubName -Namespace $eventHubNamespaceName | Select-Object -ExpandProperty NameAvailable
if ($availability -eq $true) {
Write-Host -ForegroundColor Green `r`n"Entered Event Hub Namespace name is available"

对于存储帐户

while ($true) {
Write-Host -ForegroundColor Yellow `r`n"Enter Storage account name (Press Enter for default) : " -NoNewline
$storageAccountName = Read-Host
if ([string]::IsNullOrEmpty($storageAccountName)) {
$storageAccountName = $defaultstorageAccountName
}
Write-Host -ForegroundColor Yellow `r`n"Checking whether the entered name for Storage account is available"
$availability = Get-AzureRmStorageAccountNameAvailability -Name $storageAccountName | Select-Object -ExpandProperty NameAvailable
if ($availability -eq $true ) {
Write-Host -ForegroundColor Green `r`n"Entered Storage account name is available"
break
}
Write-Host `r`n"Enter valid Storage account name"
}

这将通过在部署前进行验证并要求用户在输入的名称不存在时再次输入有效名称来防止部署错误。

相关内容

  • 没有找到相关文章

最新更新