ARM 템플릿의 개체 함수

리소스 관리자는 ARM 템플릿(Azure Resource Manager 템플릿)에서 개체를 사용하기 위한 몇 가지 함수를 제공합니다.

ARM 템플릿과 동일한 기능을 제공하고 구문이 사용하기 더 쉽기 때문에 Bicep를 권장합니다. 자세한 내용은 개체 함수를 참조하세요.

contains

contains(container, itemToFind)

배열에 값이 포함되는지, 개체에 키가 포함되는지 또는 문자열에 하위 문자열이 포함되는지를 확인합니다. 문자열 비교에서는 대/소문자를 구분합니다. 그러나 개체에 키가 포함되어 있는지를 테스트할 때는 비교에서 대/소문자를 구분하지 않습니다.

Bicep에서 contains 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
컨테이너 배열, 개체 또는 문자열 찾을 값을 포함하는 값입니다.
itemToFind 문자열 또는 int 찾을 값입니다.

반환 값

항목이 있으면 True이고, 항목이 없으면 False입니다.

예시

다음 예제에서는 여러 다른 형식의 contains를 사용하는 방법을 보여 줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stringToTest": {
      "type": "string",
      "defaultValue": "OneTwoThree"
    },
    "objectToTest": {
      "type": "object",
      "defaultValue": {
        "one": "a",
        "two": "b",
        "three": "c"
      }
    },
    "arrayToTest": {
      "type": "array",
      "defaultValue": [ "one", "two", "three" ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "stringTrue": {
      "type": "bool",
      "value": "[contains(parameters('stringToTest'), 'e')]"
    },
    "stringFalse": {
      "type": "bool",
      "value": "[contains(parameters('stringToTest'), 'z')]"
    },
    "objectTrue": {
      "type": "bool",
      "value": "[contains(parameters('objectToTest'), 'one')]"
    },
    "objectFalse": {
      "type": "bool",
      "value": "[contains(parameters('objectToTest'), 'a')]"
    },
    "arrayTrue": {
      "type": "bool",
      "value": "[contains(parameters('arrayToTest'), 'three')]"
    },
    "arrayFalse": {
      "type": "bool",
      "value": "[contains(parameters('arrayToTest'), 'four')]"
    }
  }
}

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

이름 타입
stringTrue Bool True
stringFalse Bool False
objectTrue Bool True
objectFalse Bool False
arrayTrue Bool True
arrayFalse Bool False

createObject

createObject(key1, value1, key2, value2, ...)

키와 값에서 개체를 만듭니다.

Bicep에서 createObject 함수는 지원되지 않습니다. {}를 사용하여 개체를 생성합니다. 개체를 참조하세요.

매개 변수

매개 변수 필수 Type 설명
key1 아니요 string 키의 이름입니다.
value1 아니요 int, 부울, 문자열, 개체 또는 배열 키의 값입니다.
더 많은 키 아니요 string 키의 더 많은 이름입니다.
더 많은 값 아니요 int, 부울, 문자열, 개체 또는 배열 키에 대한 더 많은 값입니다.

함수는 짝수의 매개 변수만 사용할 수 있습니다. 각 키는 일치 값이 있어야 합니다.

반환 값

각 키와 값 쌍을 포함하는 개체입니다.

예시

다음 예에서는 다양한 값 형식에서 개체를 만듭니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
  ],
  "outputs": {
    "newObject": {
      "type": "object",
      "value": "[createObject('intProp', 1, 'stringProp', 'abc', 'boolProp', true(), 'arrayProp', createArray('a', 'b', 'c'), 'objectProp', createObject('key1', 'value1'))]"
    }
  }
}

기본값을 사용하는 이전 예제의 출력은 다음과 같은 값을 가진 newObject라는 개체입니다.

{
  "intProp": 1,
  "stringProp": "abc",
  "boolProp": true,
  "arrayProp": ["a", "b", "c"],
  "objectProp": {"key1": "value1"}
}

empty

empty(itemToTest)

배열, 개체 또는 문자열이 비어 있는지를 확인합니다.

Bicep에서 empty 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
itemToTest 배열, 개체 또는 문자열 비어 있는지 확인할 값입니다.

반환 값

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

예시

다음 예제에서는 배열, 개체 및 문자열이 비어 있는지 여부를 확인합니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testArray": {
      "type": "array",
      "defaultValue": []
    },
    "testObject": {
      "type": "object",
      "defaultValue": {}
    },
    "testString": {
      "type": "string",
      "defaultValue": ""
    }
  },
  "resources": [
  ],
  "outputs": {
    "arrayEmpty": {
      "type": "bool",
      "value": "[empty(parameters('testArray'))]"
    },
    "objectEmpty": {
      "type": "bool",
      "value": "[empty(parameters('testObject'))]"
    },
    "stringEmpty": {
      "type": "bool",
      "value": "[empty(parameters('testString'))]"
    }
  }
}

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

