2017-06-14 101 views
1

我想用戶拷貝循環功能在Azure的ARM模板下面Azure的ARM模板的資源塊我與數組作爲參數

{ 
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
"contentVersion": "1.0.0.0", 
"parameters": { 
"resourceGroupsName": { 
    "type": "string" 
}, 
"clusterName": { 
    "type": "string" 
}, 
"clusterLoginUserName": { 
    "type": "string" 
}, 
"clusterLoginPassword": { 
    "type": "securestring" 
}, 
"sshUserName": { 
    "type": "string" 
}, 
"sshPassword": { 
    "type": "securestring" 
}, 
"location": { 
    "type": "string" 
}, 
"clusterType": { 
    "type": "string", 
    "defaultValue": "spark" 
}, 
"clusterVersion": { 
    "type": "string" 
}, 
"sparkVersion": { 
    "type": "string" 
}, 
"clusterWorkerNodeCount": { 
    "type": "int", 
    "defaultValue": 2 
}, 
"virtualNetworkName": { 
    "type": "string" 
}, 
"subnetName": { 
    "type": "string" 
}, 
"vnetResourceGroupName": { 
    "type": "string" 
}, 
"clusterStorageAccountName": { 
    "type": "string" 
}, 
"dataStorageAccountName": { 
    "type": "string" 
}, 
"clusterStorageContainerName": { 
    "type": "string" 
}, 
"externalStorageAccounts": { 
    "type": "array" 
}, 
"storageAccountResourceGroupName": { 
    "type": "string" 
}, 
"headNodeSize": { 
    "type": "string" 
}, 
"workerNodeSize": { 
    "type": "string" 
}, 
"edgeNodeSize": { 
    "type": "string" 
}, 
"dbServerName": { 
    "type": "string" 
}, 
"hivedbName": { 
    "type": "string", 
    "metadata": { "description": "Name of the database where metadata will be stored" } 
}, 
"ooziedbName": { 
    "type": "string", 
    "metadata": { "description": "Name of the database where metadata will be stored" } 
}, 
"dbuser": { 
    "type": "string", 
    "metadata": { "description": "User Name of the database server where metadata will be stored" } 
}, 
"dbpassword": { 
    "type": "securestring", 
    "metadata": { "description": "Password of the database where metadata will be stored" } 
}, 
"collation": { 
    "type": "string", 
    "defaultValue": "SQL_Latin1_General_CP1_CI_AS", 
    "metadata": { 
    "description": "The database collation for governing the proper use of characters." 
    } 
}, 
"edition": { 
    "type": "string", 
    "defaultValue": "Standard", 
    "allowedValues": [ 
    "Basic", 
    "Standard", 
    "Premium" 
    ], 
    "metadata": { 
    "description": "The type of database to create." 
    } 
}, 
"maxSizeBytes": { 
    "type": "string", 
    "defaultValue": "1073741824", 
    "metadata": { 
    "description": "The maximum size, in bytes, for the database" 
    } 
}, 
"requestedServiceObjectiveName": { 
    "type": "string", 
    "defaultValue": "S1", 
    "allowedValues": [ 
    "Basic", 
    "S0", 
    "S1", 
    "S2", 
    "P1", 
    "P2", 
    "P3" 
    ], 
    "metadata": { 
    "description": "Describes the performance level for Edition" 
    } 
}, 
"omsWorkspace": { 
    "type": "string", 
    "metadata": { 
    "description": "OMS Workspace ID" 
    } 
}, 
"omsResourceGroup": { 
    "type": "string", 
    "metadata": { 
    "description": "OMS Workspace Key" 
    } 
}, 
"Environment": { 
    "type": "string", 
    "allowedValues": [ 
    "dev", 
    "qa", 
    "stage", 
    "prod" 
    ], 
    "metadata": { 
    "description": "The environment that the resources will be tagged with (dev, test, stage, prod)." 
    } 
}, 
"ProjectName": { 
    "type": "string", 
    "metadata": { 
    "description": "A name for the project or company that this template is being provisioned for (used for tagging)." 
    } 
} 
}, 
"variables": { 
"dbServerName": "[concat(parameters('dbServerName'),'.database.windows.net')]", 
"defaultApiVersion": "2015-05-01-preview", 
"clusterApiVersion": "2015-03-01-preview", 
"vnetID": "[concat(resourceId(parameters('vnetResourceGroupName'),'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName')))]", 
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/', parameters('subnetName'))]", 
"applicationName": "[concat('edgenode')]" 
}, 
"resources": [ 
    { 
    "name": "[parameters('clusterName')]", 
    "type": "Microsoft.HDInsight/clusters", 
    "location": "[resourceGroup().location]", 
    "apiVersion": "[variables('clusterApiVersion')]", 
    "dependsOn": [], 
    "tags": { 
     "Environment": "[parameters('Environment')]", 
     "Project": "[parameters('ProjectName')]" 
    }, 
    "properties": { 
     "clusterVersion": "[parameters('clusterVersion')]", 
     "osType": "Linux", 
     "tier": "standard", 
     "clusterDefinition": { 
     "kind": "[parameters('clusterType')]", 
     "componentVersion": { 
       "Spark": "[parameters('sparkVersion')]" 
     }, 
     "configurations": { 
      "gateway": { 
      "restAuthCredential.isEnabled": true, 
      "restAuthCredential.username": "[parameters('clusterLoginUserName')]", 
      "restAuthCredential.password": "[parameters('clusterLoginPassword')]" 
      }, 
      "core-site": { 
      }, 
      "hive-site": { 
      "javax.jdo.option.ConnectionDriverName": "com.microsoft.sqlserver.jdbc.SQLServerDriver", 
      "javax.jdo.option.ConnectionURL": "[concat('jdbc:sqlserver://', variables('dbServerName'),';database=', parameters('hivedbName'),';encrypt=true;trustServerCertificate=true;create=false;loginTimeout=300')]", 
      "javax.jdo.option.ConnectionUserName": "[parameters('dbuser')]", 
      "javax.jdo.option.ConnectionPassword": "[parameters('dbpassword')]" 
      }, 
      "hive-env": { 
      "hive_database": "Existing MSSQL Server database with SQL authentication", 
      "hive_database_name": "[parameters('hivedbName')]", 
      "hive_database_type": "mssql", 
      "hive_existing_mssql_server_database": "[parameters('hivedbName')]", 
      "hive_existing_mssql_server_host": "[variables('dbServerName')]", 
      "hive_hostname": "[variables('dbServerName')]" 
      }, 
      "oozie-site": { 
      "oozie.service.JPAService.jdbc.driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver", 
      "oozie.service.JPAService.jdbc.url": "[concat('jdbc:sqlserver://', variables('dbServerName'),';database=', parameters('ooziedbName'),';encrypt=true;trustServerCertificate=true;create=false;loginTimeout=300')]", 
      "oozie.service.JPAService.jdbc.username": "[parameters('dbuser')]", 
      "oozie.service.JPAService.jdbc.password": "[parameters('dbpassword')]", 
      "oozie.db.schema.name": "oozie" 
      }, 
      "oozie-env": { 
      "oozie_database": "Existing MSSQL Server database with SQL authentication", 
      "oozie_database_name": "[parameters('ooziedbName')]", 
      "oozie_database_type": "mssql", 
      "oozie_existing_mssql_server_database": "[parameters('ooziedbName')]", 
      "oozie_existing_mssql_server_host": "[variables('dbServerName')]", 
      "oozie_hostname": "[variables('dbServerName')]" 
      } 
     } 
     }, 
     "storageProfile": { 
     "copy": [ 
      { 
       "name": "storageaccounts", 
       "count": "[length(parameters('externalStorageAccounts'))]", 
       "input": { 
        "name": "[concat(parameters('externalStorageAccounts')[copyIndex('storageaccounts')].name,'.blob.core.windows.net')]", 
        "isDefault": "[parameters('externalStorageAccounts')[copyIndex('storageaccounts')].isDefault]", 
        "container": "[parameters('externalStorageAccounts')[copyIndex('storageaccounts')].container]", 
        "key": "[listKeys(resourceId(parameters('externalStorageAccounts')[copyIndex('storageaccounts')].resourceGroupsName,'Microsoft.Storage/storageAccounts', parameters('externalStorageAccounts')[copyIndex('storageaccounts')].name), variables('defaultApiVersion')).key1]", 
       } 
      } 
     ] 
     }, 
    "computeProfile": { 
     "roles": [ 
      { 
      "name": "headnode", 
      "targetInstanceCount": "2", 
      "hardwareProfile": { 
       "vmSize": "[parameters('headNodeSize')]" 
      }, 
      "osProfile": { 
       "linuxOperatingSystemProfile": { 
       "username": "[parameters('sshUserName')]", 
       "password": "[parameters('sshPassword')]" 
       } 
      }, 
      "virtualNetworkProfile": { 
       "id": "[variables('vnetID')]", 
       "subnet": "[variables('subnet1Ref')]" 
      }, 
      "scriptActions": [] 
      }, 
      { 
      "name": "workernode", 
      "targetInstanceCount": "[parameters('clusterWorkerNodeCount')]", 
      "hardwareProfile": { 
       "vmSize": "[parameters('workerNodeSize')]" 
      }, 
      "osProfile": { 
       "linuxOperatingSystemProfile": { 
       "username": "[parameters('sshUserName')]", 
       "password": "[parameters('sshPassword')]" 
       } 
      }, 
      "virtualNetworkProfile": { 
       "id": "[variables('vnetID')]", 
       "subnet": "[variables('subnet1Ref')]" 
      }, 
      "scriptActions": [] 
      } 
     ] 
     } 
    } 
    } 
], 
"outputs": { 
"cluster": { 
    "type": "object", 
    "value": "[reference(resourceId('Microsoft.HDInsight/clusters',parameters('clusterName')))]" 
} 
} 
} 

