AllowedPattern プロパティを使用したパラメーター値の検証

  • リリースバージョン: Yokohama
  • 更新日 2026年03月13日
  • 所要時間:3分
  • Azure Resource Manager (ARM) および CloudFormation (CF) テンプレートの AllowedPattern プロパティは、プロビジョニング要求を送信する前に入力検証を実行します。

    始める前に

    必要なロール:sn.cmp.cloud_service_designer

    このタスクについて

    プロビジョニング要求をクラウドに送信する前にパラメーター値を検証するルールを指定できます。検証が失敗した場合にエラーメッセージで通知を受けるには、テンプレートの ConstraintDescription プロパティを指定します。ConstraintDescription プロパティのエラーメッセージをカスタマイズして、メッセージを明確かつ明示的にできます。通常、CF テンプレートには、AllowedPattern および ConstraintDescription プロパティが既に存在しています。これらのプロパティが存在しない場合は、次の手順で説明するように追加できます。

    手順

    1. クラウドアドミンポータル 設計 > クラウドテンプレート.
    2. テンプレートを選択するか、[新規] をクリックして新しいクラウドテンプレートを作成します。
      既存のテンプレートを選択した場合は、テンプレートの名前を変更します。
    3. [本文] テキストボックスで、ARM テンプレートと CF テンプレートに次の変更を行います。
      1. ARM テンプレートで、次の変更を行います。
        • パラメーターのメタデータセクションで、「SNC::Parameter::Metadata」を入力します。
        • AllowedPattern キーを追加し、有効な値の範囲を入力します。
        • ConstraintDescription キーを追加し、エラーメッセージを入力します。
        "parameters": {
                 "newStorageAccountName": {
                     "type": "string",
                      "metadata": {
                          "description": "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed.",
                           "SNC::Parameter::Metadata": {
                               "allowedPattern": "[0-9a-z]{1,11}",
                                "ConstraintDescription": "must be an alphanumeric "
                                                      
                                   }}} 
               
            
        
      2. CF テンプレートで、次の変更を行います。
        • AllowedPattern キーを追加し、有効な値の範囲を入力します。
        • ConstraintDescription キーを追加し、エラーメッセージを入力します。
        "Parameters" : {
                        "SSHLocation" : {
                        "Description" : "The IP address range that can be used to SSH to the EC2 instances",
                        "Type": "String",
                        "MinLength": "9",
                        "MaxLength": "18",
                        "Default": "0.0.0.0/0",
                         "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
                         "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
        
            } 
          }
    4. [送信] をクリックします。