gpt4 book ai didi

azure - 在 Azure 资源管理模板中创建 StorageV2 存储帐户

转载 作者:行者123 更新时间:2023-12-01 15:40:50 26 4
gpt4 key购买 nike

我正在尝试创建一个 ARM 模板,其中包括创建存储帐户。

我想创建一个 StorageV2(通用 v2) 帐户,但这似乎失败,因为 schema 中不存在 StorageV2 .

{
"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 唯一允许的值为 StorageBlobStorage,因此在尝试部署上述模板时,会收到以下错误:

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

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

最佳答案

您必须将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

关于azure - 在 Azure 资源管理模板中创建 StorageV2 存储帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50837532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com