隨着參數文件:https://gist.github.com/anonymous/fa27714ea74bbcecafbbfa1380b2308a

我傳遞參數externalStorageAccounts如以下細節

"externalStorageAccounts": { 
    "value": [ 
    { "name": "sparkstg", "container": "sparkdata", "isDefault": "true","resourceGroupsName": "Spark" }, 
    { "name": "s1rg", "container": "blank", "isDefault": "false","resourceGroupsName": "s1rg" }, 
    { "name": "s2rg", "container": "blank", "isDefault": "false","resourceGroupsName": "s2rg" }, 
    { "name": "s3rg", "container": "blank", "isDefault": "false","resourceGroupsName": "s3rg" }, 
    { "name": "s4rg", "container": "blank", "isDefault": "false","resourceGroupsName": "s3rg" } 
    ] 
} 

但是,讓無效的模板錯誤

陣列

試圖瞭解我在這裏做什麼錯誤。

+0

你的語法很好 - 我認爲你遇到了一個問題,在屬性副本中使用listkeys(),不知道爲什麼 - lemme挖了一下,看看我能不能找出... –

回答

0

你需要從資源定義中移除copy並創建以下JSON:

"storageProfile": { 
    "copy": [ 
     { 
      "name": "storageaccounts", 
      "count": "[length(parameters('externalStorageAccounts'))]", 
      "input": { 
       "name": "[concat(parameters('externalStorageAccounts')[copyIndex('storageaccounts')].name,'.blob.core.windows.net')]", 
       "isDefault": "[parameters('externalStorageAccounts')[copyIndex('storageaccounts')].isDefault]", 
       "container": "[parameters('externalStorageAccounts')[copyIndex('storageaccounts')].container]", 
       "key": "[listKeys(resourceId(parameters('externalStorageAccounts')[copyIndex('storageaccounts')].resourceGroupsName,'Microsoft.Storage/storageAccounts', parameters('externalStorageAccounts')[copyIndex('storageaccounts')].name), variables('defaultApiVersion')).key1]" 
      } 
     } 
    ] 
} 

