ARM テンプレート用の数値関数

Resource Manager では、Azure Resource Manager テンプレート (ARM テンプレート) で整数を操作するために、次の関数が提供されています。

ヒント

ARM テンプレートと同じ機能を備え、構文も使いやすいため、Bicep をお勧めします。 Bicep でのintminmaxの使用の詳細については、「int関数」を参照してください。 その他の数値の場合、「数値演算子」を参照してください。

add

add(operand1, operand2)

指定された 2 つ整数の合計を返します。

add 関数は、Bicep ではサポートされていません。 代わりに、 演算子を使用してください。

パラメーター

パラメーター 必須 説明
operand1 はい INT 加算する最初の整数。
operand2 はい INT 加算する 2 つ目の整数。

戻り値

パラメーターの合計を格納する整数。

次の例では、2 つのパラメーターを加算します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "first": {
      "type": "int",
      "defaultValue": 5,
      "metadata": {
        "description": "First integer to add"
      }
    },
    "second": {
      "type": "int",
      "defaultValue": 3,
      "metadata": {
        "description": "Second integer to add"
      }
    }
  },
  "resources": [
  ],
  "outputs": {
    "addResult": {
      "type": "int",
      "value": "[add(parameters('first'), parameters('second'))]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
addResult int 8

copyIndex

copyIndex(loopName, offset)

反復処理のループのインデックスを返します。

Bicep では、反復ループを使用します。

パラメーター

パラメーター 必須 説明
loopName いいえ string 反復処理の取得対象となるループの名前。
offset いいえ INT 0 から始まる反復値に追加する整数。

注釈

この関数は常に copy オブジェクトと共に使用されます。 offset の値が指定されていない場合、現在の反復値が返されます。 反復値は 0 から始まります。

copyIndex がリソースの反復処理を指すのかプロパティの反復処理を指すのかは、loopName プロパティで指定できます。 loopName に値を指定しなかった場合は、現在のリソース タイプの反復処理が使われます。 プロパティに対する反復では、loopName に値を指定してください。

copy の使い方の詳細については、次を参照してください。

次の例では、コピー ループと、名前に含まれるインデックス値を示します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageCount": {
      "type": "int",
      "defaultValue": 2
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-09-01",
      "name": "[format('{0}storage{1}', range(0, parameters('storageCount'))[copyIndex()], uniqueString(resourceGroup().id))]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "Storage",
      "properties": {},
      "copy": {
        "name": "storagecopy",
        "count": "[parameters('storageCount')]"
      }
    }
  ]
}

戻り値

反復値の現在のインデックスを表す整数。

div

div(operand1, operand2)

指定された 2 つの整数の整数除算を返します。

div 関数は、Bicep ではサポートされていません。 代わりに、 演算子を使用してください。

パラメーター

パラメーター 必須 説明
operand1 はい INT 除算される整数。
operand2 はい INT 除算に使用される整数。 0 にすることはできません。

戻り値

除算を表す整数。

