【问题标题】:Create a StorageV2 Storage account in an Azure resource management template在 Azure 资源管理模板中创建 StorageV2 存储帐户
【发布时间】:2018-06-13 12:39:30
【问题描述】:

我正在尝试创建一个包含创建存储帐户的 ARM 模板。

我想创建一个StorageV2 (general purpose v2) 帐户,但这似乎失败了,因为StorageV2 在schema 中不存在。

{
  "name": "[variables('xblobstorageName')]",
  "type": "Microsoft.Storage/storageAccounts",
  "location": "[resourceGroup().location]",
  "apiVersion": "2016-01-01",
  "sku": {
    "name": "[parameters('xblobstorageType')]"
  },
  "dependsOn": [],
  "tags": {
    "displayName": "xblobstorage"
  },
  "kind": "StorageV2"
}

kind 的唯一允许值是 Storage 和 BlobStorage,因此在尝试部署上述模板时会收到以下错误:

"error": {
 "code": "AccountPropertyIsInvalid",
 "message": "Account property kind is invalid for the request."
}

是否可以使用 ARM 模板创建 V2 存储帐户?

【问题讨论】:

  • 您可以尝试将 apiVersion 更新为 2018-02-01
  • @MartinBrandl 啊当然!请随意回答,我会接受。
  • 好的,谢谢 - 很高兴我能提供帮助。

标签: azure azure-resource-manager arm-template


【解决方案1】:

您必须更新 apiVersion 为2018-02-01。

我编写了一个 PowerShell 脚本来确定资源提供者的最新 API 版本:

<#
.Synopsis
   Gets the latest API version of a resource provider
.DESCRIPTION
   The following cmdlet returns the latest API version for the specified resource provider.
   You can also include pre-release (preview) versions using the -IncludePreview switch
.EXAMPLE
   Using the Full Parameter Set:
   Get-AzureRmResourceProviderLatestApiVersion -Type Microsoft.Storage/storageAccounts
.EXAMPLE
   Using the Full Parameter Set with the -IncludePreview switch:
   Get-AzureRmResourceProviderLatestApiVersion -Type Microsoft.Storage/storageAccounts -IncludePreview
.EXAMPLE
   Using the ProviderAndType Parameter Set:
   Get-AzureRmResourceProviderLatestApiVersion -ResourceProvider Microsoft.Storage -ResourceType storageAccounts
#>
function Get-AzureRmResourceProviderLatestApiVersion
{
    [CmdletBinding()]
    [Alias()]
    [OutputType([string])]
    Param
    (
        [Parameter(ParameterSetName = 'Full', Mandatory = $true, Position = 0)]
        [string]$Type,

        [Parameter(ParameterSetName = 'ProviderAndType', Mandatory = $true, Position = 0)]
        [string]$ResourceProvider,

        [Parameter(ParameterSetName = 'ProviderAndType', Mandatory = $true, Position = 1)]
        [string]$ResourceType,

        [switch]$IncludePreview
    )

    # retrieving the resource providers is time consuming therefore we store
    # them in a script variable to accelerate subsequent requests.
    if (-not $script:resourceProvider)
    {
        $script:resourceProvider = Get-AzureRmResourceProvider
    }

    if ($PSCmdlet.ParameterSetName -eq 'Full')
    {
        $ResourceProvider = ($Type -replace "\/.*")
        $ResourceType = ($Type -replace ".*?\/(.+)", '$1')
    }

    $provider = $script:resourceProvider |
        Where-Object {
        $_.ProviderNamespace -eq $ResourceProvider -and
        $_.ResourceTypes.ResourceTypeName -eq $ResourceType
    }

    if ($IncludePreview)
    {
        $provider.ResourceTypes.ApiVersions[0]
    }
    else
    {
        $provider.ResourceTypes.ApiVersions | Where-Object {
            $_ -notmatch '-preview'
        } | Select-Object -First 1
    }
}

用法:

Get-AzureRmResourceProviderLatestApiVersion -Type Microsoft.Storage/storageAccounts

并写了一篇关于它的博客文章: Determine latest API version for a resource provider

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2019-01-26
    相关资源
    最近更新 更多