Set-AzureRmNetworkSecurityRuleConfig sets values of not provided parameters to null
Cmdlet(s)
Set-AzureRmNetworkSecurityRuleConfig
Module Version
5.1.1 (Noticed on Azure Stack's version 1.2.11 but read the source code and the issue exists on Azure as well)
Description
Set-AzureRmNetworkSecurityRuleConfig modifies the chosen parameters of the network security rule but sets all other parameters to null. This seems very unintuitive, therefore I'm filing a bug to discuss whether it wouldn't be better to change the behaviour so that the cmdlet modifies only the provided parameters.
Script/Steps for Reproduction
$nsg = Get-AzureRmNetworkSecurityGroup ...
$nsg = Set-AzureRmNetworkSecurityRuleConfig -Name <rule_name_here> -NetworkSecurityGroup $nsg -Priority 123
At this point if you take a look at the NSG object, you will notice that while the priority of the rule was changed to 123, all other rule's properties were set to null.
Before executing the cmdlet, the security rule "ruleIn" has all properties.
After executing the cmdlet, the security rule had its priority updated, but all other properties were set to null.
Root cause of the issue
The reason why it happens is here: SetAzureNetworkSecurityRuleConfigCommand.cs. All the properties of the security rule are set even though they were not necessarily provided to the cmdlet:
rule.Description = this.Description;
rule.Protocol = this.Protocol;
rule.SourcePortRange = this.SourcePortRange;
rule.DestinationPortRange = this.DestinationPortRange;
rule.SourceAddressPrefix = this.SourceAddressPrefix;
rule.DestinationAddressPrefix = this.DestinationAddressPrefix;
rule.Access = this.Access;
rule.Priority = this.Priority;
rule.Direction = this.Direction;
@DeepakRajendranMsft Can you take a look at this request? I agree with @jadzikow that this is unexpected and destructive behavior.
Any updates on this?
@MikhailTryakhov Hey Mikhail, would you mind assigning this to the proper contact? (is it the same as NSG?)
Any updates on this?
Well, this behavior was sure annoying and unexpected. Any progress on fixing this issue?
@MikhailTryakhov Hey Mikhail, would you mind making sure that the proper team has a chance to look at this issue?
@chandrasekarsrinivasan @avijitgupta owns this issue
:bell: Routing this issue to @act-quality-productivity-squad.