이름 타입
arrayEmpty Bool True
objectEmpty Bool True
stringEmpty Bool True

교집합

intersection(arg1, arg2, arg3, ...)

매개 변수에서 공통 요소를 갖는 단일 배열 또는 개체를 반환합니다.

Bicep에서 intersection 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
arg1 배열 또는 개체 공통 요소를 찾는 데 사용할 첫 번째 값입니다.
arg2 배열 또는 개체 공통 요소를 찾는 데 사용할 두 번째 값입니다.
더 많은 인수 아니요 배열 또는 개체 일반적인 요소를 찾는 데 사용할 더 많은 값입니다.

반환 값

공통 요소가 있는 배열 또는 개체입니다.

예시

다음 예제에서는 배열 및 개체에 intersection을 사용하는 방법을 보여줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstObject": {
      "type": "object",
      "defaultValue": {
        "one": "a",
        "two": "b",
        "three": "c"
      }
    },
    "secondObject": {
      "type": "object",
      "defaultValue": {
        "one": "a",
        "two": "z",
        "three": "c"
      }
    },
    "firstArray": {
      "type": "array",
      "defaultValue": [ "one", "two", "three" ]
    },
    "secondArray": {
      "type": "array",
      "defaultValue": [ "two", "three" ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "objectOutput": {
      "type": "object",
      "value": "[intersection(parameters('firstObject'), parameters('secondObject'))]"
    },
    "arrayOutput": {
      "type": "array",
      "value": "[intersection(parameters('firstArray'), parameters('secondArray'))]"
    }
  }
}

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

이름 타입
objectOutput Object {"one": "a", "three": "c"}
arrayOutput 배열 ["two", "three"]

항목

items(object)

사전 개체를 배열로 변환합니다. 배열을 개체로 변환하는 방법은 toObject를 참조하세요.

Bicep에서 items 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
개체 개체 배열로 변환할 사전 개체입니다.

반환 값

변환된 사전에 대한 개체의 배열입니다. 배열의 각 개체에는 사전의 키 값이 포함된 key 속성이 있습니다. 또한 각 개체에는 해당 개체의 속성이 포함된 value 속성이 있습니다.

예시

다음 예제에서는 사전 개체를 배열로 변환합니다. 배열의 각 개체에 대해 수정된 값으로 새 개체를 만듭니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "copy": [
      {
        "name": "modifiedListOfEntities",
        "count": "[length(items(variables('entities')))]",
        "input": {
          "key": "[items(variables('entities'))[copyIndex('modifiedListOfEntities')].key]",
          "fullName": "[items(variables('entities'))[copyIndex('modifiedListOfEntities')].value.displayName]",
          "itemEnabled": "[items(variables('entities'))[copyIndex('modifiedListOfEntities')].value.enabled]"
        }
      }
    ],
    "entities": {
      "item002": {
        "enabled": false,
        "displayName": "Example item 2",
        "number": 200
      },
      "item001": {
        "enabled": true,
        "displayName": "Example item 1",
        "number": 300
      }
    }
  },
  "resources": [],
  "outputs": {
    "modifiedResult": {
      "type": "array",
      "value": "[variables('modifiedListOfEntities')]"
    }
  }
}

이전 예제에서는 다음을 반환합니다.

"modifiedResult": {
  "type": "Array",
  "value": [
    {
      "fullName": "Example item 1",
      "itemEnabled": true,
      "key": "item001"
    },
    {
      "fullName": "Example item 2",
      "itemEnabled": false,
      "key": "item002"
    }
  ]
}

다음 예제는 items 함수에서 반환되는 배열을 보여줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "entities": {
      "item002": {
        "enabled": false,
        "displayName": "Example item 2",
        "number": 200
      },
      "item001": {
        "enabled": true,
        "displayName": "Example item 1",
        "number": 300
      }
    },
    "entitiesArray": "[items(variables('entities'))]"
  },
  "resources": [],
  "outputs": {
    "itemsResult": {
      "type": "array",
      "value": "[variables('entitiesArray')]"
    }
  }
}

이 예제에서는 다음을 반환합니다.

"itemsResult": {
  "type": "Array",
  "value": [
    {
      "key": "item001",
      "value": {
        "displayName": "Example item 1",
        "enabled": true,
        "number": 300
      }
    },
    {
      "key": "item002",
      "value": {
        "displayName": "Example item 2",
        "enabled": false,
        "number": 200
      }
    }
  ]
}

