gpt4 book ai didi

azure - ARM - 仅当存储帐户不存在时才部署

转载 作者:行者123 更新时间:2023-12-01 12:20:25 26 4
gpt4 key购买 nike

有没有办法使用 Azure 资源管理器 (ARM) 模板仅在存储帐户不存在时部署该存储帐户?

将创建以下模板:

  1. App Insights 资源(共享)
  2. 存储帐户(共享)
  3. 应用计划
  4. 配置包含 App Insights Instrumentation Key 和存储帐户连接字符串的应用实例。

我希望前两个步骤是可选的,这意味着如果它们已经存在,只需使用它们。

到目前为止我唯一发现的是 newOrExisting 的模式,但这没有任何意义。该脚本应该能够判断这些资源是否已经存在并简单地跳过创建。

其他部署脚本将使用相同的应用程序见解和存储帐户,因此如果模板能够弄清楚它就好了。

感谢您的帮助!

{
"$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/

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