gpt4 book ai didi

Azure 二头肌循环存储帐户

转载 作者:行者123 更新时间:2023-12-02 06:38:13 25 4
gpt4 key购买 nike

我仍然不熟悉 azure bicep,但我真的很喜欢 Microsoft 迄今为止所做的事情。

我仍在学习语法和基础知识,但我在这一点上陷入了困境。

我想做的是复制存储帐户的创建并设置一些配置,例如 minimum_tls_version DeleteRetentionPolicy 等。

我正在尝试在循环中创建它,以便我可以使用相同的配置创建多个存储。

到目前为止我已经讲到这一点了。

param storageAccounts array = [
'storage2'
]

resource storage_Accounts 'Microsoft.Storage/storageAccounts@2021-04-01' = [ for storageName in storageAccounts :{
name: [storageName]
location: 'westeurope'
sku: {
name: 'Standard_RAGRS'
tier: 'Standard'
}
kind: 'StorageV2'
properties: {
allowCrossTenantReplication: true
minimumTlsVersion: 'TLS1_2'
allowBlobPublicAccess: false
allowSharedKeyAccess: true
networkAcls: {
bypass: 'AzureServices'
virtualNetworkRules: []
ipRules: []
defaultAction: 'Allow'
}
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
keyType: 'Account'
enabled: true
}
blob: {
keyType: 'Account'
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
accessTier: 'Hot'
}
}]

resource storage_Accounts_name_default 'Microsoft.Storage/storageAccounts/blobServices@2021-04-01' = [ for storageName in storageAccounts :{
parent: storage_Accounts
name: [storageName]
properties: {
changeFeed: {
enabled: false
}
restorePolicy: {
enabled: false
}
containerDeleteRetentionPolicy: {
enabled: true
days: 7
}
cors: {
corsRules: []
}
deleteRetentionPolicy: {
enabled: true
days: 30
}
isVersioningEnabled: true
}
}]

此时,在最后一行 }] 我收到以下错误:

Expected the "}" character at this location.bicep(BCP018)
Expected the "]" character at this location.bicep(BCP018)

我不明白为什么会出现此语法错误,所有 }] 似乎都是正确的。

有人认为我不明白这一点。当我手动创建存储帐户时,软删除等的策略配置是在存储帐户级别进行的。但根据文档,此配置是在单个 blob 存储 中完成的。

有人可以给我解释一下这个和最好的方法吗?

非常感谢您提供的任何帮助

最佳答案

请尝试更改以下代码行:

name: [storageName]

name: storageName

并且您不应该收到编译错误。

我在 Bicep Playground 中尝试了以下操作:

param storageAccounts array = [
'storage2'
]
resource storage_Accounts 'Microsoft.Storage/storageAccounts@2021-04-01' = [ for storageName in storageAccounts :{
name: storageName
location: 'westeurope'
sku: {
name: 'Standard_RAGRS'
tier: 'Standard'
}
kind: 'StorageV2'
properties: {
allowCrossTenantReplication: true
minimumTlsVersion: 'TLS1_2'
allowBlobPublicAccess: false
allowSharedKeyAccess: true
networkAcls: {
bypass: 'AzureServices'
virtualNetworkRules: []
ipRules: []
defaultAction: 'Allow'
}
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
keyType: 'Account'
enabled: true
}
blob: {
keyType: 'Account'
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
accessTier: 'Hot'
}
}]

resource storage_Accounts_name_default 'Microsoft.Storage/storageAccounts/blobServices@2021-04-01' = [ for (storageName, i) in storageAccounts :{
parent: storage_Accounts[i]
name: storageName
properties: {
changeFeed: {
enabled: false
}
restorePolicy: {
enabled: false
}
containerDeleteRetentionPolicy: {
enabled: true
days: 7
}
cors: {
corsRules: []
}
deleteRetentionPolicy: {
enabled: true
days: 30
}
isVersioningEnabled: true
}
}]

并得到以下ARM模板:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.4.1.14562",
"templateHash": "6966745077860153629"
}
},
"parameters": {
"storageAccounts": {
"type": "array",
"defaultValue": [
"storage2"
]
}
},
"functions": [],
"resources": [
{
"copy": {
"name": "storage_Accounts",
"count": "[length(parameters('storageAccounts'))]"
},
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-04-01",
"name": "[parameters('storageAccounts')[copyIndex()]]",
"location": "westeurope",
"sku": {
"name": "Standard_RAGRS",
"tier": "Standard"
},
"kind": "StorageV2",
"properties": {
"allowCrossTenantReplication": true,
"minimumTlsVersion": "TLS1_2",
"allowBlobPublicAccess": false,
"allowSharedKeyAccess": true,
"networkAcls": {
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": [],
"defaultAction": "Allow"
},
"supportsHttpsTrafficOnly": true,
"encryption": {
"services": {
"file": {
"keyType": "Account",
"enabled": true
},
"blob": {
"keyType": "Account",
"enabled": true
}
},
"keySource": "Microsoft.Storage"
},
"accessTier": "Hot"
}
},
{
"copy": {
"name": "storage_Accounts_name_default",
"count": "[length(parameters('storageAccounts'))]"
},
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2021-04-01",
"name": "[format('{0}/{1}', parameters('storageAccounts')[copyIndex()], parameters('storageAccounts')[copyIndex()])]",
"properties": {
"changeFeed": {
"enabled": false
},
"restorePolicy": {
"enabled": false
},
"containerDeleteRetentionPolicy": {
"enabled": true,
"days": 7
},
"cors": {
"corsRules": []
},
"deleteRetentionPolicy": {
"enabled": true,
"days": 30
},
"isVersioningEnabled": true
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts')[copyIndex()])]"
]
}
]
}

关于Azure 二头肌循环存储帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69346453/

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