【问题标题】:How do I dynamically generate Traffic Manager endpoints in an ARM template?如何在 ARM 模板中动态生成流量管理器端点?
【发布时间】:2016-04-13 21:30:15
【问题描述】:

我有一个 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')]"
    }
  ]
}

我还想为创建的每个网站创建一个带有端点的流量管理器配置文件。但是,似乎没有办法在流量管理器资源的endpoints 参数中使用copy。我见过的所有示例都有端点 explicitly listed out,但我不知道提前创建了多少 web 应用程序,所以这对我不起作用。

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

【问题讨论】:

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


    【解决方案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"
            }
        }
    

    【讨论】:

    • 是不是表示该端点应该是 ExternalEndpointExample TrafficManagerProfile 的一部分的 dependsOn 属性?
    【解决方案2】:

    我尚未对此进行测试,但似乎 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": {
      }
    }
    

    【讨论】:

    • 此链接仍然没有提供如何创建这些端点的示例,您有示例说明如何工作吗?
    • 我确实有一个例子......我会尽快编辑我的答案,以便在此处包含适当的 sn-ps。
    【解决方案3】:

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

    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"
          }
        }
      ]
    

    【讨论】:

      【解决方案4】:

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

          {
        "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"
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-13
        • 1970-01-01
        • 1970-01-01
        • 2020-11-04
        相关资源
        最近更新 更多