Skip to content

Commit 4313922

Browse files
Nullify ASG refs if absent'
1 parent f4543f7 commit 4313922

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed

src/ResourceManager/Network/Commands.Network/NetworkInterface/NetworkInterfaceBaseCmdlet.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public PSNetworkInterface GetScaleSetNetworkInterface(string resourceGroupName,
7777
return psNetworkInterface;
7878
}
7979

80+
public void NullifyApplicationSecurityGroupIfAbsent(NetworkInterface nic)
81+
{
82+
// Temporary - to be removed
83+
foreach (var ipconfigModel in nic.IpConfigurations)
84+
{
85+
if (ipconfigModel.ApplicationSecurityGroups != null && ipconfigModel.ApplicationSecurityGroups.Count == 0)
86+
{
87+
ipconfigModel.ApplicationSecurityGroups = null;
88+
}
89+
}
90+
}
91+
8092
public PSNetworkInterface ToPsNetworkInterface(NetworkInterface nic)
8193
{
8294
var psNic = Mapper.Map<PSNetworkInterface>(nic);

src/ResourceManager/Network/Commands.Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ private PSNetworkInterface CreateNetworkInterface()
419419

420420
var networkInterfaceModel = Mapper.Map<MNM.NetworkInterface>(networkInterface);
421421

422-
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
422+
this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);
423+
424+
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
423425

424426
this.NetworkInterfaceClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkInterfaceModel);
425427

src/ResourceManager/Network/Commands.Network/NetworkInterface/SetAzureNetworkInterfaceCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public override void Execute()
5252

5353
// Map to the sdk object
5454
var networkInterfaceModel = Mapper.Map<MNM.NetworkInterface>(this.NetworkInterface);
55-
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkInterface.Tag, validate: true);
55+
56+
this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);
57+
58+
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkInterface.Tag, validate: true);
5659

5760
this.NetworkInterfaceClient.CreateOrUpdate(this.NetworkInterface.ResourceGroupName, this.NetworkInterface.Name, networkInterfaceModel);
5861

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NetworkSecurityGroupBaseCmdlet.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ public PSNetworkSecurityGroup GetNetworkSecurityGroup(string resourceGroupName,
6464
return psNetworkSecurityGroup;
6565
}
6666

67+
// Temporary - to be removed
68+
public void NullifyApplicationSecurityGroupsIfAbsent(NetworkSecurityGroup nsg)
69+
{
70+
foreach (var rule in nsg.SecurityRules)
71+
{
72+
if (rule.SourceApplicationSecurityGroups != null && rule.SourceApplicationSecurityGroups.Count == 0)
73+
{
74+
rule.SourceApplicationSecurityGroups = null;
75+
}
76+
77+
if (rule.DestinationApplicationSecurityGroups != null && rule.DestinationApplicationSecurityGroups.Count == 0)
78+
{
79+
rule.DestinationApplicationSecurityGroups = null;
80+
}
81+
}
82+
}
83+
6784
public PSNetworkSecurityGroup ToPsNetworkSecurityGroup(NetworkSecurityGroup nsg)
6885
{
6986
var psNsg = Mapper.Map<PSNetworkSecurityGroup>(nsg);

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/NewAzureNetworkSecurityGroupCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ private PSNetworkSecurityGroup CreateNetworkSecurityGroup()
9494

9595
// Map to the sdk object
9696
var nsgModel = Mapper.Map<MNM.NetworkSecurityGroup>(nsg);
97-
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
97+
98+
this.NullifyApplicationSecurityGroupsIfAbsent(nsgModel);
99+
100+
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
98101

99102
// Execute the Create NetworkSecurityGroup call
100103
this.NetworkSecurityGroupClient.CreateOrUpdate(this.ResourceGroupName, this.Name, nsgModel);

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/SetAzureNetworkSecurityGroupCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public override void Execute()
4242

4343
// Map to the sdk object
4444
var nsgModel = Mapper.Map<MNM.NetworkSecurityGroup>(this.NetworkSecurityGroup);
45-
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkSecurityGroup.Tag, validate: true);
45+
46+
this.NullifyApplicationSecurityGroupsIfAbsent(nsgModel);
47+
48+
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkSecurityGroup.Tag, validate: true);
4649

4750
// Execute the PUT NetworkSecurityGroup call
4851
this.NetworkSecurityGroupClient.CreateOrUpdate(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name, nsgModel);

0 commit comments

Comments
 (0)