【问题标题】:Initialization logic of a Azure ARM solution template without VM resource没有 VM 资源的 Azure ARM 解决方案模板的初始化逻辑
【发布时间】:2018-08-03 16:52:46
【问题描述】:

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

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

【问题讨论】:

    标签: azure azure-resource-manager arm-template


    【解决方案1】:

    我不确定您到底想要什么,但我们使用 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 Function 并为其提供 cosmosDb 名称和密钥,您可以在 Azure Function 中使用它来连接到 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;
    

    【讨论】:

    • 是否可以在包含 cosmosDB 帐户资源的同一 ARM 解决方案模板中部署该 Azure 函数?如果是,那么它解决了我的问题。
    • 嗯,技术上是的。您可以使用公共 github repo 来定义功能代码。也看看这里:gist.github.com/christopheranderson/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多