增量部署时StorageAccountAlreadyTaken错误 [英] StorageAccountAlreadyTaken error at incremental deployment

查看:144
本文介绍了增量部署时StorageAccountAlreadyTaken错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在同一资源组上运行的此模板产生了错误StorageAccountAlreadyTaken,但预期将进行增量部署.不创建任何新资源.该如何解决?

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

使用此模板运行New-AzureRmResourceGroupDeployment @args -debug,并输出:

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.以某种方式从VSTS运行不会产生此结果.从本地计算机运行.奇怪的是,活动日志中也没有这样的错误.

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.

更新.

如果我不按以下方式选择订阅,但仅针对RM,则没有错误.

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 }

推荐答案

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

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.

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"
    }

这将通过在部署之前进行验证并防止用户输入有效的名称(如果不存在所输入的名称)来防止部署错误.

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.

这篇关于增量部署时StorageAccountAlreadyTaken错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