How to copy subsections multiple time in Azure Templates? -


i'm preparing new azure template using arm , configure inboundnatrules on loadbalancer each vms created. number of vm defined parameters need find way "copy" inboundnatrules section multiple time.

how can achieved? i'm going crazy on one.

"inboundnatrules": [                 {                     "name": "[concat('rdp-vm',copyindex())]",                                           "properties": {                         "frontendipconfiguration":                             {                                 "id": "[variables('frontendipconfigid')]"                             },                         "protocol": "tcp",                         "frontendport": "[concat('227',copyindex())]",                         "backendport": 22,                         "enablefloatingip": false                     }                 }             ] 

unfortunately there no way copy/clone nat rules. can add custom script extension vm, execute powershell script in turn creates nat rule particular vm:

{     "type": "microsoft.compute/virtualmachines/extensions",     "name": "[concat('mycustomscriptextension', copyindex())]",     "copy": {         "name": "virtualmachineloop",         "count": "[variables('numberofinstances')]"     },     "apiversion": "2015-05-01-preview",     "dependson": [        "[concat('microsoft.compute/virtualmachines/',parameters('vmname'))]"     ],     "properties": {        "publisher": "microsoft.compute",        "type": "customscriptextension",        "settings": {            "fileuris": ["http://mystorage.blob.core.windows.net/customscriptfiles/create-nat-rule.ps1"],            "commandtoexecute": "powershell.exe -executionpolicy unrestricted -file create-nat-rule.ps1",             "protectedsettings": {                 "vmindex": "[copyindex()]",             }         }     } } 

content of create-nat-rule.ps1 file:

param(   $vmindex ) $rdpport = "5000$($vmindex)" #port based on vm index: 50000, 50001, etc get-azurenetworksecuritygroup -name "dmznsg" | ` set-azurenetworksecurityrule -name "allow-rdp-vm-$($vmindex)" `     -type inbound `     -priority 120 `     -action allow `     -sourceaddressprefix 'internet'  `     -sourceportrange $rdpport `     -destinationaddressprefix '*' `     -destinationportrange '3389' `     -protocol tcp 

it assumed load balancer exists prior vm creation, if not case can add dependson vm definition or modify powershell create load balancer if not exist


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -