简体   繁体   中英

Azure ARM Template - Set NSG and Subnet on single input parameter

In the process of creating an Azure Template that builds on a VM based on a set of questions asked. As of right now I have two parameter fields related to the networking side, one being the Subnet Name (existing Subnet) and the other being the NSG Name (again already existing).

In this template I don't want to create new subnets or NSG's and the way we have the environment setup it is an extension of our network so each subnet is tied to a specific NSG because they have a specific purpose; like, Application Subnet/NSG, SQL Subnet/NSG, Web Subnet/NSG, etc. and the rules are defined therein.

My question is, instead of having the people select each a Subnet and an NSG (where they could technically select two separate and the rules wouldn't align = no connectivity), I'd like to prompt them in a parameter to say the servers "purpose" (Application, SQL, Web, DMZ, etc.) and based on their answer automatically set what NSG and Subnet the new VM needs to be added too.

Thoughts?

Well, if the link between application\\sql\\dmz and subnet\\nsg is fixed and predefined you can do it easily. créate variables and calculate the value:

"subnet": "[concat(parameters('purpose'), ' Subnet')]",
"nsg": "[concat(parameters('purpose'), ' Subnet/NSG')]",

you can use object for mapping:

subnets: {
    "application": "purposesubnet",
    "sql": "nopurposesubnet",
    ...
},
subnet: "[variables('subnets')[parameters('applicationPurpose')]]"

same goes for NSG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM