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

4
我有一个 ARM 模板,使用 copy 结构创建任意数量的 Azure Web 应用程序,如下所示(删除了不相关部分):
{
  "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资源的“endpoints”参数中似乎没有使用“copy”的方法。所有我看到的示例都明确列出了端点,但我不知道有多少Web应用程序会提前创建,因此这对我不起作用。
如何在我的模板中动态生成端点?我尝试在trafficManagerProfiles资源中使用“copy”语句,但这会创建具有单个端点的多个配置文件。
4个回答

1
这是创建外部端点作为“子资源”的示例,配置文件单独创建没有任何端点,然后此资源添加端点。它使用外部端点,但同样适用于Web应用程序,并与标准复制功能兼容。
敬祝好运, Gareth
    {
        "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"
        }
    }

这是一个关于编程的内容,请将以下句子从英语翻译成中文:is it dependsOn 属性表明该端点应该是 ExternalEndpointExample TrafficManagerProfile 的一部分? - Anirudh Goel

1
你可以参考下面的模板添加启用复制的流量管理器终结点。
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"
      }
    }
  ]

1

我还没有测试过这个功能,但看起来复制/copyIndex现在应该是Traffic Manager端点的支持场景:

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

1
这个链接仍然没有提供如何创建这些端点的示例,你有这样的示例吗? - Mr. Kraus
我有一个例子...我会尝试编辑我的答案,很快包含适当的片段。 - Paul

0
被接受的答案对我来说不够清晰,Paul的回答到目前为止只提供了部分示例。在故障排除期间,我遇到了另一个与名称段长度相关的错误,这个错误不容易理解,所以这里是我的工作解决方案(也删除了非相关部分):
    {
  "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"
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接