4

我有一个 ARM 模板,它使用该构造创建任意数量的 Azure webapp copy,如下所示(删除了不相关的部分):

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

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

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

4

4 回答 4

1

这是将外部端点创建为“子资源”的示例,配置文件是单独创建的,没有任何端点,然后此资源添加端点。它使用外部端点,但对于 web 应用程序也同样适用,并且与标准复制功能兼容。

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"
        }
    }
于 2016-04-14T09:59:00.050 回答
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": {
  }
}
于 2016-04-22T17:14:02.687 回答
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"
      }
    }
  ]
于 2018-08-14T11:33:33.180 回答
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"
  }
}
于 2018-04-11T10:18:46.687 回答