gpt4 book ai didi

azure - 资源 [] ARM 模板上的 copyIndex()

转载 作者:行者123 更新时间:2023-12-03 02:49:15 25 4
gpt4 key购买 nike

复制 Azure 存储帐户上多个 Blob 容器的索引。

"name": "[concat(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.blobServicesContainerProperties[copyIndex()].blobServicesContainerName,'-',copyIndex())]",

参数.json:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"gcAppEnv": {
"value": {
"subscriptionId": "{SubcrptionID}",
"mmcTenantId": "{TenantID}",
"oPreFix": "gc",
"subEnvironment": "Integration",
"subEnvironmentNicName": "n",
"networkSettings": {
"virtualNetworkResourceGroupName": "{ResourceGroupName}",
"virtualNetworks": "/subscriptions/{SubcrptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{VNet}",
"virtualNetworkName": "{VNet}",
"metadata": {
"description": "Default Settings Created By MGTI.Please Update As Per Your Requirement"
}
}
}
},
"storageAccountObject": {
"value": [
{
"type": "AppAndDb",
"isNew": true,
"storageAccounts_name": "gcappdbstorageacctdev",
"storageAccountSkuObject": {
"name": "Standard_GRS",
"tier": "Standard"
},
"storageAccountTag": {
"responsibleOrg": "Guy Carpenter",
"appName": "GCEdge",
"typeOfStorageNetworkSupport": "AppAndDb"
},
"storageAccountKindOff": "StorageV2",
"storageAccountProperties": {
"NetworkAcls": {
"Bypass": "AzureServices",
"VNetSubNetRule": [
{
"subnets": "/subscriptions/{SubcrptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{VNet}/subnets/{SubNet-APP}",
"subnetsaction": "Allow",
"subnetsstate": "Succeeded"
},
{
"subnets": "/subscriptions/{SubcrptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{VNet}/subnets/{SubNet-DB}",
"subnetsaction": "Allow",
"subnetsstate": "Succeeded"
}
],
"IPRules": [
{
"value": "205.156.84.229/32"
},
{
"value": "205.156.136.229/32"
},
{
"value": "13.86.33.223"
}
],
"DefaultAction": "Deny"
},
"SupportsHttpsTrafficOnly": true,
"AccessTier": "Hot"
},
"blobServicesProperties": {
"blobServicesName": "default",
"corsProperties": {
"corsRules": [
{
"allowedOrigins": [
"*"
],
"allowedMethods": [
"OPTIONS",
"GET",
"HEAD"
],
"maxAgeInSeconds": 60,
"exposedHeaders": [
"Access-Control-Allow-Credentials"
],
"allowedHeaders": [
"Content-Type",
"Authorization",
"x-timestamp"
]
}
]
},
"BlobServiceSoftDeleteRetentionPolicy": {
"enabled": false,
"days": 365
},
"BlobServiceSoftAutomaticSnapshotPolicy": false,
"blobServicesContainerProperties": [
{
"blobServicesContainerName": "gc-app-container-blob",
"PublicAccess": "Container",
"blobServicesContainerImmutabilityProperties": {
"immutabilityPeriodSinceCreationInDays": 10
}
},
{
"blobServicesContainerName": "gc-db-container-blob",
"PublicAccess": "Blob",
"blobServicesContainerImmutabilityProperties": {
"immutabilityPeriodSinceCreationInDays": 10
}
},
{
"blobServicesContainerName": "gc-web-container-blob",
"PublicAccess": "None",
"blobServicesContainerImmutabilityProperties": {
"immutabilityPeriodSinceCreationInDays": 10
}
}
]
}
}
]
}
}
}

