有没有一种方法可以使用Azure资源管理器(ARM)模板仅在该存储帐户不存在时才部署该存储帐户?
以下模板将创建:
我希望前两个步骤是可选的,如果它们已经存在,请使用它们。
到目前为止,我唯一发现的就是newOrExisting的模式,但这毫无意义。该脚本应该能够判断这些资源是否已经存在,并且只需跳过创建即可。
其他部署脚本将使用相同的App Insights和存储帐户,因此,如果模板能够弄清楚它,那就太好了。
谢谢你的帮助!
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environmentName": {
"type": "string",
"defaultValue": "Dev",
"allowedValues": [
"Dev",
"Test",
"Prod"
]
}
},
"variables": {
"rgLocation": "[resourceGroup().location]",
"insightsName": "[concat('Insights-', parameters('environmentName'))]",
"appName": "[concat('MyAppName-', parameters('environmentName'))]",
"genStorageName": "[concat('blgenstorage', parameters('environmentName'))]"
},
{
"comments": "Creates a general storage account that is used to save various data, including configurations.",
"name": "[variables('genStorageName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2017-06-01",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"location": "[variables('rgLocation')]",
"tags": {},
"properties": {}
},
{
"comments": "Creates the service plan under which the web app will live.",
"name": "[concat('ServicePlan-MyApp-', parameters('environment'))]",
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2016-09-01",
"kind": "app",
"location": "[variables('rgLocation')]",
"tags": {},
"properties": {
"name": "[concat('ServicePlan-MyApp-', parameters('environmentName'))]",
"perSiteScaling": "false",
"reserved": "false"
},
"sku": {
"name": "S1",
"tier": "Standard",
"size": "S1",
"family": "S",
"capacity": 1
}
},
{
"comments": "Primary web app deployment.",
"name": "[variables('appName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2016-08-01",
"kind": "app",
"location": "[variables('rgLocation')]",
"tags": {},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', concat('ServicePlan-MyApp-', variables('envShortName')))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('genStorageName'))]",
"[resourceId('microsoft.insights/components', variables('insightsName'))]"
],
"properties": {
"enabled": true,
"hostNameSslStates": [
{
"name": "[concat(variables('appName'), '.azurewebsites.net')]",
"sslState": "Disabled"
},
{
"name": "[concat(variables('appName'), '.scm.azurewebsites.net')]",
"sslState": "Disabled"
}
],
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', concat('ServicePlan-MyApp-', parameters('environmentName')))]",
"siteConfig": {
"numberOfWorkers": 1,
"defaultDocuments": [
"Default.htm",
"Default.html",
"Default.asp",
"index.htm",
"index.html",
"iisstart.htm",
"default.aspx",
"index.php",
"hostingstart.html"
],
"netFrameworkVersion": "v4.6",
"appSettings": [
{
"name": "AppInsightsInstrumentationKey",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('insightsName')), '2015-05-01').InstrumentationKey]"
}
],
"connectionStrings": [
{
"name": "AzureStorage",
"connectionString": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('genStorageName')), '2017-06-01').keys[0].value]",
"type": "Custom"
}
],
"alwaysOn": true,
"managedPipelineMode": "Integrated",
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": false
}
],
"autoHealEnabled": false,
"vnetName": ""
},
"microService": "WebSites",
"clientAffinityEnabled": false,
"clientCertEnabled": false,
"hostNamesDisabled": false
}
}
最佳答案
如果存在存储帐户,您将如何创建?
基本上,如果ARM模板遇到资源,则其部署将在属性不匹配时对其进行更新。在您的情况下,它不会做任何事情(它将跳过它)。
关于azure - ARM-仅在不存在时才部署存储帐户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44767974/