[英]How do I get part of the name of my Azure resource group and use it to create a new Azure resource name?
我對創作自己的 JSON ARM 模板是全新的。
我試圖通過構建一些快捷方式來積極主動地創建模板。
我的問題是……在 JSON 中,如何從 Azure 資源組名稱中獲取字符以復制到我正在創建的新資源?
這就是我到目前為止所擁有的。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ResourceTypeAbbr": {
"type": "String",
"defaultValue": "STG"
}
},
"variables": {
},
"resources": [
{
//How do I make this part work?//
"name": "[concat(resourceGroup().name)(parameters(ResourceTypeAbbr),('001'))]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "storageaccount1"
},
"properties": {
"accountType": "Standard_LRS"
}
}
],
"outputs": {
}
}
那么我可以使用 resourceGroup().name 並從索引位置 0-16 獲取字符並將其作為我的新 Azure 資源名稱的一部分嗎?
因此,如果我的 Azure 資源組名稱是 CAP-OOO-USWE-PRD-RG-001 ...Id' 希望我的新 Azure 資源在這種情況下獲得名稱 CAP-OOO-USWE-PRD-STG-001。
您可以做的是使用參數和變量的混合來構建名稱,例如:
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ResourceNamePrefix": {
"type": "String",
"value": "CAP-OOO-USWE-PRD"
}
},
"variables": {
"ResourceName": [concat(parameters('ResourceNamePrefix'), '-STG-001')]
},
"resources": [
{
"name": variables('ResourceName'),
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "storageaccount1"
},
"properties": {
"accountType": "Standard_LRS"
}
}
],
"outputs": {
}
或者,您可以使用 concat 方法並附加您想要的任何其他信息。 例如,假設您要使用資源組並圍繞此值構建:
"name": [concat(resourceGroup().name, parameters('ResourceTypeAbbr'), '-001')]
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.