public override void ExecuteCmdlet() { AppServiceEnvironmentResource ase = WebsitesClient.GetAppServiceEnvironment(ResourceGroupName, Name); string shouldProcessMessage = ""; if (ase.Kind.ToLower() == "asev2") { shouldProcessMessage = SkipDns ? "No changes will be made" : $"Create Private DNS Zone and A Records for {Name}"; } else if (ase.Kind.ToLower() == "asev3") { shouldProcessMessage = SkipDns ? $"Disable Network Policy in Subnet and create private endpoint for {Name}" : $"Disable Network Policy in Subnet, create private endpoint, and create Private DNS Zone and A Records for {Name}"; } if (ShouldProcess(Name, shouldProcessMessage)) { switch (ParameterSetName) { case SubnetNameParameterSet: case SubnetIdParameterSet: var subnet = ParameterSetName == SubnetNameParameterSet ? SubnetName : SubnetId; //Fetch RG of given Subnet var subnetResourceGroupName = NetworkClient.GetSubnetResourceGroupName(subnet, VirtualNetworkName); //If unable to fetch Subnet rg from above step, use the input RG to get validation error from api call. subnetResourceGroupName = !String.IsNullOrEmpty(subnetResourceGroupName) ? subnetResourceGroupName : ResourceGroupName; var subnetResourceId = NetworkClient.ValidateSubnet(subnet, VirtualNetworkName, subnetResourceGroupName, DefaultContext.Subscription.Id); if (ase != null) { string inboundIPAddress = ""; if (ase.Kind.ToLower() == "asev2") { // Internal ASEv2 if (ase.InternalLoadBalancingMode != "None") { var vipInfo = WebsitesClient.GetAppServiceEnvironmentAddresses(ResourceGroupName, Name); inboundIPAddress = vipInfo.InternalIpAddress; } else { throw new Exception("Private DNS Zone is not compatible with External App Service Environment"); } } else if (ase.Kind.ToLower() == "asev3") { // Create private endpoint var aseResourceId = ase.Id; var aseGroupId = "hostingEnvironments"; NetworkClient.EnsureSubnetPrivateEndpointPolicy(subnetResourceId, false); var pe = NetworkClient.CreatePrivateEndpoint(ResourceGroupName, Name, aseResourceId, aseGroupId, subnetResourceId, ase.Location); var nicId = pe.NetworkInterfaces[0].Id; inboundIPAddress = NetworkClient.GetNetworkInterfacePrivateIPAddress(nicId); } if (!SkipDns) { // Create Private DNS Zone and records var virtualNetworkResourceId = NetworkClient.GetVirtualNetworkResourceId(subnetResourceId); PrivateDnsClient.CreateAppServiceEnvironmentPrivateDnsZone(ResourceGroupName, Name, virtualNetworkResourceId, inboundIPAddress); } } break; } if (PassThru) { WriteObject(true); } } }