Skip to content

Commit 1d339a3

Browse files
authored
{AzureNetworking} fixes #20416 Add support for what-if parameter (#20491)
* {AzureNetworking} fixes #20416 Add support for what-if parameter fixes #20416 Add support for what-if parameter As per our docs, the Add-AzLoadBalancerFrontendIpConfig, Add-AzLoadBalancerProbeConfig, Add-AzLoadBalancerBackendAddressPoolConfig cmdlets support `what-if` parameter. But currently its not honoring the `what-if` switch. This PR fixes this issue. * Update AddAzureRmLoadBalancerBackendAddressPoolConfigCommand.cs fixes #20416 Add support for what-if parameter As per our docs, the Add-AzLoadBalancerFrontendIpConfig, Add-AzLoadBalancerProbeConfig, Add-AzLoadBalancerBackendAddressPoolConfig cmdlets support what-if parameter. But currently its not honoring the what-if switch. This PR fixes this issue. * Update AddAzureRmLoadBalancerFrontendIpConfigCommand.cs fixes #20416 Add support for what-if parameter As per our docs, the Add-AzLoadBalancerFrontendIpConfig, Add-AzLoadBalancerProbeConfig, Add-AzLoadBalancerBackendAddressPoolConfig cmdlets support what-if parameter. But currently its not honoring the what-if switch. This PR fixes this issue. * Update ChangeLog.md * Update RemoveAzureRmLoadBalancerInboundNatRuleConfigCommand.cs * Update NewAzureRmLoadBalancerRuleConfigCommand.cs * Update SetAzureRMLoadBalancerCommand.cs * Update ChangeLog.md * Update ChangeLog.md
1 parent 47dc74c commit 1d339a3

File tree

7 files changed

+278
-263
lines changed

7 files changed

+278
-263
lines changed

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
## Upcoming Release
2222
* Fixed a bug that added Ddos related properties when viewing PublicIpAddress and DdosProtectionPlan objects
2323
* Fixed a Bug for Set-AzIpGroup cmdlet to support the -whatif parameter
24+
* Fixed a Bug for `Add-AzLoadBalancerFrontendIpConfig`, `Add-AzLoadBalancerProbeConfig`, `Add-AzLoadBalancerBackendAddressPoolConfig`, `Set-AzLoadBalancer`, `New-AzLoadBalancerRuleConfig`, `Remove-AzLoadBalancerInboundNatRuleConfig` cmdlets to support the `-whatif` parameter. Fix [#20416]
2425

2526
## Version 5.2.0
2627
* Added optional parameters `CustomBlockResponseStatusCode` and `CustomBlockResponseBody` parameter to `AzApplicationGatewayFirewallPolicySettings`

src/Network/Network/LoadBalancer/BackendAddressPool/AddAzureRmLoadBalancerBackendAddressPoolConfigCommand.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,37 @@ public partial class AddAzureRmLoadBalancerBackendAddressPoolConfigCommand : Net
4444

4545
public override void Execute()
4646
{
47-
// BackendAddressPools
48-
if (this.LoadBalancer.BackendAddressPools == null)
47+
if (ShouldProcess(this.LoadBalancer.Name, "Adding Backend pool Configuration"))
4948
{
50-
this.LoadBalancer.BackendAddressPools = new List<PSBackendAddressPool>();
51-
}
49+
// BackendAddressPools
50+
if (this.LoadBalancer.BackendAddressPools == null)
51+
{
52+
this.LoadBalancer.BackendAddressPools = new List<PSBackendAddressPool>();
53+
}
5254

53-
var existingBackendAddressPool = this.LoadBalancer.BackendAddressPools.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
54-
if (existingBackendAddressPool != null)
55-
{
56-
throw new ArgumentException("BackendAddressPool with the specified name already exists");
57-
}
55+
var existingBackendAddressPool = this.LoadBalancer.BackendAddressPools.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
56+
if (existingBackendAddressPool != null)
57+
{
58+
throw new ArgumentException("BackendAddressPool with the specified name already exists");
59+
}
5860

59-
var vBackendAddressPool = new PSBackendAddressPool();
61+
var vBackendAddressPool = new PSBackendAddressPool();
6062

61-
vBackendAddressPool.Name = this.Name;
62-
vBackendAddressPool.TunnelInterfaces = this.TunnelInterface?.ToList();
63+
vBackendAddressPool.Name = this.Name;
64+
vBackendAddressPool.TunnelInterfaces = this.TunnelInterface?.ToList();
6365

64-
var generatedId = string.Format(
65-
"/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
66-
this.NetworkClient.NetworkManagementClient.SubscriptionId,
67-
this.LoadBalancer.ResourceGroupName,
68-
this.LoadBalancer.Name,
69-
"BackendAddressPools",
70-
this.Name);
71-
vBackendAddressPool.Id = generatedId;
66+
var generatedId = string.Format(
67+
"/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
68+
this.NetworkClient.NetworkManagementClient.SubscriptionId,
69+
this.LoadBalancer.ResourceGroupName,
70+
this.LoadBalancer.Name,
71+
"BackendAddressPools",
72+
this.Name);
73+
vBackendAddressPool.Id = generatedId;
7274

73-
this.LoadBalancer.BackendAddressPools.Add(vBackendAddressPool);
74-
WriteObject(this.LoadBalancer, true);
75+
this.LoadBalancer.BackendAddressPools.Add(vBackendAddressPool);
76+
WriteObject(this.LoadBalancer, true);
77+
}
7578
}
7679
}
7780
}

