If you want to add an endpoint to Azure traffic manager, you need to define Endpoint
object, profileName
, groupName
and endpointType
. Besides, please note that we have to define different Endpoint
object according to the endpoint type and traffic routing method. For more details, please refer to here.
For example. My traffic routing method is Priority
and the endpoint type is AzureEndpoints
For example
- Create a service principal and assign
Contributor
role to the sp
az login
az ad sp create-for-rbac -n "MyApp" --role contributor \
--scopes /subscriptions/{SubID} --sdk-auth true
- Code
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.trafficmanager import TrafficManagerManagementClient
from azure.mgmt.trafficmanager.models import EndpointStatus, Endpoint
client_id = "<sp appId>"
secret = "<sp password>"
tenant = "<sp tenant>"
subscription_ID = "<>"
tm_client = TrafficManagerManagementClient(creds, subscription_ID)
# define endpoint
param = Endpoint(
# my target resource is app service
target_resource_id='/subscriptions/<>/resourceGroups/<>/providers/Microsoft.Web/sites/<>',
endpoint_status=EndpointStatus.enabled,
priority=1
)
result = tm_client.endpoints.create_or_update(
resource_group_name='testsignlar',
profile_name='test05',
endpoint_type='AzureEndpoints',
endpoint_name='mypoint',
parameters=param)
print(result.id)
![enter image description here](https://i.stack.imgur.com/OpcgQ.png)