没有VM资源的Azure ARM解决方案模板的初始化逻辑



是否可以将ARM解决方案模板(createUiDefinition.json、azuredeploy.json等(发布到Azure Marketplace,该模板具有应用程序服务和CosmosDB帐户资源,但没有任何VM资源来具有初始化逻辑(如创建CosmosDB数据库、集合(,该逻辑在部署解决方案模板后执行。

如果解决方案模板包含VM,那么可以使用自定义脚本扩展,但有没有办法不使用VM?

我不确定你到底想要什么,但我们正在使用Azure Function作为arm模板的一部分来配置cosmosDb。以下是它的工作原理:

"uri": "[concat('https://functionUrl?param1=', parameters('cosmosName'), '&param2=', listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('cosmosName')), '2016-03-31').primaryMasterKey, '&code=', parameters('functionKey'))]"

这将调用Azure函数,并为其提供cosmosDb名称和密钥,您可以在Azure函数中使用该名称和密钥连接到cosmosDb并对其进行配置。唯一需要注意的是,您的函数应返回空模板(或者不为空,仅可由引擎解析(。

var template = @"{'$schema': 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#', 'contentVersion': '1.0.0.0', 'parameters': {}, 'variables': {}, 'resources': []}";
HttpResponseMessage myResponse = req.CreateResponse(HttpStatusCode.OK);
myResponse.Content = new StringContent(template, System.Text.Encoding.UTF8, "application/json");
return myResponse;

最新更新