다음을 통해 공유


ARM 템플릿의 비교 함수

Resource Manager는 ARM 템플릿(Azure Resource Manager 템플릿)에서 비교를 수행하기 위한 몇 가지 함수를 제공합니다.

ARM 템플릿과 동일한 기능을 제공하고 구문이 사용하기 더 쉽기 때문에 Bicep를 권장합니다. 자세한 내용은 병합 논리 연산자 및 비교 연산자를 참조하세요.

coalesce

coalesce(arg1, arg2, arg3, ...)

매개 변수에서 첫 번째 null이 아닌 값을 반환합니다. 빈 문자열, 빈 배열 및 빈 개체는 null이 아닙니다.

Bicep에서는 대신 ?? 연산자를 사용합니다. Coalesce ??를 참조하세요.

매개 변수

매개 변수 필수 Type 설명
arg1 int, 문자열, 배열 또는 개체 null인지 테스트할 첫 번째 값입니다.
더 많은 인수 아니요 int, 문자열, 배열 또는 개체 null에 대해 테스트할 수 있는 더 많은 값입니다.

반환 값

문자열, int, 배열 또는 개체일 수 있는 첫 번째 null이 아닌 매개 변수의 값입니다. 모든 매개 변수가 null이면 null입니다.

예시

다음 예제 템플릿에서는 병합을 다르게 사용하여 출력된 결과를 보여줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "objectToTest": {
      "type": "object",
      "defaultValue": {
        "null1": null,
        "null2": null,
        "string": "default",
        "int": 1,
        "object": { "first": "default" },
        "array": [ 1 ]
      }
    }
  },
  "resources": [
  ],
  "outputs": {
    "stringOutput": {
      "type": "string",
      "value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').string)]"
    },
    "intOutput": {
      "type": "int",
      "value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').int)]"
    },
    "objectOutput": {
      "type": "object",
      "value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').object)]"
    },
    "arrayOutput": {
      "type": "array",
      "value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').array)]"
    },
    "emptyOutput": {
      "type": "bool",
      "value": "[empty(coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2))]"
    }
  }
}

기본 값을 사용한 이전 예제의 출력은 다음과 같습니다.

이름 타입
stringOutput 문자열 default
intOutput 정수 1
objectOutput Object {"first": "default"}
arrayOutput 배열 [1]
emptyOutput Bool True

같음

equals(arg1, arg2)

두 값이 서로 일치하는지 여부를 확인합니다.

Bicep에서는 대신 == 연산자를 사용합니다. 같음 ==을 참조하세요.

매개 변수

매개 변수 필수 Type 설명
arg1 int, 문자열, 배열 또는 개체 같은지 확인할 첫 번째 값입니다.
arg2 int, 문자열, 배열 또는 개체 같은지 확인할 두 번째 값입니다.

반환 값

값이 같으면 True를 반환하고 같지 않으면 False를 반환합니다.

설명

equals 함수는 종종 condition 요소와 함께 리소스 배포 여부를 테스트하는 데 사용됩니다.

{
  "condition": "[equals(parameters('newOrExisting'),'new')]",
  "type": "Microsoft.Storage/storageAccounts",
  "name": "[variables('storageAccountName')]",
  "apiVersion": "2022-09-01",
  "location": "[resourceGroup().location]",
  "sku": {
    "name": "[variables('storageAccountType')]"
  },
  "kind": "Storage",
  "properties": {}
}

예시

다음 예제에서는 서로 다른 유형의 값을 동일하게 검사합니다. 모든 기본값은 True를 반환합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstInt": {
      "type": "int",
      "defaultValue": 1
    },
    "secondInt": {
      "type": "int",
      "defaultValue": 1
    },
    "firstString": {
      "type": "string",
      "defaultValue": "a"
    },
    "secondString": {
      "type": "string",
      "defaultValue": "a"
    },
    "firstArray": {
      "type": "array",
      "defaultValue": [ "a", "b" ]
    },
    "secondArray": {
      "type": "array",
      "defaultValue": [ "a", "b" ]
    },
    "firstObject": {
      "type": "object",
      "defaultValue": { "a": "b" }
    },
    "secondObject": {
      "type": "object",
      "defaultValue": { "a": "b" }
    }
  },
  "resources": [
  ],
  "outputs": {
    "checkInts": {
      "type": "bool",
      "value": "[equals(parameters('firstInt'), parameters('secondInt') )]"
    },
    "checkStrings": {
      "type": "bool",
      "value": "[equals(parameters('firstString'), parameters('secondString'))]"
    },
    "checkArrays": {
      "type": "bool",
      "value": "[equals(parameters('firstArray'), parameters('secondArray'))]"
    },
    "checkObjects": {
      "type": "bool",
      "value": "[equals(parameters('firstObject'), parameters('secondObject'))]"
    }
  }
}

기본 값을 사용한 이전 예제의 출력은 다음과 같습니다.

이름 타입
checkInts Bool True
checkStrings Bool True
checkArrays Bool True
checkObjects Bool True

다음 예제 템플릿에서는 equalsnot을 사용합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
  ],
  "outputs": {
    "checkNotEquals": {
      "type": "bool",
      "value": "[not(equals(1, 2))]"
    }
  }
}

위 예제의 출력은 다음과 같습니다.

이름 타입
checkNotEquals Bool True

greater

greater(arg1, arg2)

첫 번째 값이 두 번째 값보다 큰지 여부를 확인합니다.

Bicep에서는 대신 > 연산자를 사용합니다. 보다 큼 >을 참조하세요.

매개 변수

매개 변수 필수 Type 설명
arg1 int 또는 문자열 greater 비교에 사용할 첫 번째 값입니다.
arg2 int 또는 문자열 greater 비교에 사용할 두 번째 값입니다.

