I need to add an existing ASG (Application Security Group ) to my existing NetworkInterface.
In my code below I can find my ASG and NetworkInterface... but I have no clue how to attach both of them together.
public void AddASG(string servername, string ASGName)
{
IAzure azure = ConnectAzure();
var ASG = azure.ApplicationSecurityGroups.List().Where(y => y.Name == ASGName).First();
var nic = azure.NetworkInterfaces.List()
.Where(y => y.Name.ToUpper().Contains(servername))
.Select(x => x).First();
nic.IPConfigurations?????;
}
It seems that such a feature is not possible currently. Please have a look at the same feature request , It's still open.
As a workaround, you could make this REST API request in order to associate the desired ASG to your Network Interface.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}?api-version=2018-11-01
Send a JSON request with the format:
{
"location": "xxx",
"properties": {
"ipConfigurations": [
{
"name": "primary",
"properties":
{
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "/subscriptions/xxxxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworks/xxx/subnets/xxx"
},
"applicationSecurityGroups" : [
{
"id": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/applicationSecurityGroups/xxx"
}
]
}
}
]
}
}
Alternatively, you also could execute PowerShell scripts from C#
Hope this could help you.
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.