次の例では、一方のパラメーターをもう一方のパラメーターで除算します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "first": {
      "type": "int",
      "defaultValue": 8,
      "metadata": {
        "description": "Integer being divided"
      }
    },
    "second": {
      "type": "int",
      "defaultValue": 3,
      "metadata": {
        "description": "Integer used to divide"
      }
    }
  },
  "resources": [
  ],
  "outputs": {
    "divResult": {
      "type": "int",
      "value": "[div(parameters('first'), parameters('second'))]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
divResult int 2

float

float(arg1)

値を浮動小数点数に変換します。 この関数は、ロジック アプリなどのアプリケーションにカスタム パラメーターを渡す場合にのみ使用します。

float 関数は、Bicep ではサポートされていません。

パラメーター

パラメーター 必須 説明
arg1 はい 文字列または整数 浮動小数点数に変換する値。

戻り値

浮動小数点数。

次の例では、ロジック アプリにパラメーターを渡すために浮動小数点数を使用する方法を示します。

{
  "type": "Microsoft.Logic/workflows",
  "properties": {
    ...
    "parameters": {
      "custom1": {
        "value": "[float('3.0')]"
      },
      "custom2": {
        "value": "[float(3)]"
      },

INT

int(valueToConvert)

指定された値を整数に変換します。

Bicep では、int 関数を使用します。

パラメーター

パラメーター 必須 説明
valueToConvert はい 文字列または整数 整数に変換する値。

戻り値

変換された値の整数。

次のテンプレート例では、ユーザー指定のパラメーター値を整数に変換します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stringToConvert": {
      "type": "string",
      "defaultValue": "4"
    }
  },
  "resources": [
  ],
  "outputs": {
    "intResult": {
      "type": "int",
      "value": "[int(parameters('stringToConvert'))]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
intResult int 4

max

max(arg1)

整数の配列または整数のコンマ区切りリストから最大値を返します。

Bicep では、max 関数を使用します。

パラメーター

パラメーター 必須 説明
arg1 はい 整数の配列、または整数のコンマ区切りリスト 最大値を取得するコレクション。

戻り値

コレクションの最大値を表す整数。

次の例では、max を配列および整数のリストと共に使用する方法を示します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "arrayToTest": {
      "type": "array",
      "defaultValue": [ 0, 3, 2, 5, 4 ]
    }
  },
  "resources": [],
  "outputs": {
    "arrayOutput": {
      "type": "int",
      "value": "[max(parameters('arrayToTest'))]"
    },
    "intOutput": {
      "type": "int",
      "value": "[max(0,3,2,5,4)]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
arrayOutput int 5
intOutput int 5

min

min(arg1)

整数の配列または整数のコンマ区切りリストから最小値を返します。

Bicep では、json 関数を使用します。

パラメーター

パラメーター 必須 説明
arg1 はい 整数の配列、または整数のコンマ区切りリスト 最小値を取得するコレクション。

戻り値

コレクションの最小値を表す整数。

次の例では、min を配列および整数のリストと共に使用する方法を示します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "arrayToTest": {
      "type": "array",
      "defaultValue": [ 0, 3, 2, 5, 4 ]
    }
  },
  "resources": [],
  "outputs": {
    "arrayOutput": {
      "type": "int",
      "value": "[min(parameters('arrayToTest'))]"
    },
    "intOutput": {
      "type": "int",
      "value": "[min(0,3,2,5,4)]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
arrayOutput int 0
intOutput int 0

mod

mod(operand1, operand2)

指定された 2 つの整数を使用した整数除算の剰余を返します。

mod 関数は、Bicep ではサポートされていません。 代わりに、% 演算子を使用してください。

パラメーター

パラメーター 必須 説明
operand1 はい INT 除算される整数。
operand2 はい INT 除算に使用される整数。0 にすることはできません。

戻り値

剰余を表す整数。

次の例では、一方のパラメーターをもう一方のパラメーターで除算した剰余を返します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "first": {
      "type": "int",
      "defaultValue": 7,
      "metadata": {
        "description": "Integer being divided"
      }
    },
    "second": {
      "type": "int",
      "defaultValue": 3,
      "metadata": {
        "description": "Integer used to divide"
      }
    }
  },
  "resources": [
  ],
  "outputs": {
    "modResult": {
      "type": "int",
      "value": "[mod(parameters('first'), parameters('second'))]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
modResult int 1

mul

mul(operand1, operand2)

指定された 2 つの整数の乗算を返します。

mul 関数は、Bicep ではサポートされていません。 代わりに、* 演算子を使用してください。

パラメーター

パラメーター 必須 説明
operand1 はい INT 乗算する最初の整数。
operand2 はい INT 乗算する 2 つ目の整数。

戻り値

乗算を表す整数。

次の例では、一方のパラメーターをもう一方のパラメーターで乗算します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "first": {
      "type": "int",
      "defaultValue": 5,
      "metadata": {
        "description": "First integer to multiply"
      }
    },
    "second": {
      "type": "int",
      "defaultValue": 3,
      "metadata": {
        "description": "Second integer to multiply"
      }
    }
  },
  "resources": [
  ],
  "outputs": {
    "mulResult": {
      "type": "int",
      "value": "[mul(mul(parameters('first'), parameters('second')), 3)]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
mulResult int 45

sub

sub(operand1, operand2)

指定された 2 つの整数の減算を返します。

sub 関数は、Bicep ではサポートされていません。 代わりに、- 演算子を使用してください。

パラメーター

パラメーター 必須 説明
operand1 はい INT 減算される整数。
operand2 はい INT 減算する整数。

戻り値

減算を表す整数。

次の例では、一方のパラメーターからもう一方のパラメーターを減算します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "first": {
      "type": "int",
      "defaultValue": 7,
      "metadata": {
        "description": "Integer subtracted from"
      }
    },
    "second": {
      "type": "int",
      "defaultValue": 3,
      "metadata": {
        "description": "Integer to subtract"
      }
    }
  },
  "resources": [
  ],
  "outputs": {
    "subResult": {
      "type": "int",
      "value": "[sub(parameters('first'), parameters('second'))]"
    }
  }
}

既定値を使用した場合の前の例の出力は次のようになります。

名前
subResult int 4

次のステップ