Closed oleksandr-bilyk closed 5 years ago
@oleksandr-bilyk - it looks like you are trying to take a property from an array of objects, and create a new array from the values for that property. Is that right? I don't see an easy way to do that. If you know the number of elements in the array, you could use createarray and just hardcode the array index values.
Copy doesn't work because input is an object so you will always get the values wrapped in an object.
Can you pass in the parameter values differently? You could have the http ports in a separate parameter of type array.
@tfitzmac Thank you for reply. Creating additional parameter will cause ports duplications because we need two duplicating structures
@bmoore-msft - do you know of a way to create an array of integers from one property on an array of objects? Copy doesn't seem to work because it creates an array of objects. createarray works but would require a hardcoded number of elements.
Unfortunately no good way to create a dynamic array in the language today... it's on the backlog.
@oleksandr-bilyk - thanks for this example and feedback. At this point, there is not an update we can make to the documentation, but we will update it when the capabilities change.
Thank you @tfitzmac and @bmoore-msft
I need to construct array of integers. All what I may to create is array of structures like { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "hostedServices": { "type": "array", "defaultValue": [ { "name": "name1", "httpPort": 8995 }, { "name": "name2", "httpPort": 8901 } ] } }, "variables": { "hostedServicesHttpPorts": { "copy": [ { "name": "hostedServicesHttpPorts", "count": "[length(parameters('hostedServices'))]", "input": { "value": "[parameters('hostedServices')[copyIndex('hostedServicesHttpPorts')].httpPort]" } } ] } }, "resources": [], "outputs": { "hostedServicesHttpPorts": { "value": "[variables('hostedServicesHttpPorts')]", "type": "object" } } }
How may I project input array of objects into array of integers? Following syntax is not correct:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "hostedServices": { "type": "array", "defaultValue": [ { "name": "name1", "httpPort": 8995 }, { "name": "name2", "httpPort": 8901 } ] } }, "variables": { "hostedServicesHttpPorts": { "copy": [ { "name": "hostedServicesHttpPorts", "count": "[length(parameters('hostedServices'))]", "input": { "value": "[parameters('hostedServices')[copyIndex('hostedServicesHttpPorts')].httpPort]" } } ] } }, "resources": [], "outputs": { "hostedServicesHttpPorts": { "value": "[variables('hostedServicesHttpPorts')]", "type": "object" } } }
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.