我有我创建的这个模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"variables": {
"name": "sxp",
"slotName": "develop",
"identityWebAppName": "sxp-identity",
"identityDevelopWebAppName": "[concat(variables('identityWebAppName'), '-', variables('slotName'))]",
"sendGridPassword": "[concat('P', uniqueString(resourceGroup().id, '994ED2DD-1363-49E5-AC6E-61E878EEE357'), 'x', '!')]",
"sxpWebAppName": "[concat(variables('name'), '-website')]",
"sxpDevelopWebAppName": "[concat(variables('sxpWebAppName'), '-', variables('slotName'))]",
"sxpApiWebAppName": "[concat(variables('name'), '-api')]",
"sxpApiDevelopWebAppName": "[concat(variables('sxpApiWebAppName'), '-', variables('slotName'))]",
"sxpAdminWebAppName": "[concat(variables('name'), '-admin')]",
"sxpAdminDevelopWebAppName": "[concat(variables('sxpAdminWebAppName'), '-', variables('slotName'))]",
"authorityName": "[concat(variables('name'), '-identity')]",
"sku": "F1",
"sqlServerName": "[variables('name')]",
"sqlServerDevelopmentName": "[concat(variables('name'), '-', variables('slotName'))]",
"sqlServerPassword": "[concat('P', uniqueString(resourceGroup().id, '224F5A8B-51DB-46A3-A7C8-59B0DD584A41'), 'x', '!')]",
"sqlServerDevelopmentPassword": "[concat('P', uniqueString(resourceGroup().id, 'C1CBF350-010C-46AB-B55A-CC73046DCD9B'), 'x', '!')]",
"identityDatabaseName": "identity",
"sxpDatabaseName": "[variables('name')]",
"hangFireDatabaseName": "hangfire",
"cosmosContainerName": "products",
"cosmosThroughPut": "400",
"cosmosDevelopThroughPut": "400",
"locations": [
{
"locationName": "[parameters('location')]",
"failoverPriority": 0
}
]
},
"resources": [
{
"apiVersion": "2019-08-01",
"type": "Microsoft.Web/serverfarms",
"kind": "app",
"name": "[variables('name')]",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('sku')]"
}
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('sxpWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
},
"resources": []
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('sxpDevelopWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
},
"resources": []
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('identityWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2018-11-01",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('identityWebAppName'))]"
],
"properties": {
"httpsOnly": true,
"ASPNETCORE_DETAILEDERRORS": "false",
"ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('identityDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerPassword'), ';')]",
"Options:IdentityServerBaseUrl": "[concat('https://', variables('identityWebAppName'), '.azurewebsites.net/')]",
"Email:ApiKey": "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"
}
}
]
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('identityDevelopWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2018-11-01",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('identityDevelopWebAppName'))]"
],
"properties": {
"httpsOnly": true,
"ASPNETCORE_DETAILEDERRORS": "false",
"ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('identityDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerDevelopmentPassword'), ';')]",
"Options:IdentityServerBaseUrl": "[concat('https://', variables('identityDevelopWebAppName'), '.azurewebsites.net/')]",
"Email:ApiKey": "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"
}
}
]
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('sxpApiWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2018-11-01",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('sxpApiWebAppName'))]"
],
"properties": {
"httpsOnly": true,
"ASPNETCORE_DETAILEDERRORS": "false",
"ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('sxpDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServermentPassword'), ';')]",
"ConnectionStrings:HangFireConnection": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('hangFireDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServermentPassword'), ';')]",
"ConnectionStrings:StorageConnectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('name'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').key1)]",
"Options:Authority": "[concat('https://', variables('authorityName'), '-', variables('slotName'), '.azurewebsites.net')]",
"Azure:DocumentDbPrimaryKey": "bVzgKKKRxW1XG3cKwxErdkvQ4kI6c85W9H8WXiN0uGGdIjm0NaNFHGsN4mGOMC0ZNVb36tRKffemDtUtrm1ZEQ=="
}
}
]
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('sxpApiDevelopWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2018-11-01",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('sxpApiDevelopWebAppName'))]"
],
"properties": {
"httpsOnly": true,
"ASPNETCORE_DETAILEDERRORS": "false",
"ConnectionStrings:ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('sxpDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerDevelopmentPassword'), ';')]",
"ConnectionStrings:HangFireConnection": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('hangFireDatabaseName'), ';User Id=', variables('name'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlServerDevelopmentName'))).fullyQualifiedDomainName, ';Password=', variables('sqlServerDevelopmentPassword'), ';')]",
"ConnectionStrings:StorageConnectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('name'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').key1)]",
"Options:Authority": "[concat('https://', variables('authorityName'), '-', variables('slotName'), '.azurewebsites.net')]",
"Azure:DocumentDbPrimaryKey": "bVzgKKKRxW1XG3cKwxErdkvQ4kI6c85W9H8WXiN0uGGdIjm0NaNFHGsN4mGOMC0ZNVb36tRKffemDtUtrm1ZEQ=="
}
}
]
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('sxpAdminWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
}
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Web/sites",
"name": "[variables('sxpAdminDevelopWebAppName')]",
"kind": "app",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"WEBSITE_TIME_ZONE": "GMT Standard Time",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('name'))]"
}
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('name')]",
"location": "[parameters('location')]",
"tags": {
"name": "SXP storage"
},
"kind": "Storage",
"sku": {
"name": "Standard_LRS"
}
},
{
"name": "[variables('sqlServerName')]",
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"location": "[parameters('location')]",
"tags": {
"name": "SXP SQL server"
},
"properties": {
"administratorLogin": "[variables('name')]",
"administratorLoginPassword": "[variables('sqlServerPassword')]"
},
"resources": [
{
"apiVersion": "2019-06-01-preview",
"name": "AllowMachine",
"type": "firewallrules",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
],
"properties": {
"startIpAddress": "81.103.80.33",
"endIpAddress": "81.103.80.33"
}
},
{
"apiVersion": "2019-06-01-preview",
"name": "AllowSlot",
"type": "firewallrules",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
],
"properties": {
"startIpAddress": "51.143.191.44",
"endIpAddress": "51.143.191.44"
}
},
{
"name": "[variables('identityDatabaseName')]",
"type": "databases",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"tags": {
"name": "Identity database"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
]
},
{
"name": "[variables('sxpDatabaseName')]",
"type": "databases",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"tags": {
"name": "Sxp database"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
]
}
]
},
{
"name": "[variables('sqlServerDevelopmentName')]",
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"location": "[parameters('location')]",
"tags": {
"name": "SXP Development SQL server"
},
"properties": {
"administratorLogin": "[variables('name')]",
"administratorLoginPassword": "[variables('sqlServerDevelopmentPassword')]"
},
"resources": [
{
"apiVersion": "2019-06-01-preview",
"name": "AllowDevelopmentMachine",
"type": "firewallrules",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerDevelopmentName'))]"
],
"properties": {
"startIpAddress": "81.103.80.33",
"endIpAddress": "81.103.80.33"
}
},
{
"apiVersion": "2019-06-01-preview",
"name": "AllowDevelopmentSlot",
"type": "firewallrules",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerDevelopmentName'))]"
],
"properties": {
"startIpAddress": "51.143.191.44",
"endIpAddress": "51.143.191.44"
}
},
{
"name": "[variables('identityDatabaseName')]",
"type": "databases",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"tags": {
"name": "Development identity database"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers', '/', variables('sqlServerDevelopmentName'))]"
]
},
{
"name": "[variables('sxpDatabaseName')]",
"type": "databases",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"tags": {
"name": "Development Sxp database"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers', '/', variables('sqlServerDevelopmentName'))]"
]
}
]
},
{
"name": "[variables('sqlServerName')]",
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2019-12-12",
"location": "[parameters('location')]",
"tags": {
"name": "Cosmos DB Account"
},
"properties": {
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard"
}
},
{
"name": "[variables('sqlServerDevelopmentName')]",
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2019-12-12",
"location": "[parameters('location')]",
"tags": {
"name": "Cosmos Development DB Account"
},
"properties": {
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
"name": "[concat(variables('sqlServerName'), '/sql/', variables('sqlServerName'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('sqlServerName'))]" ],
"properties": {
"resource": {
"name": "[variables('sqlServerName')]"
},
"options": {
"throughput": "[variables('cosmosThroughPut')]"
}
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
"name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('sqlServerName'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('sqlServerDevelopmentName'))]" ],
"properties": {
"resource": {
"name": "[variables('sqlServerName')]"
},
"options": {
"throughput": "[variables('cosmosDevelopThroughPut')]"
}
}
},
{
"name": "[concat(variables('sqlServerName'), '/sql/', variables('sqlServerName'), '/', variables('cosmosContainerName'))]",
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerName'), 'sql', variables('sqlServerName'))]" ],
"properties": {
"resource": {
"name": "[variables('cosmosContainerName')]",
"partitionKey": {
"paths": [
"/categoryId"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [
{
"path": "/*"
}
]
}
}
}
},
{
"name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('sqlServerName'), '/', variables('cosmosContainerName'))]",
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerDevelopmentName'), 'sql', variables('sqlServerName'))]" ],
"properties": {
"resource": {
"name": "[variables('cosmosContainerName')]",
"partitionKey": {
"paths": [
"/categoryId"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [
{
"path": "/*"
}
]
}
}
}
},
{
"name": "[variables('name')]",
"type": "Sendgrid.Email/accounts",
"location": "[parameters('location')]",
"apiVersion": "2015-01-01",
"plan": {
"name": "free",
"publisher": "Sendgrid",
"product": "sendgrid_azure",
"promotionCode": ""
},
"properties": {
"password": "[variables('sendGridPassword')]",
"acceptMarketingEmails": "0"
}
}
]
}
运行时,出现错误,指出与sxp.database.windows.net有冲突。
如果我删除了实时SQL Server,它将起作用:
{
"name": "[variables('sqlServerName')]",
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"location": "[parameters('location')]",
"tags": {
"name": "SXP SQL server"
},
"properties": {
"administratorLogin": "[variables('name')]",
"administratorLoginPassword": "[variables('sqlServerPassword')]"
},
"resources": [
{
"apiVersion": "2019-06-01-preview",
"name": "AllowMachine",
"type": "firewallrules",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
],
"properties": {
"startIpAddress": "81.103.80.33",
"endIpAddress": "81.103.80.33"
}
},
{
"apiVersion": "2019-06-01-preview",
"name": "AllowSlot",
"type": "firewallrules",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
],
"properties": {
"startIpAddress": "51.143.191.44",
"endIpAddress": "51.143.191.44"
}
},
{
"name": "[variables('identityDatabaseName')]",
"type": "databases",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"tags": {
"name": "Identity database"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
]
},
{
"name": "[variables('sxpDatabaseName')]",
"type": "databases",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"tags": {
"name": "Sxp database"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers', '/', variables('sqlServerName'))]"
]
}
]
},
但是奇怪的是,当我运行它并查看我的资源组时,它实际上显示了与cosmos db帐户的冲突:
这很奇怪,错误消息看起来像这样:
消息:{\“ code \”:\“ BadRequest \”,\“消息\”:\“消息:{\\” partitionCount \\“:1} \ r \ nActivityId:1fd32e81-a8df-4789-920e -5594f8583ce9,请求URI:/ apps / a678790d-5f32-4849-9590-eb510b1dc384 / services / dec5d369-43fe-49e5-ba42-4bc135299134 / partitions / f780127e-794c-4ab7-9448-7aec1d4b6c81 / replicas / 132271944036741324 SDK:Microsoft.Azure.Documents.Common / 2.9.2 \“},请求URI:/ dbs,RequestStats:,SDK:Microsoft.Azure.Documents.Common / 2.9.2,Microsoft.Azure.Documents.Common / 2.9。 2,Microsoft.Azure.Documents.Common / 2.9.2,Microsoft.Azure.Documents.Common / 2.9.2,Microsoft.Azure.Documents.Common / 2.9.2,Microsoft.Azure.Documents.Common / 2.9.2, Microsoft.Azure.Documents.Common / 2.9.2,Microsoft.Azure.Documents.Common / 2.9.2,Microsoft.Azure.Documents.Common / 2.9.2
sxp appsettings错误是这样:
无法处理资源'/subscriptions/87ce59eb-a0b7-428c-8b0a-506da6569d92/resourceGroups/sxp/providers/Microsoft.Web/sites/sxp-api-develop/config/appsettings'的模板语言表达式”和“ 7003”列。 '语言表达属性'key1'不存在,可用属性为'keys'。'
和最后一个(用于sql server)指出:
名称'sxp.database.windows.net'已经存在。选择其他名称。
[就像我说过的,当我删除sql server(和数据库)时,它全部部署良好,没有冲突。有人知道我在做什么错吗?
对于第二个错误sxp应用设置错误,您在第一个模板的listkeys
的appsettings
子资源和第一个模板的[variables('sxpApiWebAppName')]
[variables('sxpApiDevelopWebAppName')]
资源中使用了Microsoft.Web/sites
函数错误。
根据documentation和here,listkeys
返回keys
数组。要访问键的实际字符串,请使用listkeys(....).keys[0].value
。
基本上,将listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').key1)
行替换为listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('name')), '2019-06-01').keys[0].value)
,然后重试。
此外,要获取存储帐户密钥,在使用密钥之前,必须存在或应该部署存储帐户。由于存储帐户本身没有任何依赖性,因此应首先进行部署。对于不依赖于其他资源的其他资源也是如此。将两个资源的存储帐户都添加到dependsOn。第二个错误应该消失。