farmer icon indicating copy to clipboard operation
farmer copied to clipboard

Support for Traffic Manager

Open evilpilaf opened this issue 4 years ago • 7 comments

evilpilaf avatar May 21 '20 16:05 evilpilaf

@evilpilaf Good idea. Can you provide a sample template as a basis to develop the implementation?

Here's the ARM resource spec: https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2018-04-01/trafficmanagerprofiles

isaacabraham avatar May 21 '20 17:05 isaacabraham

A sample template could be as such:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "profileName": {
            "defaultValue": "<ProfileName>",
            "type": "String"
        },
        "endpointOne": {
            "defaultValue": "/subscriptions/<GUID>/resourceGroups/endpointOneResourceGroupName/providers/Microsoft.Web/sites/<endpointOne>",
            "type": "String"
        }
		// ...
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Network/trafficManagerProfiles",
            "apiVersion": "2018-04-01",
            "name": "[parameters('profileName')]",
            "location": "global",
            "properties": {
                "profileStatus": "Enabled",
                "trafficRoutingMethod": "Performance",
                "dnsConfig": {
                    "relativeName": "[parameters('profileName')]",
                    "ttl": 60
                },
                "monitorConfig": {
                    "profileMonitorStatus": "CheckingEndpoints",
                    "protocol": "HTTP",
                    "port": 80,
                    "path": "/",
                    "intervalInSeconds": 30,
                    "toleratedNumberOfFailures": 3,
                    "timeoutInSeconds": 10
                },
                "endpoints": [
                    {
                        "id": "[concat(resourceId('Microsoft.Network/trafficManagerProfiles', parameters('profileName')), '/azureEndpoints/<FirstEndpointName>')]",
                        "name": "east",
                        "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints",
                        "properties": {
                            "endpointStatus": "Enabled",
                            "endpointMonitorStatus": "CheckingEndpoint",
                            "targetResourceId": "[parameters('endpointOne')]",
                            "target": "<TargetUrl>",
                            "weight": "<Weigth>",
                            "priority": "<Priority>",
                            "endpointLocation": "<TargetLocation>"
                        }
                    },
					// ...
                ],
                "trafficViewEnrollmentStatus": "Disabled",
                "maxReturn": 0
            }
        }
    ]
}

evilpilaf avatar May 22 '20 15:05 evilpilaf

Here is a traffic manager that routes to external endpoints (IP-addresses, can be e.g. Azure VMs) by priority:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "trafficManagerProfiles_mydomain_name": {
            "defaultValue": "mydomain",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Network/trafficManagerProfiles",
            "apiVersion": "2018-04-01",
            "name": "[parameters('trafficManagerProfiles_mydomain_name')]",
            "location": "global",
            "properties": {
                "profileStatus": "Enabled",
                "trafficRoutingMethod": "Priority",
                "dnsConfig": {
                    "relativeName": "[parameters('trafficManagerProfiles_mydomain_name')]",
                    "ttl": 60
                },
                "monitorConfig": {
                    "profileMonitorStatus": "Online",
                    "protocol": "HTTPS",
                    "port": 443,
                    "path": "/",
                    "intervalInSeconds": 30,
                    "toleratedNumberOfFailures": 3,
                    "timeoutInSeconds": 10,
                    "customHeaders": [],
                    "expectedStatusCodeRanges": []
                },
                "endpoints": [
                    {
                        "id": "[concat(resourceId('Microsoft.Network/trafficManagerProfiles', parameters('trafficManagerProfiles_mydomain_name')), '/externalEndpoints/Myserver')]",
                        "name": "Myserver",
                        "type": "Microsoft.Network/trafficManagerProfiles/externalEndpoints",
                        "properties": {
                            "endpointStatus": "Disabled",
                            "endpointMonitorStatus": "Disabled",
                            "target": "123.123.123.123",
                            "weight": 1,
                            "priority": 1
                        }
                    },
                    {
                        "id": "[concat(resourceId('Microsoft.Network/trafficManagerProfiles', parameters('trafficManagerProfiles_mydomain_name')), '/externalEndpoints/Myserver2')]",
                        "name": "Myserver2",
                        "type": "Microsoft.Network/trafficManagerProfiles/externalEndpoints",
                        "properties": {
                            "endpointStatus": "Enabled",
                            "endpointMonitorStatus": "Online",
                            "target": "123.123.123.124",
                            "weight": 1,
                            "priority": 2
                        }
                    }
                ],
                "trafficViewEnrollmentStatus": "Enabled"
            }
        }
    ]
}

Thorium avatar Jun 30 '20 13:06 Thorium

Would this make it possible to create f# script that deploys a new server and modifies the existing traffic manager to use that, if we know that there is a heavy traffic, e.g. a marketing campaign starts tomorrow?

Thorium avatar Jul 03 '20 17:07 Thorium

I started to work on on adding support in a PR since I need it for a project and I wanted to learn how to build a CE anyway. I'll probably need a few pointers to get it polished.

BrianVallelunga avatar May 26 '21 12:05 BrianVallelunga

I think this is working and can be closed.

Thorium avatar Jul 29 '21 13:07 Thorium

One more thing though: All the endpoints created by Azure seem to have an id-property which is not created by Farmer. Does anyone know should the id be added, is it used for anything?

Edit: The id-attribute is auto-generated also for a trafficmanager created by Farmer, so I guess that is not needed in the template. The what-if output only trigged me here.

Also, from azureEndpoints only a target_webapp "WebSite" is supported. But azureEndpoints can refer also to a static Azure IP, like in this ARM:

"endpoints": [
	{
		"id": "[concat(resourceId('Microsoft.Network/trafficManagerProfiles', parameters('trafficManagerProfiles_testMgr3212_name')), '/azureEndpoints/myEndpoint1')]",
		"name": "myEndpoint1",
		"type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints",
		"properties": {
			"endpointStatus": "Disabled",
			"endpointMonitorStatus": "Disabled",
			"targetResourceId": "[parameters('publicIPAddresses_myVM_ip_externalid')]",
			"target": "vmDnsName.uksouth.cloudapp.azure.com",
			"weight": 1,
			"priority": 1,
			"endpointLocation": "UK South"
		}
	}
]

Thorium avatar Sep 22 '21 11:09 Thorium

With target_external you can reference an external domain or IP. Closing this as fixed by #635.

As far as the id field, that is a read-only, ARM generated field.

ninjarobot avatar Mar 15 '23 12:03 ninjarobot