Share via


クイック スタート: Bicep を使用して Traffic Manager プロファイルを作成する

このクイックスタートでは、Bicep を使用して、パフォーマンスによるルーティング方法を使用する外部エンドポイントがある Traffic Manager プロファイルの作成方法について説明します。

Bicep は、宣言型の構文を使用して Azure リソースをデプロイするドメイン固有言語 (DSL) です。 簡潔な構文、信頼性の高いタイプ セーフ、およびコードの再利用のサポートが提供されます。 Bicep により、Azure のコード ソリューションとしてのインフラストラクチャに最適な作成エクスペリエンスが実現します。

前提条件

Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。

Bicep ファイルを確認する

このクイックスタートで使用される Bicep ファイルは、Azure クイックスタート テンプレートからのものです。

@description('Relative DNS name for the traffic manager profile, must be globally unique.')
param uniqueDnsName string

resource ExternalEndpointExample 'Microsoft.Network/trafficmanagerprofiles@2022-04-01' = {
  name: 'ExternalEndpointExample'
  location: 'global'
  properties: {
    profileStatus: 'Enabled'
    trafficRoutingMethod: 'Performance'
    dnsConfig: {
      relativeName: uniqueDnsName
      ttl: 30
    }
    monitorConfig: {
      protocol: 'HTTPS'
      port: 443
      path: '/'
      expectedStatusCodeRanges: [
        {
          min: 200
          max: 202
        }
        {
          min: 301
          max: 302
        }
      ]
    }
    endpoints: [
      {
        type: 'Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints'
        name: 'endpoint1'
        properties: {
          target: 'www.microsoft.com'
          endpointStatus: 'Enabled'
          endpointLocation: 'northeurope'
        }
      }
      {
        type: 'Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints'
        name: 'endpoint2'
        properties: {
          target: 'docs.microsoft.com'
          endpointStatus: 'Enabled'
          endpointLocation: 'southcentralus'
        }
      }
    ]
  }
}
output name string = ExternalEndpointExample.name
output resourceGroupName string = resourceGroup().name
output resourceId string = ExternalEndpointExample.id

Bicep ファイルには、1 つの Azure リソースが定義されています。

Bicep ファイルをデプロイする

  1. Bicep ファイルを main.bicep としてローカル コンピューターに保存します。

  2. Azure CLI または Azure PowerShell のどちらかを使用して Bicep ファイルをデプロイします。

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep --parameters uniqueDnsName=<dns-name>
    

    Bicep ファイルのデプロイによって、2 つの外部エンドポイントがあるプロファイルが作成されます。 Endpoint1 は、www.microsoft.com のターゲット エンドポイントを使用し、その場所は北ヨーロッパです。 Endpoint2 は、learn.microsoft.com のターゲット エンドポイントを使用し、その場所は米国中南部です。

    Note

    Bicep ファイルが正常にデプロイされるためには、uniqueDNSname がグローバルに一意の名前である必要があります。

    デプロイが完了すると、デプロイが成功したことを示すメッセージが表示されます。

デプロイの検証

Azure CLI または Azure PowerShell を使って、デプロイを検証します。

  1. Traffic Manager プロファイルの DNS 名を判別します。

    az network traffic-manager profile show --name ExternalEndpointExample --resource-group exampleRG 
    

    出力から fqdn 値をコピーします。 これは、<relativeDnsName>.trafficmanager.net という形式になります。 また、この値は、Traffic Manager プロファイルの DNS 名でもあります。

  2. 次のコマンドを実行します。その際に、{relativeDnsName} 変数を <relativeDnsName>.trafficmanager.net に置き換えます。

    nslookup -type=cname {relativeDnsName}
    

    どちらのリージョンが近いかに応じて、www.microsoft.com または learn.microsoft.com の正規名を取得する必要があります。

  3. もう一方のエンドポイントに解決できるかどうかを確認するには、最後の手順で取得したターゲットのエンドポイントを無効にします。 www.microsoft.com または learn.microsoft.com のターゲットを無効にするには、 {endpointName} をそれぞれ endpoint1 または endpoint2 に置き換えます。

    az network traffic-manager endpoint update --name {endpointName} --type externalEndpoints --profile-name ExternalEndpointExample --resource-group exampleRG --endpoint-status "Disabled"
    
  4. Azure CLI または Azure PowerShell で手順 2 のコマンドをもう一度実行します。 今回は、もう一方のエンドポイントの正規名または NameHost を取得する必要があります。

リソースをクリーンアップする

Traffic Manager プロファイルが不要になったら、Azure portal、Azure CLI、または Azure PowerShell を使用して、リソース グループを削除します。 これにより、Traffic Manager プロファイルとすべての関連リソースが削除されます。

az group delete --name exampleRG

次のステップ

このクイックスタートでは、Bicep を使用して Traffic Manager プロファイルを作成しました。

トラフィックのルーティングについて理解を深めるために、引き続き Traffic Manager のチュートリアルをご覧ください。