,而不是將現有的storageProfile

基本上你在做什麼的 - 試圖創建相同的資源X倍,你需要做的是複製單個屬性X次

好的,經過這一點修補之後,我可以向你保證這是不可能的,因爲listkeys是一個運行時功能,屬性拷貝是一個公司mpilation時間函數。所以這不可能工作(這起初不知道怎麼回事)。

你的解決方法,可以事先拔鑰匙,並直接將其添加到陣列,所以你的陣列是這樣的:

"externalStorageAccounts": { 
    "value": [ 
    { "name": "salsbx01sparkstg", "container": "dlid01spk21", "isDefault": "true","key": "xxx" }, 
    ... 
    { "name": "s4rg", "container": "blank", "isDefault": "false","key": "xxx" } 
    ] 
}, 
+0

不,我只想部署資源一次,但希望將存儲帳戶數組附加到'storageProfile'塊中的羣集。 – roy

+0

然後你完全錯了 – 4c74356b41

+0

這樣做的正確方法是什麼? – roy

0

我想這可能與我們正在跨越推出一個修復數據中心 - 你可以嘗試部署到westus(如果可能,我知道你有一些先決條件),看看是否有用?我可以在那裏驗證模板(並且不會在上週)。

+0

我正在美國西部嘗試這種方法。 – roy

+0

你最近試過了嗎?該修復直到上週晚些時候纔開始推出...... –