title | description | ms.topic | ms.custom | ms.date |
---|---|---|---|---|
Template functions - string |
Describes the functions to use in an Azure Resource Manager template (ARM template) to work with strings. |
conceptual |
devx-track-arm-template |
01/31/2024 |
Resource Manager provides the following functions for working with strings in your Azure Resource Manager template (ARM template):
- base64
- base64ToJson
- base64ToString
- concat
- contains
- dataUri
- dataUriToString
- empty
- endsWith
- first
- format
- guid
- indexOf
- join
- json
- last
- lastIndexOf
- length
- newGuid
- padLeft
- replace
- skip
- split
- startsWith
- string
- substring
- take
- toLower
- toUpper
- trim
- uniqueString
- uri
- uriComponent
- uriComponentToString
Tip
We recommend Bicep because it offers the same capabilities as ARM templates and the syntax is easier to use. To learn more, see string functions.
base64(inputString)
Returns the base64 representation of the input string.
In Bicep, use the base64 function.
Parameter | Required | Type | Description |
---|---|---|---|
inputString | Yes | string | The value to return as a base64 representation. |
A string containing the base64 representation.
The following example shows how to use the base64
function.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/base64.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
base64Output | String | b25lLCB0d28sIHRocmVl |
toStringOutput | String | one, two, three |
toJsonOutput | Object | {"one": "a", "two": "b"} |
base64ToJson(base64Value)
Converts a base64 representation to a JSON object.
In Bicep, use the base64ToJson function.
Parameter | Required | Type | Description |
---|---|---|---|
base64Value | Yes | string | The base64 representation to convert to a JSON object. |
A JSON object.
The following example uses the base64ToJson
function to convert a base64 value:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/base64.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
base64Output | String | b25lLCB0d28sIHRocmVl |
toStringOutput | String | one, two, three |
toJsonOutput | Object | {"one": "a", "two": "b"} |
base64ToString(base64Value)
Converts a base64 representation to a string.
In Bicep, use the base64ToString function.
Parameter | Required | Type | Description |
---|---|---|---|
base64Value | Yes | string | The base64 representation to convert to a string. |
A string of the converted base64 value.
The following example uses the base64ToString
function to convert a base64 value:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/base64.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
base64Output | String | b25lLCB0d28sIHRocmVl |
toStringOutput | String | one, two, three |
toJsonOutput | Object | {"one": "a", "two": "b"} |
concat(arg1, arg2, arg3, ...)
Combines multiple string values and returns the concatenated string, or combines multiple arrays and returns the concatenated array.
In Bicep, use string interpolation instead of the concat()
function to improve readability. However, in some cases such as string replacement in multi-line strings, you may need to fall back on using the concat()
function or the replace()
function.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | string or array | The first string or array for concatenation. |
more arguments | No | string or array | More strings or arrays in sequential order for concatenation. |
This function can take any number of arguments, and can accept either strings or arrays for the parameters. However, you can't provide both arrays and strings for parameters. Strings are only concatenated with other strings.
A string or array of concatenated values.
The following example shows how to combine two string values and return a concatenated string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/concat-string.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
concatOutput | String | prefix-5yj4yjf5mbg72 |
The following example shows how to combine two arrays.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/concat-array.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
return | Array | ["1-1", "1-2", "1-3", "2-1", "2-2", "2-3"] |
contains(container, itemToFind)
Checks whether an array contains a value, an object contains a key, or a string contains a substring. The string comparison is case-sensitive. However, when testing if an object contains a key, the comparison is case-insensitive.
In Bicep, use the contains function.
Parameter | Required | Type | Description |
---|---|---|---|
container | Yes | array, object, or string | The value that contains the value to find. |
itemToFind | Yes | string or int | The value to find. |
True if the item is found; otherwise, False.
The following example shows how to use contains with different types:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/contains.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
stringTrue | Bool | True |
stringFalse | Bool | False |
objectTrue | Bool | True |
objectFalse | Bool | False |
arrayTrue | Bool | True |
arrayFalse | Bool | False |
dataUri(stringToConvert)
Converts a value to a data URI.
In Bicep, use the dataUri function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToConvert | Yes | string | The value to convert to a data URI. |
A string formatted as a data URI.
The following example converts a value to a data URI, and converts a data URI to a string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/datauri.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
dataUriOutput | String | data:text/plain;charset=utf8;base64,SGVsbG8= |
toStringOutput | String | Hello, World! |
dataUriToString(dataUriToConvert)
Converts a data URI formatted value to a string.
In Bicep, use the dataUriToString function.
Parameter | Required | Type | Description |
---|---|---|---|
dataUriToConvert | Yes | string | The data URI value to convert. |
A string containing the converted value.
The following example template converts a value to a data URI, and converts a data URI to a string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/datauri.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
dataUriOutput | String | data:text/plain;charset=utf8;base64,SGVsbG8= |
toStringOutput | String | Hello, World! |
empty(itemToTest)
Determines if an array, object, or string is empty.
In Bicep, use the empty function.
Parameter | Required | Type | Description |
---|---|---|---|
itemToTest | Yes | array, object, or string | The value to check if it's empty. |
Returns True if the value is empty; otherwise, False.
The following example checks whether an array, object, and string are empty.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/empty.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayEmpty | Bool | True |
objectEmpty | Bool | True |
stringEmpty | Bool | True |
endsWith(stringToSearch, stringToFind)
Determines whether a string ends with a value. The comparison is case-insensitive.
In Bicep, use the endsWith function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToSearch | Yes | string | The value that contains the item to find. |
stringToFind | Yes | string | The value to find. |
True if the last character or characters of the string match the value; otherwise, False.
The following example shows how to use the startsWith
and endsWith
functions:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/startsendswith.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
startsTrue | Bool | True |
startsCapTrue | Bool | True |
startsFalse | Bool | False |
endsTrue | Bool | True |
endsCapTrue | Bool | True |
endsFalse | Bool | False |
first(arg1)
Returns the first character of the string, or first element of the array. If an empty string is given, the function results in an empty string. In the case of an empty array, the function returns null
.
In Bicep, use the first function.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array or string | The value to retrieve the first element or character. |
A string of the first character, or the type (string, int, array, or object) of the first element in an array.
The following example shows how to use the first function with an array and string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/first.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | String | one |
stringOutput | String | O |
format(formatString, arg1, arg2, ...)
Creates a formatted string from input values.
In Bicep, use the format function.
Parameter | Required | Type | Description |
---|---|---|---|
formatString | Yes | string | The composite format string. |
arg1 | Yes | string, integer, or boolean | The value to include in the formatted string. |
more arguments | No | string, integer, or boolean | More values to include in the formatted string. |
Use this function to format a string in your template. It uses the same formatting options as the System.String.Format method in .NET.
The following example shows how to use the format function.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/format.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
formatTest | String | Hello, User. Formatted number: 8,175,133 |
guid(baseString, ...)
Creates a value in the format of a globally unique identifier based on the values provided as parameters.
In Bicep, use the guid function.
Parameter | Required | Type | Description |
---|---|---|---|
baseString | Yes | string | The value used in the hash function to create the GUID. |
more parameters as needed | No | string | You can add as many strings as needed to create the value that specifies the level of uniqueness. |
This function is helpful when you need to create a value in the format of a globally unique identifier. You provide parameter values that limit the scope of uniqueness for the result. You can specify whether the name is unique down to subscription, resource group, or deployment.
The returned value isn't a random string, but rather the result of a hash function on the parameters. The returned value is 36 characters long. It isn't globally unique. To create a new GUID that isn't based on that hash value of the parameters, use the newGuid function.
The following examples show how to use guid to create a unique value for commonly used levels.
Unique scoped to subscription
"[guid(subscription().subscriptionId)]"
Unique scoped to resource group
"[guid(resourceGroup().id)]"
Unique scoped to deployment for a resource group
"[guid(resourceGroup().id, deployment().name)]"
The guid
function implements the algorithm from RFC 4122 §4.3. The original source can be found in GuidUtility with some modifications.
A string containing 36 characters in the format of a globally unique identifier.
The following example returns results from guid
:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/guid.json":::
indexOf(stringToSearch, stringToFind)
Returns the first position of a value within a string. The comparison is case-insensitive.
In Bicep, use the indexOf function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToSearch | Yes | string | The value that contains the item to find. |
stringToFind | Yes | string | The value to find. |
An integer that represents the position of the item to find. The value is zero-based. If the item isn't found, -1 is returned.
The following example shows how to use the indexOf
and lastIndexOf
functions:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/indexof.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
firstT | Int | 0 |
lastT | Int | 3 |
firstString | Int | 2 |
lastString | Int | 0 |
notFound | Int | -1 |
join(inputArray, delimiter)
Joins a string array into a single string, separated using a delimiter.
In Bicep, use the join function.
Parameter | Required | Type | Description |
---|---|---|---|
inputArray | Yes | array of string | An array of string to join. |
delimiter | Yes | The delimiter to use for splitting the string. |
A string.
The following example joins the input string array into strings delimited by using different delimiters.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/join.json":::
The output from the preceding example is:
Name | Type | Value |
---|---|---|
firstOutput | String | "one,two,three" |
secondOutput | String | "one;two;three" |
json(arg1)
Converts a valid JSON string into a JSON data type. For more information, see json function.
In Bicep, use the json function.
last(arg1)
Returns last character of the string, or the last element of the array.
In Bicep, use the last function.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array or string | The value to retrieve the last element or character. |
A string of the last character, or the type (string, int, array, or object) of the last element in an array.
The following example shows how to use the last
function with an array and string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/last.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | String | three |
stringOutput | String | e |
lastIndexOf(stringToSearch, stringToFind)
Returns the last position of a value within a string. The comparison is case-insensitive.
In Bicep, use the lastIndexOf function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToSearch | Yes | string | The value that contains the item to find. |
stringToFind | Yes | string | The value to find. |
An integer that represents the last position of the item to find. The value is zero-based. If the item isn't found, -1 is returned.
The following example shows how to use the indexOf
and lastIndexOf
functions:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/indexof.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
firstT | Int | 0 |
lastT | Int | 3 |
firstString | Int | 2 |
lastString | Int | 0 |
notFound | Int | -1 |
length(string)
Returns the number of characters in a string, elements in an array, or root-level properties in an object.
In Bicep, use the length function.
Parameter | Required | Type | Description |
---|---|---|---|
arg1 | Yes | array, string, or object | The array to use for getting the number of elements, the string to use for getting the number of characters, or the object to use for getting the number of root-level properties. |
An int.
The following example shows how to use the length
function with an array and string:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/length.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayLength | Int | 3 |
stringLength | Int | 13 |
objectLength | Int | 4 |
newGuid()
Returns a value in the format of a globally unique identifier. This function can only be used in the default value for a parameter.
In Bicep, use the newGuid function.
You can only use this function within an expression for the default value of a parameter. Using this function anywhere else in a template returns an error. The function isn't allowed in other parts of the template because it returns a different value each time it's called. Deploying the same template with the same parameters wouldn't reliably produce the same results.
The newGuid function differs from the guid function because it doesn't take any parameters. When you call guid with the same parameter, it returns the same identifier each time. Use guid when you need to reliably generate the same GUID for a specific environment. Use newGuid when you need a different identifier each time, such as deploying resources to a test environment.
The newGuid function uses the Guid structure in the .NET Framework to generate the globally unique identifier.
If you use the option to redeploy an earlier successful deployment, and the earlier deployment includes a parameter that uses newGuid, the parameter isn't reevaluated. Instead, the parameter value from the earlier deployment is automatically reused in the rollback deployment.
In a test environment, you may need to repeatedly deploy resources that only live for a short time. Rather than constructing unique names, you can use newGuid with uniqueString to create unique names.
Be careful redeploying a template that relies on the newGuid function for a default value. When you redeploy and don't provide a value for the parameter, the function is reevaluated. If you want to update an existing resource rather than create a new one, pass in the parameter value from the earlier deployment.
A string containing 36 characters in the format of a globally unique identifier.
The following example shows a parameter with a new identifier.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/newguid.json":::
The output from the preceding example varies for each deployment but will be similar to:
Name | Type | Value |
---|---|---|
guidOutput | string | b76a51fc-bd72-4a77-b9a2-3c29e7d2e551 |
The following example uses the newGuid
function to create a unique name for a storage account. This template might work for test environment where the storage account exists for a short time and isn't redeployed.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/newguid-storageaccount.json":::
The output from the preceding example varies for each deployment but will be similar to:
Name | Type | Value |
---|---|---|
nameOutput | string | storagenziwvyru7uxie |
padLeft(valueToPad, totalLength, paddingCharacter)
Returns a right-aligned string by adding characters to the left until reaching the total specified length.
In Bicep, use the padLeft function.
Parameter | Required | Type | Description |
---|---|---|---|
valueToPad | Yes | string or int | The value to right-align. |
totalLength | Yes | int | The total number of characters in the returned string. |
paddingCharacter | No | single character | The character to use for left-padding until the total length is reached. The default value is a space. |
If the original string is longer than the number of characters to pad, no characters are added.
A string with at least the number of specified characters.
The following example shows how to pad the user-provided parameter value by adding the zero character until it reaches the total number of characters.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/padleft.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
stringOutput | String | 0000000123 |
replace(originalString, oldString, newString)
Returns a new string with all instances of one string replaced by another string.
In Bicep, use the replace function.
Parameter | Required | Type | Description |
---|---|---|---|
originalString | Yes | string | The value that has all instances of one string replaced by another string. |
oldString | Yes | string | The string to be removed from the original string. |
newString | Yes | string | The string to add in place of the removed string. |
A string with the replaced characters.
The following example shows how to remove all dashes from the user-provided string, and how to replace part of the string with another string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/replace.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
firstOutput | String | 1231231234 |
secondOutput | String | 123-123-xxxx |
skip(originalValue, numberToSkip)
Returns a string with all the characters after the specified number of characters, or an array with all the elements after the specified number of elements.
In Bicep, use the skip function.
Parameter | Required | Type | Description |
---|---|---|---|
originalValue | Yes | array or string | The array or string to use for skipping. |
numberToSkip | Yes | int | The number of elements or characters to skip. If this value is 0 or less, all the elements or characters in the value are returned. If it's larger than the length of the array or string, an empty array or string is returned. |
An array or string.
The following example skips the specified number of elements in the array, and the specified number of characters in a string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/skip.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | Array | ["three"] |
stringOutput | String | two three |
split(inputString, delimiter)
Returns an array of strings that contains the substrings of the input string that are delimited by the specified delimiters.
In Bicep, use the split function.
Parameter | Required | Type | Description |
---|---|---|---|
inputString | Yes | string | The string to split. |
delimiter | Yes | string or array of strings | The delimiter to use for splitting the string. |
An array of strings.
The following example splits the input string with a comma, and with either a comma or a semicolon.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/split.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
firstOutput | Array | ["one", "two", "three"] |
secondOutput | Array | ["one", "two", "three"] |
startsWith(stringToSearch, stringToFind)
Determines whether a string starts with a value. The comparison is case-insensitive.
In Bicep, use the startsWith function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToSearch | Yes | string | The value that contains the item to find. |
stringToFind | Yes | string | The value to find. |
True if the first character or characters of the string match the value; otherwise, False.
The following example shows how to use the startsWith
and endsWith
functions:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/startsendswith.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
startsTrue | Bool | True |
startsCapTrue | Bool | True |
startsFalse | Bool | False |
endsTrue | Bool | True |
endsCapTrue | Bool | True |
endsFalse | Bool | False |
string(valueToConvert)
Converts the specified value to a string.
In Bicep, use the string function.
Parameter | Required | Type | Description |
---|---|---|---|
valueToConvert | Yes | Any | The value to convert to string. Any type of value can be converted, including objects and arrays. |
A string of the converted value.
The following example shows how to convert different types of values to strings.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/string.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
objectOutput | String | {"valueA":10,"valueB":"Example Text"} |
arrayOutput | String | ["a","b","c"] |
intOutput | String | 5 |
substring(stringToParse, startIndex, length)
Returns a substring that starts at the specified character position and contains the specified number of characters.
In Bicep, use the substring function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToParse | Yes | string | The original string from which the substring is extracted. |
startIndex | No | int | The zero-based starting character position for the substring. |
length | No | int | The number of characters for the substring. Must refer to a location within the string. Must be zero or greater. If omitted, the remainder of the string from the start position will be returned. |
The substring. Or, an empty string if the length is zero.
The function fails when the substring extends beyond the end of the string, or when length is less than zero. The following example fails with the error "The index and length parameters must refer to a location within the string. The index parameter: '0', the length parameter: '11', the length of the string parameter: '10'.".
"parameters": {
"inputString": {
"type": "string",
"value": "1234567890"
}
}, "variables": {
"prefix": "[substring(parameters('inputString'), 0, 11)]"
}
The following example extracts a substring from a parameter.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/substring.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
substringOutput | String | two |
take(originalValue, numberToTake)
Returns an array or string. An array has the specified number of elements from the start of the array. A string has the specified number of characters from the start of the string.
In Bicep, use the take function.
Parameter | Required | Type | Description |
---|---|---|---|
originalValue | Yes | array or string | The array or string to take the elements from. |
numberToTake | Yes | int | The number of elements or characters to take. If this value is 0 or less, an empty array or string is returned. If it's larger than the length of the given array or string, all the elements in the array or string are returned. |
An array or string.
The following example takes the specified number of elements from the array, and characters from a string.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/array/take.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
arrayOutput | Array | ["one", "two"] |
stringOutput | String | on |
toLower(stringToChange)
Converts the specified string to lower case.
In Bicep, use the toLower function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToChange | Yes | string | The value to convert to lower case. |
The string converted to lower case.
The following example converts a parameter value to lower case and to upper case.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/tolower.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
toLowerOutput | String | one two three |
toUpperOutput | String | ONE TWO THREE |
toUpper(stringToChange)
Converts the specified string to upper case.
In Bicep, use the toUpper function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToChange | Yes | string | The value to convert to upper case. |
The string converted to upper case.
The following example converts a parameter value to lower case and to upper case.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/tolower.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
toLowerOutput | String | one two three |
toUpperOutput | String | ONE TWO THREE |
trim(stringToTrim)
Removes all leading and trailing white-space characters from the specified string.
In Bicep, use the trim function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToTrim | Yes | string | The value to trim. |
The string without leading and trailing white-space characters.
The following example trims the white-space characters from the parameter.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/trim.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
return | String | one two three |
uniqueString(baseString, ...)
Creates a deterministic hash string based on the values provided as parameters.
In Bicep, use the uniqueString function.
Parameter | Required | Type | Description |
---|---|---|---|
baseString | Yes | string | The value used in the hash function to create a unique string. |
more parameters as needed | No | string | You can add as many strings as needed to create the value that specifies the level of uniqueness. |
This function is helpful when you need to create a unique name for a resource. You provide parameter values that limit the scope of uniqueness for the result. You can specify whether the name is unique down to subscription, resource group, or deployment.
The returned value isn't a random string, but rather the result of a hash function. The returned value is 13 characters long. It isn't globally unique. You may want to combine the value with a prefix from your naming convention to create a name that is meaningful. The following example shows the format of the returned value. The actual value varies by the provided parameters.
tcvhiyu5h2o5o
The following examples show how to use uniqueString
to create a unique value for commonly used levels.
Unique scoped to subscription
"[uniqueString(subscription().subscriptionId)]"
Unique scoped to resource group
"[uniqueString(resourceGroup().id)]"
Unique scoped to deployment for a resource group
"[uniqueString(resourceGroup().id, deployment().name)]"
The following example shows how to create a unique name for a storage account based on your resource group. Inside the resource group, the name isn't unique if constructed the same way.
"resources": [{
"name": "[concat('storage', uniqueString(resourceGroup().id))]",
"type": "Microsoft.Storage/storageAccounts",
...
If you need to create a new unique name each time you deploy a template, and don't intend to update the resource, you can use the utcNow function with uniqueString
. You could use this approach in a test environment. For an example, see utcNow.
A string containing 13 characters.
The following example returns results from uniquestring
:
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/uniquestring.json":::
uri(baseUri, relativeUri)
Creates an absolute URI by combining the baseUri and the relativeUri string.
In Bicep, use the uri function.
Parameter | Required | Type | Description |
---|---|---|---|
baseUri | Yes | string | The base uri string. Take care to observe the behavior about the handling of the trailing slash (/ ), as described following this table. |
relativeUri | Yes | string | The relative uri string to add to the base uri string. |
-
If baseUri ends in a trailing slash, the result is baseUri followed by relativeUri.
-
If baseUri doesn't end in a trailing slash one of two things happens.
-
If baseUri has no slashes at all (aside from the
//
near the front) the result is baseUri followed by relativeUri. -
If baseUri has some slashes, but doesn't end with a slash, everything from the last slash onward is removed from baseUri and the result is baseUri followed by relativeUri.
-
Here are some examples:
uri('http://contoso.org/firstpath', 'myscript.sh') -> http://contoso.org/myscript.sh
uri('http://contoso.org/firstpath/', 'myscript.sh') -> http://contoso.org/firstpath/myscript.sh
uri('http://contoso.org/firstpath/azuredeploy.json', 'myscript.sh') -> http://contoso.org/firstpath/myscript.sh
uri('http://contoso.org/firstpath/azuredeploy.json/', 'myscript.sh') -> http://contoso.org/firstpath/azuredeploy.json/myscript.sh
For complete details, the baseUri and relativeUri parameters are resolved as specified in RFC 3986, section 5.
A string representing the absolute URI for the base and relative values.
The following example shows how to construct a link to a nested template based on the value of the parent template.
"templateLink": "[uri(deployment().properties.templateLink.uri, 'nested/azuredeploy.json')]"
The following example template shows how to use uri
, uriComponent
, and uriComponentToString
.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/uri.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
uriOutput | String | http://contoso.com/resources/nested/azuredeploy.json |
componentOutput | String | http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json |
toStringOutput | String | http://contoso.com/resources/nested/azuredeploy.json |
uricomponent(stringToEncode)
Encodes a URI.
In Bicep, use the uriComponent function.
Parameter | Required | Type | Description |
---|---|---|---|
stringToEncode | Yes | string | The value to encode. |
A string of the URI encoded value.
The following example template shows how to use uri
, uriComponent
, and uriComponentToString
.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/uri.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
uriOutput | String | http://contoso.com/resources/nested/azuredeploy.json |
componentOutput | String | http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json |
toStringOutput | String | http://contoso.com/resources/nested/azuredeploy.json |
uriComponentToString(uriEncodedString)
Returns a string of a URI encoded value.
In Bicep, use the uriComponentToString function.
Parameter | Required | Type | Description |
---|---|---|---|
uriEncodedString | Yes | string | The URI encoded value to convert to a string. |
A decoded string of URI encoded value.
The following example shows how to use uri
, uriComponent
, and uriComponentToString
.
:::code language="json" source="~/resourcemanager-templates/azure-resource-manager/functions/string/uri.json":::
The output from the preceding example with the default values is:
Name | Type | Value |
---|---|---|
uriOutput | String | http://contoso.com/resources/nested/azuredeploy.json |
componentOutput | String | http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json |
toStringOutput | String | http://contoso.com/resources/nested/azuredeploy.json |
- For a description of the sections in an ARM template, see Understand the structure and syntax of ARM templates.
- To merge multiple templates, see Using linked and nested templates when deploying Azure resources.
- To iterate a specified number of times when creating a type of resource, see Resource iteration in ARM templates.
- To see how to deploy the template you've created, see Deploy resources with ARM templates and Azure PowerShell.