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);
                }
            }
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            var ase = WebsitesClient.GetAppServiceEnvironment(ResourceGroupName, Name);

            WriteObject(new PSAppServiceEnvironment(ase), true);
        }
Esempio n. 3
0
        public override void ExecuteCmdlet()
        {
            if (ShouldProcess(Name, $"Creating App Service Environment '{Name}'"))
            {
                AppServiceEnvironmentResource appServiceEnvironment = new AppServiceEnvironmentResource();
                appServiceEnvironment.AppServiceEnvironmentResourceName     = Name;
                appServiceEnvironment.AppServiceEnvironmentResourceLocation = Location;
                appServiceEnvironment.Location    = Location;
                appServiceEnvironment.Kind        = Kind;
                appServiceEnvironment.WorkerPools = new List <WorkerPool>()
                {
                };

                AppServiceEnvironmentResource ase = null;
                switch (ParameterSetName)
                {
                case ASEv2SubnetNameParameterSet:
                case ASEv2SubnetIdParameterSet:
                    var subnet = ParameterSetName == ASEv2SubnetNameParameterSet ? 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 (!SkipRouteTable)
                    {
                        NetworkClient.EnsureASEv2RouteTable(ResourceGroupName, Name, Location, subnetResourceId);
                    }

                    if (!SkipNetworkSecurityGroup)
                    {
                        NetworkClient.EnsureASEv2NetworkSecurityGroup(ResourceGroupName, Name, Location, subnetResourceId);
                    }

                    appServiceEnvironment.VirtualNetwork            = new VirtualNetworkProfile(id: subnetResourceId);
                    appServiceEnvironment.InternalLoadBalancingMode = LoadBalancerMode == "External" ? "None" : "Web,Publishing";

                    // Create ASEv2
                    ase = WebsitesClient.CreateAppServiceEnvironment(ResourceGroupName, Name, appServiceEnvironment);
                    break;

                case ASEv3SubnetNameParameterSet:
                case ASEv3SubnetIdParameterSet:
                    var outboundSubnet = ParameterSetName == ASEv3SubnetNameParameterSet ? SubnetName : SubnetId;
                    //Fetch RG of given Subnet
                    var outboundSubnetResourceGroupName = NetworkClient.GetSubnetResourceGroupName(outboundSubnet, VirtualNetworkName);
                    //If unable to fetch Subnet rg from above step, use the input RG to get validation error from api call.
                    outboundSubnetResourceGroupName = !String.IsNullOrEmpty(outboundSubnetResourceGroupName) ? outboundSubnetResourceGroupName : ResourceGroupName;
                    var outboundSubnetResourceId = NetworkClient.ValidateSubnet(outboundSubnet, VirtualNetworkName, outboundSubnetResourceGroupName, DefaultContext.Subscription.Id);

                    appServiceEnvironment.VirtualNetwork = new VirtualNetworkProfile(id: outboundSubnetResourceId);

                    // Create ASEv3
                    NetworkClient.VerifyEmptySubnet(outboundSubnetResourceId);
                    NetworkClient.EnsureSubnetDelegation(outboundSubnetResourceId, "Microsoft.Web/hostingEnvironments");
                    ase = WebsitesClient.CreateAppServiceEnvironment(ResourceGroupName, Name, appServiceEnvironment);
                    break;
                }

                if (PassThru)
                {
                    // Refresh object to get the final state
                    var ps_ase = new PSAppServiceEnvironment(WebsitesClient.GetAppServiceEnvironment(ResourceGroupName, Name));
                    WriteObject(ps_ase);
                }
            }
        }