Looking for some feedback on how i can output my app services instances names. I worked with CopyIndex and I do not understand exactly how i can do it.
First my parameters. Note that i used an array for parameters location.
"parameters": {
"location": {
"type": "array",
"metadata": {
"description": "array of region"
},
"allowedValues": [
"centralus",
"eastus"
]
}
Then i instanciate my AppServices and iterate on my differents location
{ // App Services
"type": "Microsoft.Web/sites",
"name": "[concat(variables('appServiceName'), parameters('location')[copyIndex()])]",
"apiVersion": "2018-11-01",
"copy": {
"name": "Copy website",
"count": "[length(parameters('location'))]"
},
"location": "[parameters('location')[copyIndex()]]",
"tags": {
"cost": "[parameters('Stage')]"
}
....
It works well and now I would like to output the app Service instance name:
"outputs": {
"websitesname": {
"type": "array",
"copy": {
"count": "[length(parameters('location'))]",
"input":{
"id": "here i struggle :("
}
}
}
}
I really do not know how can i get instance name ? First i tried to return value of variable but it failed.Second i tried to return value of reference but again it failed.
Any idea ?
Update 1 I applied suggestion provided by Stringfellow and i get same as your screenshot.
I am able to retrieve KeyVault name using $deploymentResult.Outputs.keyVaultName.Value
but for appServicename i have no luck. I tried $deploymentResult.Outputs.websitesname.Value then try to separate the value but it failed. I also tried to convertto-json. I believe it exists a smart way. Based on my example, how can i retrieve value AppService-Prod-centralus and AppService-Prod-eastus ?
You could construct a new variable using the copy operator and define the resource naming there. Then use the new array to copy the resources and construct the output you need, or just output the new array as it is.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "array"
}
},
"variables": {
"appServiceName": "prefix",
"copy": [
{
"name": "webSiteNames",
"count": "[length(parameters('location'))]",
"input": {
"name": "[concat(variables('appServiceName'), parameters('location')[copyIndex('webSiteNames')])]",
"location": "[parameters('location')[copyIndex('webSiteNames')]]"
}
}
]
},
"resources": [
{ // App Services
"type": "Microsoft.Web/sites",
"name": "[variables('webSiteNames')[copyIndex()].name]",
"apiVersion": "2018-11-01",
"copy": {
"name": "Copy website",
"count": "[length(parameters('location'))]"
},
"location": "[variables('webSiteNames')[copyIndex()].location]",
...
}
],
"outputs": {
"websitesname": {
"type": "array",
"copy": {
"count": "[length(variables('webSiteNames'))]",
"input": {
"id": "[variables('webSiteNames')[copyIndex()].name]"
}
}
},
"webSiteName": {
"type": "array",
"value": "[variables('webSiteNames')]"
}
}
}