Azure / Azure/azure-powershell
Set-AzureRmNetworkSecurityRuleConfig sets values of not provided parameters to null
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### 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 -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](https://github.com/Azure/azure-powershell/blob/master/src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NetworkSecurityRule/SetAzureNetworkSecurityRuleConfigCommand.cs#L69).
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;
```
Contributor guide
Assessment
This issue has not been assessed yet.