JSON에서 개체는 0개 이상 키/값 쌍의 순서가 지정되지 않은 컬렉션입니다. 순서는 구현에 따라 다를 수 있습니다. 예를 들어 Bicep items() 함수는 개체를 알파벳 순서로 정렬합니다. 다른 위치에서는 원래 순서를 유지할 수 있습니다. 이러한 비결정성 때문에 배포 매개 변수 및 출력과 상호 작용하는 코드를 작성할 때는 개체 키의 순서를 가정하지 않아야 합니다.

json

json(arg1)

유효한 JSON 문자열을 JSON 데이터 형식으로 변환합니다.

Bicep에서 json 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
arg1 string JSON으로 변환할 값입니다. 문자열은 올바른 형식의 JSON 문자열이어야 합니다.

반환 값

지정된 문자열의 JSON 데이터 형식이거나, null을 지정한 경우 빈 개체입니다.

설명

JSON 개체에 매개 변수 값이나 변수를 포함해야 하는 경우 format 함수를 사용하여 함수로 전달할 문자열을 작성합니다.

null()을 사용하여 Null 값을 가져올 수도 있습니다.

예시

다음 예제에서는 json 함수를 사용하는 방법을 보여 줍니다. 빈 개체에 대해 null을 전달할 수 있습니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "jsonEmptyObject": {
      "type": "string",
      "defaultValue": "null"
    },
    "jsonObject": {
      "type": "string",
      "defaultValue": "{\"a\": \"b\"}"
    },
    "jsonString": {
      "type": "string",
      "defaultValue": "\"test\""
    },
    "jsonBoolean": {
      "type": "string",
      "defaultValue": "true"
    },
    "jsonInt": {
      "type": "string",
      "defaultValue": "3"
    },
    "jsonArray": {
      "type": "string",
      "defaultValue": "[[1,2,3 ]"
    },
    "concatValue": {
      "type": "string",
      "defaultValue": "demo value"
    }
  },
  "resources": [
  ],
  "outputs": {
    "emptyObjectOutput": {
      "type": "bool",
      "value": "[empty(json(parameters('jsonEmptyObject')))]"
    },
    "objectOutput": {
      "type": "object",
      "value": "[json(parameters('jsonObject'))]"
    },
    "stringOutput": {
      "type": "string",
      "value": "[json(parameters('jsonString'))]"
    },
    "booleanOutput": {
      "type": "bool",
      "value": "[json(parameters('jsonBoolean'))]"
    },
    "intOutput": {
      "type": "int",
      "value": "[json(parameters('jsonInt'))]"
    },
    "arrayOutput": {
      "type": "array",
      "value": "[json(parameters('jsonArray'))]"
    },
    "concatObjectOutput": {
      "type": "object",
      "value": "[json(concat('{\"a\": \"', parameters('concatValue'), '\"}'))]"
    }
  }
}

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

이름 타입
emptyObjectOutput 부울 True
objectOutput Object {"a": "b"}
stringOutput 문자열 테스트
booleanOutput 부울 True
intOutput 정수 3
arrayOutput 배열 [ 1, 2, 3 ]
concatObjectOutput Object { "a": "demo value" }

length

length(arg1)

배열의 요소 수, 문자열의 문자 수 또는 개체의 루트 수준 속성 수를 반환합니다.

Bicep에서 length 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
arg1 배열, 문자열 또는 개체 요소의 수를 가져오는 데 사용할 배열, 문자 수를 가져오는 데 사용할 문자열 또는 루트 수준의 속성 수를 가져오려는 데 사용할 개체입니다.

반환 값

int입니다.

예시

다음 예제에서는 배열 및 문자열에 length를 사용하는 방법을 보여 줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "arrayToTest": {
      "type": "array",
      "defaultValue": [
        "one",
        "two",
        "three"
      ]
    },
    "stringToTest": {
      "type": "string",
      "defaultValue": "One Two Three"
    },
    "objectToTest": {
      "type": "object",
      "defaultValue": {
        "propA": "one",
        "propB": "two",
        "propC": "three",
        "propD": {
          "propD-1": "sub",
          "propD-2": "sub"
        }
      }
    }
  },
  "resources": [],
  "outputs": {
    "arrayLength": {
      "type": "int",
      "value": "[length(parameters('arrayToTest'))]"
    },
    "stringLength": {
      "type": "int",
      "value": "[length(parameters('stringToTest'))]"
    },
    "objectLength": {
      "type": "int",
      "value": "[length(parameters('objectToTest'))]"
    }
  }
}

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

