如何在ARM模板中动态生成Traffic Manager端点?

时间:2016-04-13 21:30:16

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

我有一个ARM模板,可以使用copy构造创建任意数量的Azure webapps,就像这样(删除了不相关的部分):

{
  "parameters": { 
    "numWebsites": {
      "type": "int",
      "defaultValue": 2
    }
  },
  "resources": [
    "name": "[concat('webapp-', copyIndex()]",
    "type": "Microsoft.Web/sites",
    "copy": {
      "name": "websitescopy",
      "count": "[parameters('numWebsites')]"
    }
  ]
}

我还想为每个创建的网站创建一个带有端点的Traffic Manager配置文件。但是,似乎没有一种方法可以在Traffic Manager资源的copy参数中使用endpoints。我见过的所有示例都有端点explicitly listed out,但我不知道提前创建了多少个Web应用程序,因此对我不起作用。

如何动态生成模板中的端点?我尝试在copy资源中使用trafficManagerProfiles语句,但会创建多个配置文件,每个配置文件都有一个端点。

4 个答案:

答案 0 :(得分:1)

以下是将外部端点创建为"子资源"的示例,在没有任何端点的情况下单独创建配置文件,然后此资源添加端点。它使用外部端点,但对于webapp也应该工作,并且与标准复制功能兼容。

HTH, 加雷斯

    {
        "apiVersion": "2015-11-01",
        "type": "Microsoft.Network/trafficManagerProfiles/ExternalEndpoints",
        "name": "ExternalEndpointExample/endpoint1",
        "dependsOn": ["Microsoft.Network/trafficManagerProfiles/ExternalEndpointExample"],
        "location": "global",
        "properties": {
            "target": "ep1.microsoft.com",
            "endpointStatus": "Enabled",
            "endpointLocation": "northeurope"
        }
    }

答案 1 :(得分:1)

我还没有对此进行测试,但现在看来copy / copyIndex应该是流量管理器端点支持的方案:

https://feedback.azure.com/forums/217313-networking/suggestions/12907815-support-copy-copyindex-in-traffic-manager-depend

以下是我实施的一个示例:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "solution-abbreviation": {
      "type": "string",
      "minLength": 1
    },
    "environment-abbreviation": {
      "type": "string",
      "allowedValues": [
        "dev",
        "test",
        "prod"
      ]
    },

    "userinterface-abbreviation": {
      "type": "string",
      "minLength": 1
    },
    "userinterface-locations": {
      "type": "array",
      "minLength": 1
    },
    "userinterface-appserviceplan-sku": {
      "type": "string",
      "allowedValues": [
        "Free",
        "Shared",
        "Basic",
        "Standard"
      ]
    },
    "userinterface-appserviceplan-workersize": {
      "type": "string",
      "allowedValues": [
        "0",
        "1",
        "2"
      ]
    },
    "userinterface-appserviceplan-numberofworkers": {
      "type": "int"
    }
  },
  "variables": {
    "userinterface-trafficmanager-name": "[concat(parameters('solution-abbreviation'), '-', parameters('environment-abbreviation'), '-', parameters('userinterface-abbreviation'))]"
  },
  "resources": [
    {
      "name": "[concat(variables('userinterface-trafficmanager-name'), '-', parameters('userinterface-locations')[copyIndex()])]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[parameters('userinterface-locations')[copyIndex()]]",
      "apiVersion": "2014-06-01",
      "dependsOn": [ ],
      "tags": {
        "displayName": "[concat(variables('userinterface-trafficmanager-name'), '-', parameters('userinterface-locations')[copyIndex()])]"
      },
      "copy": {
        "name": "[concat('serverfarms', '-copy')]",
        "count": "[length(parameters('userinterface-locations'))]"
      },
      "properties": {
        "name": "[concat(variables('userinterface-trafficmanager-name'), '-', parameters('userinterface-locations')[copyIndex()])]",
        "sku": "[parameters('userinterface-appserviceplan-sku')]",
        "workerSize": "[parameters('userinterface-appserviceplan-workersize')]",
        "numberOfWorkers": "[parameters('userinterface-appserviceplan-numberofworkers')]"
      }
    }
  ],
  "outputs": {
  }
}

答案 2 :(得分:0)

接受的答案对我来说并不清楚,保罗的回答到目前为止只提供了部分例子。在故障排除期间,我遇到了与名称段长度相关的另一个错误,这个错误并不容易理解,所以这里是我的工作解决方案(也删除了非相关部分):

    {
  "type": "Microsoft.Network/trafficManagerProfiles",
  "apiVersion": "2017-05-01",
  "location": "global",
  "name": "[variables('trafManagerProfileName')]",
  "properties": { ...}
},
{
  "apiVersion": "2015-11-01",
  "type": "Microsoft.Network/trafficManagerProfiles/ExternalEndpoints",
  "name": "[concat(variables('trafManagerProfileName'), '/Endpoint', copyIndex())]",
  "dependsOn": [
    "[concat('Microsoft.Network/trafficManagerProfiles/', variables('trafManagerProfileName'))]",
    "[concat(parameters('app_name')[copyIndex()])]"
  ],
  "location": "global",
  "properties": {
    "target": "[concat(parameters('app_name')[copyIndex()])]"        
  },
  "copy": {
    "count": "[variables('app_count')]",
    "name": "app_copy"
  }
},
{
  "type": "Microsoft.Web/sites",
  "name": "[concat(parameters('app_name')[copyIndex()])]",
  "copy": {
    "count": "[variables('app_count')]",
    "name": "app_copy"
  }
}

答案 3 :(得分:0)

您可以参考以下模板来添加启用了复制功能的流量管理器端点。

Azure不提供在副本中添加端点的功能,因此您需要创建一个单独的资源并将其链接到原始资源以添加端点。模板内部支持这种复制功能。

"resources": [ { "apiVersion": "2017-05-01", "type": "Microsoft.Network/trafficManagerProfiles", "name": "[parameters('resourceName')]", "location": "global", "properties": { "profileStatus": "Enabled", "trafficRoutingMethod": "Performance", "dnsConfig": { "relativeName": "[parameters('uniqueDnsName')]", "ttl": "[parameters('timeToLive')]" }, "monitorConfig": { "protocol": "[parameters('protocol')]", "port": "[parameters('portName')]", "path": "[parameters('pathName')]", "intervalInSeconds": "[parameters('monitorIntervalInSeconds')]", "timeoutInSeconds": "[parameters('monitorTimeoutInSeconds')]", "toleratedNumberOfFailures": "[parameters('toleratedNumberOfFailures')]" } } }, { "apiVersion": "2017-05-01", "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints", "dependsOn": [ "Microsoft.Network/trafficManagerProfiles/ExampleTMProfile" ], "location": "global", "name": "[concat('ExampleTMProfile/Endpoint', copyIndex())]", "copy": { "name": "azureEndpointsCopy", "count": "[length(parameters('azureEndpointNameArray'))]" }, "properties": { "targetResourceId": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('azureEndpointNameArray')[copyIndex()])]", "endpointStatus": "Enabled" } } ]