src/Network/Network/LoadBalancer/FrontendIPConfiguration/AddAzureRmLoadBalancerFrontendIpConfigCommand.cs

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -123,110 +123,112 @@ public partial class AddAzureRmLoadBalancerFrontendIpConfigCommand : NetworkBase
123123

124124
public override void Execute()
125125
{
126-
127-
var existingFrontendIpConfiguration = this.LoadBalancer.FrontendIpConfigurations.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
128-
if (existingFrontendIpConfiguration != null)
126+
if (ShouldProcess(this.LoadBalancer.Name, "Adding Front-End IP Configuration"))
129127
{
130-
throw new ArgumentException("FrontendIpConfiguration with the specified name already exists");
131-
}
128+
var existingFrontendIpConfiguration = this.LoadBalancer.FrontendIpConfigurations.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
129+
if (existingFrontendIpConfiguration != null)
130+
{
131+
throw new ArgumentException("FrontendIpConfiguration with the specified name already exists");
132+
}
132133

133-
// FrontendIpConfigurations
134-
if (this.LoadBalancer.FrontendIpConfigurations == null)
135-
{
136-
this.LoadBalancer.FrontendIpConfigurations = new List<PSFrontendIPConfiguration>();
137-
}
134+
// FrontendIpConfigurations
135+
if (this.LoadBalancer.FrontendIpConfigurations == null)
136+
{
137+
this.LoadBalancer.FrontendIpConfigurations = new List<PSFrontendIPConfiguration>();
138+
}
138139

139-
if (string.Equals(ParameterSetName, "SetByResourceSubnet"))
140-
{
141-
if (this.Subnet != null)
140+
if (string.Equals(ParameterSetName, "SetByResourceSubnet"))
142141
{
143-
this.SubnetId = this.Subnet.Id;
142+
if (this.Subnet != null)
143+
{
144+
this.SubnetId = this.Subnet.Id;
145+
}
144146
}
145-
}
146147

147-
if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
148-
{
149-
if (this.PublicIpAddress != null)
148+
if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
150149
{
151-
this.PublicIpAddressId = this.PublicIpAddress.Id;
150+
if (this.PublicIpAddress != null)
151+
{
152+
this.PublicIpAddressId = this.PublicIpAddress.Id;
153+
}
152154
}
153-
}
154155

155-
if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddressPrefix"))
156-
{
157-
if (this.PublicIpAddressPrefix != null)
156+
if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddressPrefix"))
158157
{
159-
this.PublicIpAddressPrefixId = this.PublicIpAddressPrefix.Id;
158+
if (this.PublicIpAddressPrefix != null)
159+
{
160+
this.PublicIpAddressPrefixId = this.PublicIpAddressPrefix.Id;
161+
}
160162
}
161-
}
162163

163-
var vFrontendIpConfigurations = new PSFrontendIPConfiguration();
164+
var vFrontendIpConfigurations = new PSFrontendIPConfiguration();
164165

165-
vFrontendIpConfigurations.PrivateIpAddress = this.PrivateIpAddress;
166-
vFrontendIpConfigurations.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
167-
if (!string.IsNullOrEmpty(vFrontendIpConfigurations.PrivateIpAddress))
168-
{
169-
vFrontendIpConfigurations.PrivateIpAllocationMethod = "Static";
170-
}
171-
else
172-
{
173-
vFrontendIpConfigurations.PrivateIpAllocationMethod = "Dynamic";
174-
}
166+
vFrontendIpConfigurations.PrivateIpAddress = this.PrivateIpAddress;
167+
vFrontendIpConfigurations.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
168+
if (!string.IsNullOrEmpty(vFrontendIpConfigurations.PrivateIpAddress))
169+
{
170+
vFrontendIpConfigurations.PrivateIpAllocationMethod = "Static";
171+
}
172+
else
173+
{
174+
vFrontendIpConfigurations.PrivateIpAllocationMethod = "Dynamic";
175+
}
175176

176-
vFrontendIpConfigurations.Name = this.Name;
177+
vFrontendIpConfigurations.Name = this.Name;
177178

178-
vFrontendIpConfigurations.Zones = this.Zone?.ToList();
179-
if (!string.IsNullOrEmpty(this.SubnetId))
180-
{
181-
// Subnet
182-
if (vFrontendIpConfigurations.Subnet == null)
179+
vFrontendIpConfigurations.Zones = this.Zone?.ToList();
180+
if (!string.IsNullOrEmpty(this.SubnetId))
183181
{
184-
vFrontendIpConfigurations.Subnet = new PSSubnet();
182+
// Subnet
183+
if (vFrontendIpConfigurations.Subnet == null)
184+
{
185+
vFrontendIpConfigurations.Subnet = new PSSubnet();
186+
}
187+
vFrontendIpConfigurations.Subnet.Id = this.SubnetId;
185188
}
186-
vFrontendIpConfigurations.Subnet.Id = this.SubnetId;
187-
}
188189

189-
if (!string.IsNullOrEmpty(this.GatewayLoadBalancerId))
190-
{
191-
// Gateway
192-
if (vFrontendIpConfigurations.GatewayLoadBalancer == null)
190+
if (!string.IsNullOrEmpty(this.GatewayLoadBalancerId))
193191
{
194-
vFrontendIpConfigurations.GatewayLoadBalancer = new PSFrontendIPConfiguration();
192+
// Gateway
193+
if (vFrontendIpConfigurations.GatewayLoadBalancer == null)
194+
{
195+
vFrontendIpConfigurations.GatewayLoadBalancer = new PSFrontendIPConfiguration();
196+
}
197+
vFrontendIpConfigurations.GatewayLoadBalancer.Id = this.GatewayLoadBalancerId;
195198
}
196-
vFrontendIpConfigurations.GatewayLoadBalancer.Id = this.GatewayLoadBalancerId;
197-
}
198199

199-
if (!string.IsNullOrEmpty(this.PublicIpAddressId))
200-
{
201-
// PublicIpAddress
202-
if (vFrontendIpConfigurations.PublicIpAddress == null)
200+
if (!string.IsNullOrEmpty(this.PublicIpAddressId))
203201
{
204-
vFrontendIpConfigurations.PublicIpAddress = new PSPublicIpAddress();
202+
// PublicIpAddress
203+
if (vFrontendIpConfigurations.PublicIpAddress == null)
204+
{
205+
vFrontendIpConfigurations.PublicIpAddress = new PSPublicIpAddress();
206+
}
207+
vFrontendIpConfigurations.PublicIpAddress.Id = this.PublicIpAddressId;
205208
}
206-
vFrontendIpConfigurations.PublicIpAddress.Id = this.PublicIpAddressId;
207-
}
208209

209-
if (!string.IsNullOrEmpty(this.PublicIpAddressPrefixId))
210-
{
211-
// PublicIpAddressPrefix
212-
if (vFrontendIpConfigurations.PublicIPPrefix == null)
210+
if (!string.IsNullOrEmpty(this.PublicIpAddressPrefixId))
213211
{
214-
vFrontendIpConfigurations.PublicIPPrefix = new PSPublicIpPrefix();
212+
// PublicIpAddressPrefix
213+
if (vFrontendIpConfigurations.PublicIPPrefix == null)
214+
{
215+
vFrontendIpConfigurations.PublicIPPrefix = new PSPublicIpPrefix();
216+
}
217+
vFrontendIpConfigurations.PublicIPPrefix.Id = this.PublicIpAddressPrefixId;
215218
}
216-
vFrontendIpConfigurations.PublicIPPrefix.Id = this.PublicIpAddressPrefixId;
217-
}
218219

219-
var generatedId = string.Format(
220-
"/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
221-
this.NetworkClient.NetworkManagementClient.SubscriptionId,
222-
this.LoadBalancer.ResourceGroupName,
223-
this.LoadBalancer.Name,
224-
"FrontendIpConfigurations",
225-
this.Name);
226-
vFrontendIpConfigurations.Id = generatedId;
227-
228-
this.LoadBalancer.FrontendIpConfigurations.Add(vFrontendIpConfigurations);
229-
WriteObject(this.LoadBalancer, true);
220+
var generatedId = string.Format(
221+
"/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
222+
this.NetworkClient.NetworkManagementClient.SubscriptionId,
223+
this.LoadBalancer.ResourceGroupName,
224+
this.LoadBalancer.Name,
225+
"FrontendIpConfigurations",
226+
this.Name);
227+
vFrontendIpConfigurations.Id = generatedId;
228+
229+
this.LoadBalancer.FrontendIpConfigurations.Add(vFrontendIpConfigurations);
230+
WriteObject(this.LoadBalancer, true);
231+
}
230232
}
231233
}
232234
}