이름 타입
arrayLength 정수 3
stringLength 정수 13
objectLength 정수 4

null

null()

null을 반환합니다.

null 함수는 Bicep에서 사용할 수 없습니다. 대신 null 키워드를 사용합니다.

매개 변수

Null 함수는 매개 변수를 허용하지 않습니다.

반환 값

항상 Null인 값입니다.

예시

다음 예제에서는 Null 함수를 사용합니다.

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

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

이름 타입
emptyOutput Bool True

union

union(arg1, arg2, arg3, ...)

매개 변수의 모든 요소를 포함하는 단일 배열 또는 개체를 반환합니다. 배열의 경우 중복 값이 한 번 포함됩니다. 개체의 경우 중복 속성 이름은 한 번만 포함됩니다.

Bicep에서 union 함수를 사용합니다.

매개 변수

매개 변수 필수 Type 설명
arg1 배열 또는 개체 요소를 조인하는 데 사용할 첫 번째 값입니다.
arg2 배열 또는 개체 요소를 조인하는 데 사용할 두 번째 값입니다.
더 많은 인수 아니요 배열 또는 개체 요소를 조인하는 데 사용할 더 많은 값입니다.

반환 값

배열 또는 개체입니다.

설명

union 함수는 매개 변수의 시퀀스를 사용하여 결과의 순서와 값을 결정합니다.

배열의 경우 함수는 첫 번째 매개 변수의 각 요소를 반복하고 아직 존재하지 않는 경우 결과에 추가합니다. 그런 다음, 두 번째 매개 변수 및 추가 매개 변수에 대한 프로세스를 반복합니다. 값이 이미 있는 경우 배열의 이전 배치가 유지됩니다.

개체의 경우 첫 번째 매개 변수의 속성 이름과 값이 결과에 추가됩니다. 후자 매개 변수의 경우 결과에 새 이름이 추가됩니다. 후자 매개 변수에 동일한 이름의 속성이 있는 경우 해당 값은 기존 값을 덮어씁니다. 속성의 순서가 보장되지 않습니다.

Union 함수는 최상위 요소뿐만 아니라 해당 요소 내의 중첩된 배열 및 개체를 재귀적으로 병합합니다. 다음 섹션의 두 번째 예제를 참조하세요.

예시

다음 예제에서는 배열 및 개체에 union을 사용하는 방법을 보여 줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstObject": {
      "type": "object",
      "defaultValue": {
        "one": "a",
        "two": "b",
        "three": "c1"
      }
    },
    "secondObject": {
      "type": "object",
      "defaultValue": {
        "three": "c2",
        "four": "d",
        "five": "e"
      }
    },
    "firstArray": {
      "type": "array",
      "defaultValue": [ "one", "two", "three" ]
    },
    "secondArray": {
      "type": "array",
      "defaultValue": [ "three", "four" ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "objectOutput": {
      "type": "object",
      "value": "[union(parameters('firstObject'), parameters('secondObject'))]"
    },
    "arrayOutput": {
      "type": "array",
      "value": "[union(parameters('firstArray'), parameters('secondArray'))]"
    }
  }
}

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

이름 타입
objectOutput Object {"one": "a", "two": "b", "three": "c2", "four": "d", "five": "e"}
arrayOutput 배열 ["one", "two", "three", "four"]

다음 예제에서는 딥 병합 기능을 보여 줍니다.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "firstObject": {
      "property": {
        "one": "a",
        "two": "b",
        "three": "c1"
      },
      "nestedArray": [
        1,
        2
      ]
    },
    "secondObject": {
      "property": {
        "three": "c2",
        "four": "d",
        "five": "e"
      },
      "nestedArray": [
        3,
        4
      ]
    },
    "firstArray": [
      [
        "one",
        "two"
      ],
      [
        "three"
      ]
    ],
    "secondArray": [
      [
        "three"
      ],
      [
        "four",
        "two"
      ]
    ]
  },
  "resources": [],
  "outputs": {
    "objectOutput": {
      "type": "Object",
      "value": "[union(variables('firstObject'), variables('secondObject'))]"
    },
    "arrayOutput": {
      "type": "Array",
      "value": "[union(variables('firstArray'), variables('secondArray'))]"
    }
  }
}

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

이름 타입
objectOutput Object {"property":{"one":"a","two":"b","three":"c2","four":"d","five":"e"},"nestedArray":[3,4]}
arrayOutput 배열 [["one","two"],["three"],["four","two"]]

중첩된 배열이 병합된 경우 objectOutput.nestedArray 값은 [1, 2, 3, 4]이고 arrayOutput 값은 [["one", "two", "three"], ["three", "four", "two"]]입니다.

다음 단계