반환 값

첫 번째 값이 두 번째 값보다 크면 True를 반환하고 크지 않으면 False를 반환합니다.

예시

다음 예제 템플릿에서는 한 값이 다른 값보다 큰지 여부를 확인합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstInt": {
      "type": "int",
      "defaultValue": 1
    },
    "secondInt": {
      "type": "int",
      "defaultValue": 2
    },
    "firstString": {
      "type": "string",
      "defaultValue": "A"
    },
    "secondString": {
      "type": "string",
      "defaultValue": "a"
    }
  },
  "resources": [
  ],
  "outputs": {
    "checkInts": {
      "type": "bool",
      "value": "[greater(parameters('firstInt'), parameters('secondInt') )]"
    },
    "checkStrings": {
      "type": "bool",
      "value": "[greater(parameters('firstString'), parameters('secondString'))]"
    }
  }
}

기본 값을 사용한 이전 예제의 출력은 다음과 같습니다.

이름 타입
checkInts Bool False
checkStrings Bool True

greaterOrEquals

greaterOrEquals(arg1, arg2)

첫 번째 값이 두 번째 값보다 크거나 같은지 여부를 확인합니다.

Bicep에서는 대신 >= 연산자를 사용합니다. 크거나 같음 >=을 참조하세요.

매개 변수

매개 변수 필수 Type 설명
arg1 int 또는 문자열 greater 또는 equal 비교에 사용할 첫 번째 값입니다.
arg2 int 또는 문자열 greater 또는 equal 비교에 사용할 두 번째 값입니다.

반환 값

첫 번째 값이 두 번째 값보다 크거나 같으면 True를 반환하고 작으면 False를 반환합니다.

예시

다음 예제에서는 한 값이 다른 값보다 크거나 같아야 하는지 여부를 검사합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstInt": {
      "type": "int",
      "defaultValue": 1
    },
    "secondInt": {
      "type": "int",
      "defaultValue": 2
    },
    "firstString": {
      "type": "string",
      "defaultValue": "A"
    },
    "secondString": {
      "type": "string",
      "defaultValue": "a"
    }
  },
  "resources": [
  ],
  "outputs": {
    "checkInts": {
      "type": "bool",
      "value": "[greaterOrEquals(parameters('firstInt'), parameters('secondInt') )]"
    },
    "checkStrings": {
      "type": "bool",
      "value": "[greaterOrEquals(parameters('firstString'), parameters('secondString'))]"
    }
  }
}

기본 값을 사용한 이전 예제의 출력은 다음과 같습니다.

이름 타입
checkInts Bool False
checkStrings Bool True

less

less(arg1, arg2)

첫 번째 값이 두 번째 값보다 작은지 여부를 확인합니다.

Bicep에서는 대신 < 연산자를 사용합니다. 보다 작음 <을 참조하세요.

매개 변수

매개 변수 필수 Type 설명
arg1 int 또는 문자열 less 비교에 사용할 첫 번째 값입니다.
arg2 int 또는 문자열 less 비교에 사용할 두 번째 값입니다.

반환 값

첫 번째 값이 두 번째 값보다 작으면 True를 반환하고 작지 않으면 False를 반환합니다.

예시

다음 예제에서는 한 값이 다른 값보다 작은지 여부를 확인합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstInt": {
      "type": "int",
      "defaultValue": 1
    },
    "secondInt": {
      "type": "int",
      "defaultValue": 2
    },
    "firstString": {
      "type": "string",
      "defaultValue": "A"
    },
    "secondString": {
      "type": "string",
      "defaultValue": "a"
    }
  },
  "resources": [
  ],
  "outputs": {
    "checkInts": {
      "type": "bool",
      "value": "[less(parameters('firstInt'), parameters('secondInt') )]"
    },
    "checkStrings": {
      "type": "bool",
      "value": "[less(parameters('firstString'), parameters('secondString'))]"
    }
  }
}

기본 값을 사용한 이전 예제의 출력은 다음과 같습니다.

이름 타입
checkInts Bool True
checkStrings Bool False

lessOrEquals

lessOrEquals(arg1, arg2)

첫 번째 값이 두 번째 값보다 작거나 같은지 여부를 확인합니다.

Bicep에서는 대신 <= 연산자를 사용합니다. 작거나 같음 <=을 참조하세요.

매개 변수

매개 변수 필수 Type 설명
arg1 int 또는 문자열 less 또는 equals 비교에 사용할 첫 번째 값입니다.
arg2 int 또는 문자열 less 또는 equals 비교에 사용할 두 번째 값입니다.

반환 값

첫 번째 값이 두 번째 값보다 작거나 같으면 True를 반환하고 크면 False를 반환합니다.

예시

다음 예제에서는 한 값이 다른 값보다 작거나 같은지 여부를 확인합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstInt": {
      "type": "int",
      "defaultValue": 1
    },
    "secondInt": {
      "type": "int",
      "defaultValue": 2
    },
    "firstString": {
      "type": "string",
      "defaultValue": "A"
    },
    "secondString": {
      "type": "string",
      "defaultValue": "a"
    }
  },
  "resources": [
  ],
  "outputs": {
    "checkInts": {
      "type": "bool",
      "value": "[lessOrEquals(parameters('firstInt'), parameters('secondInt') )]"
    },
    "checkStrings": {
      "type": "bool",
      "value": "[lessOrEquals(parameters('firstString'), parameters('secondString'))]"
    }
  }
}

기본 값을 사용한 이전 예제의 출력은 다음과 같습니다.

이름 타입
checkInts Bool True
checkStrings Bool False

다음 단계