src/Network/Network/LoadBalancer/InboundNatRule/RemoveAzureRmLoadBalancerInboundNatRuleConfigCommand.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,30 @@ public partial class RemoveAzureRmLoadBalancerInboundNatRuleConfigCommand : Netw
4040

4141
public override void Execute()
4242
{
43-
44-
// InboundNatRules
45-
if (this.LoadBalancer.InboundNatRules == null)
43+
if (ShouldProcess(this.Name, "Removing the inbound NAT rule configuration"))
4644
{
47-
WriteObject(this.LoadBalancer);
48-
return;
49-
}
50-
var vInboundNatRules = this.LoadBalancer.InboundNatRules.SingleOrDefault
51-
(e =>
52-
string.Equals(e.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)
53-
);
45+
// InboundNatRules
46+
if (this.LoadBalancer.InboundNatRules == null)
47+
{
48+
WriteObject(this.LoadBalancer);
49+
return;
50+
}
51+
var vInboundNatRules = this.LoadBalancer.InboundNatRules.SingleOrDefault
52+
(e =>
53+
string.Equals(e.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)
54+
);
5455

55-
if (vInboundNatRules != null)
56-
{
57-
this.LoadBalancer.InboundNatRules.Remove(vInboundNatRules);
58-
}
56+
if (vInboundNatRules != null)
57+
{
58+
this.LoadBalancer.InboundNatRules.Remove(vInboundNatRules);
59+
}
5960

60-
if (this.LoadBalancer.InboundNatRules.Count == 0)
61-
{
62-
this.LoadBalancer.InboundNatRules = null;
61+
if (this.LoadBalancer.InboundNatRules.Count == 0)
62+
{
63+
this.LoadBalancer.InboundNatRules = null;
64+
}
65+
WriteObject(this.LoadBalancer, true);
6366
}
64-
WriteObject(this.LoadBalancer, true);
6567
}
6668
}
6769
}

0 commit comments

Comments
 (0)