部署.json:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"gcAppEnv": {
"type": "Object"
},
"storageAccountObject": {
"type": "Array"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"copy": {
"name": "storageAccountObjectCopy",
"count": "[length(parameters('storageAccountObject'))]",
"mode": "serial"
},
"name": "[parameters('storageAccountObject')[copyIndex()].storageAccounts_name]",
"location": "[resourceGroup().location]",
"tags": "[parameters('storageAccountObject')[copyIndex()].storageAccountTag]",
"sku": "[parameters('storageAccountObject')[copyIndex()].storageAccountSkuObject]",
"kind": "[parameters('storageAccountObject')[copyIndex()].storageAccountKindOff]",
"properties": {
"networkAcls": {
"bypass": "[parameters('storageAccountObject')[copyIndex()].storageAccountProperties.NetworkAcls.Bypass]",
"ipRules": [],
"copy": [
{
"name": "virtualNetworkRules",
"count": "[length(parameters('storageAccountObject')[copyIndex()].storageAccountProperties.NetworkAcls.VNetSubNetRule)]",
"input": {
"id": "[parameters('storageAccountObject')[copyIndex()].storageAccountProperties.NetworkAcls.VNetSubNetRule[copyIndex('virtualNetworkRules')].subnets]",
"action": "[parameters('storageAccountObject')[copyIndex()].storageAccountProperties.NetworkAcls.VNetSubNetRule[copyIndex('virtualNetworkRules')].subnetsaction]",
"state": "[parameters('storageAccountObject')[copyIndex()].storageAccountProperties.NetworkAcls.VNetSubNetRule[copyIndex('virtualNetworkRules')].subnetsstate]"
}
}
],
"defaultAction": "[parameters('storageAccountObject')[copyIndex()].storageAccountProperties.NetworkAcls.DefaultAction]"
},
"supportsHttpsTrafficOnly": true,
"encryption": {
"services": {
"file": {
"enabled": true
},
"blob": {
"enabled": true
}
},
"keySource": "Microsoft.Storage"
},
"accessTier": "[parameters('storageAccountObject')[copyIndex()].storageAccountProperties.AccessTier]"
},
"resources": [
{
"type": "blobServices",
"apiVersion": "2019-04-01",
"name": "[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.blobServicesName]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountObject')[copyIndex()].storageAccounts_name)]"
],
"properties": {
"cors": {
"copy": [
{
"name": "corsRules",
"count": "[length(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules)]",
"input": {
"copy": [
{
"name": "allowedOrigins",
"count": "[length(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].allowedOrigins)]",
"input": [
"[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].allowedOrigins[copyIndex()]]"
]
},
{
"name": "allowedMethods",
"count": "[length(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].allowedMethods)]",
"input": [
"[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].allowedMethods[copyIndex()]]"
]
},
{
"name": "exposedHeaders",
"count": "[length(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].exposedHeaders)]",
"input": [
"[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].exposedHeaders[copyIndex()]]"
]
},
{
"name": "allowedHeaders",
"count": "[length(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].allowedHeaders)]",
"input": [
"[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].allowedHeaders[copyIndex()]]"
]
}
],
"maxAgeInSeconds": "[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.corsProperties.corsRules[copyIndex()].maxAgeInSeconds]"
}
}
]
},
"deleteRetentionPolicy": {
"enabled": "[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.BlobServiceSoftDeleteRetentionPolicy.enabled]",
"days": "[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.BlobServiceSoftDeleteRetentionPolicy.days]"
},
"automaticSnapshotPolicyEnabled": "[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.BlobServiceSoftAutomaticSnapshotPolicy]"
},
"resources": [
{
"type": "containers",
"name": "[concat(parameters('storageAccountObject')[copyIndex()].blobServicesProperties.blobServicesContainerProperties[copyIndex()].blobServicesContainerName,'-',copyIndex())]",
"apiVersion": "2019-04-01",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/',parameters('storageAccountObject')[copyIndex()].storageAccounts_name,'/blobServices/default')]"
],
"properties": {
"publicAccess": "[parameters('storageAccountObject')[copyIndex()].blobServicesProperties.blobServicesContainerProperties[copyIndex()].PublicAccess]"
}
}
]
}
]
}
]
}
"blobServicesContainerProperties": [
{
"blobServicesContainerName": "gc-app-container-blob",
"PublicAccess": "Container",
"blobServicesContainerImmutabilityProperties": {
"immutabilityPeriodSinceCreationInDays": 10
}
},
{
"blobServicesContainerName": "gc-db-container-blob",
"PublicAccess": "Blob",
"blobServicesContainerImmutabilityProperties": {
"immutabilityPeriodSinceCreationInDays": 10
}
},
{
"blobServicesContainerName": "gc-web-container-blob",
"PublicAccess": "None",
"blobServicesContainerImmutabilityProperties": {
"immutabilityPeriodSinceCreationInDays": 10
}
}
]

没有异常,但是创建资源失败。它只创建一个容器而不是 3 个

最佳答案

You can't use a copy loop for a child resource. To create more than one instance of a resource that you typically define as nested within another resource, you must instead create that resource as a top-level resource. You define the relationship with the parent resource through the type and name properties.

正在阅读:https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#iteration-for-a-child-resource

只需创建一个单独的容器资源:

{
"name": "[concat(parameters('storageAccountObject')[copyIndex()].storageAccounts_name, '/default/', parameters('containerName'))]",
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2018-07-01",
"dependsOn": [
"[parameters('storageAccountName')]"
]
}

关于azure - 资源 [] ARM 模板上的 copyIndex(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56973020/

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