Reputation: 3832
I have ARM template parameter which is string array (like below). How do I create variable which will be a type of string
which is join
of those values, that is "dominos","boeing"
?
"parameters": {
"clientObject": {
"value": [
"dominos",
"boeing"
]
}
}
Upvotes: 0
Views: 2346
Reputation: 1294
There actually is a join
function in ARM, see docs.
join
join(inputArray, delimiter)
Joins a string array into a single string, separated using a delimiter. ...
Examples
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"arrayString": [
"one",
"two",
"three"
]
},
"resources": [],
"outputs": {
"firstOutput": {
"type": "string",
"value": "[join(variables('arrayString'), ',')]"
},
"secondOutput": {
"type": "string",
"value": "[join(variables('arrayString'), ';')]"
}
}
}
The output from the preceding example is:
Name | Type | Value |
---|---|---|
firstOutput | String | "one,two,three" |
secondOutput | String | "one;two;three" |
Upvotes: 0
Reputation: 8717
You can use the string() function, e.g.
[string(parameters('clientObject'))]
If you don't want the square brackets you can use the replace()
function.
Upvotes: 2
Reputation: 72171
there is no easy way to my knowledge, the only working solution - using a loop of deployments, pseudocode would look like this:
{
name: concat('deploy-', copyIndex(1))
type: microsoft.resources/deployments
apiVersion: xxx
copy: {
count: length(parameters('clientObject')
name: yyy
mode: serial // (don't remember exact name, not parallel)
}
properties: {
parameters: {
param1: parameters('clientObject')[copyIndex()]
state: reference(concat('deploy-', copyIndex()).outputs.your_output.value
}
}
}
to retrieve it you would use:
reference(concat('deploy-', length(parameters('clientObject')).outputs.your_output.value
and in the nested template you would just get the current param1 passed to the template and concat it to the state (where state it the output from the previous nested template run)
if you know the length of the array (and its static) you can hardcore a concat function or (better) do a join outside of the arm template
Upvotes: 1