private void CompareApplicationGateway(ApplicationGateway gw1, ApplicationGateway gw2) { // compare count of child resources Assert.AreEqual(gw1.GatewayIPConfigurations.Count, gw2.GatewayIPConfigurations.Count); Assert.AreEqual(gw1.FrontendIPConfigurations.Count, gw2.FrontendIPConfigurations.Count); Assert.AreEqual(gw1.FrontendPorts.Count, gw2.FrontendPorts.Count); Assert.AreEqual(gw1.Probes.Count, gw2.Probes.Count); Assert.AreEqual(gw1.BackendAddressPools.Count, gw2.BackendAddressPools.Count); Assert.AreEqual(gw1.BackendHttpSettingsCollection.Count, gw2.BackendHttpSettingsCollection.Count); Assert.AreEqual(gw1.HttpListeners.Count, gw2.HttpListeners.Count); Assert.AreEqual(gw1.RequestRoutingRules.Count, gw2.RequestRoutingRules.Count); Assert.AreEqual(gw1.RedirectConfigurations.Count, gw2.RedirectConfigurations.Count); Assert.AreEqual(gw1.AuthenticationCertificates.Count, gw2.AuthenticationCertificates.Count); // compare sku Assert.AreEqual(gw1.Sku.Name, gw2.Sku.Name); Assert.AreEqual(gw1.Sku.Tier, gw2.Sku.Tier); Assert.AreEqual(gw1.Sku.Capacity, gw2.Sku.Capacity); // compare connectionDraining for (int i = 0; i < gw1.BackendHttpSettingsCollection.Count; i++) { if (gw1.BackendHttpSettingsCollection[i].ConnectionDraining != null) { Assert.NotNull(gw2.BackendHttpSettingsCollection[i].ConnectionDraining); Assert.AreEqual(gw1.BackendHttpSettingsCollection[i].ConnectionDraining.Enabled, gw2.BackendHttpSettingsCollection[i].ConnectionDraining.Enabled); Assert.AreEqual(gw1.BackendHttpSettingsCollection[i].ConnectionDraining.DrainTimeoutInSec, gw2.BackendHttpSettingsCollection[i].ConnectionDraining.DrainTimeoutInSec); } else { Assert.Null(gw2.BackendHttpSettingsCollection[i].ConnectionDraining); } } //compare WAF Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.Enabled, gw2.WebApplicationFirewallConfiguration.Enabled); Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.FirewallMode, gw2.WebApplicationFirewallConfiguration.FirewallMode); Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.RuleSetType, gw2.WebApplicationFirewallConfiguration.RuleSetType); Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.RuleSetVersion, gw2.WebApplicationFirewallConfiguration.RuleSetVersion); if (gw1.WebApplicationFirewallConfiguration.DisabledRuleGroups != null) { Assert.NotNull(gw2.WebApplicationFirewallConfiguration.DisabledRuleGroups); Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.DisabledRuleGroups.Count, gw2.WebApplicationFirewallConfiguration.DisabledRuleGroups.Count); for (int i = 0; i < gw1.WebApplicationFirewallConfiguration.DisabledRuleGroups.Count; i++) { Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.DisabledRuleGroups[i].RuleGroupName, gw2.WebApplicationFirewallConfiguration.DisabledRuleGroups[i].RuleGroupName); Assert.AreEqual(gw1.WebApplicationFirewallConfiguration.DisabledRuleGroups[i].Rules, gw2.WebApplicationFirewallConfiguration.DisabledRuleGroups[i].Rules); } } else { Assert.IsEmpty(gw2.WebApplicationFirewallConfiguration.DisabledRuleGroups); } // ssl policy Assert.AreEqual(gw1.SslPolicy.PolicyType, gw2.SslPolicy.PolicyType); Assert.AreEqual(gw1.SslPolicy.PolicyName, gw2.SslPolicy.PolicyName); Assert.AreEqual(gw1.SslPolicy.MinProtocolVersion, gw2.SslPolicy.MinProtocolVersion); }
public PSApplicationGateway ToPsApplicationGateway(ApplicationGateway appGw) { var psAppGw = Mapper.Map <PSApplicationGateway>(appGw); psAppGw.Tag = TagsConversionHelper.CreateTagHashtable(appGw.Tags); return(psAppGw); }
public PSApplicationGateway ToPsApplicationGateway(ApplicationGateway appGw) { var psAppGw = NetworkResourceManagerProfile.Mapper.Map <PSApplicationGateway>(appGw); psAppGw.Tag = TagsConversionHelper.CreateTagHashtable(appGw.Tags); return(psAppGw); }
//Constructs partially populated ApplicationGatewayEntityInternal //object from ApplicationGateway object public ApplicationGatewayEntityInternal(ApplicationGateway appGw) { Name = appGw.Name; Description = appGw.Description; VnetName = appGw.VnetName; Subnets = appGw.Subnets; InstanceCount = appGw.InstanceCount; GatewaySize = appGw.GatewaySize; State = appGw.State; VirtualIPs = appGw.VirtualIPs; DnsName = appGw.DnsName; }
public void TestVMScaleSetWithApplciationGateway() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group string rgName = TestUtilities.GenerateName(TestPrefix) + 1; var vmssName = TestUtilities.GenerateName("vmss"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var vnetResponse = CreateVNETWithSubnets(rgName, 2); var gatewaySubnet = vnetResponse.Subnets[0]; var vmssSubnet = vnetResponse.Subnets[1]; ApplicationGateway appgw = CreateApplicationGateway(rgName, gatewaySubnet); Microsoft.Azure.Management.Compute.Models.SubResource backendAddressPool = new Microsoft.Azure.Management.Compute.Models.SubResource() { Id = appgw.BackendAddressPools[0].Id }; VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking( rgName: rgName, vmssName: vmssName, storageAccount: storageAccountOutput, imageRef: imageRef, inputVMScaleSet: out inputVMScaleSet, vmScaleSetCustomizer: (virtualMachineScaleSet) => virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations[0] .ApplicationGatewayBackendAddressPools.Add(backendAddressPool), createWithPublicIpAddress: false, subnet: vmssSubnet); var getGwResponse = m_NrpClient.ApplicationGateways.Get(rgName, appgw.Name); Assert.True(2 == getGwResponse.BackendAddressPools[0].BackendIPConfigurations.Count); passed = true; } finally { m_ResourcesClient.ResourceGroups.DeleteIfExists(rgName); } Assert.True(passed); } }
private void CompareApplicationGateway(ApplicationGateway gw1, ApplicationGateway gw2) { Assert.Equal(gw1.Name, gw2.Name); Assert.Equal(gw1.Sku.Name, gw2.Sku.Name); Assert.Equal(gw1.Sku.Tier, gw2.Sku.Tier); Assert.Equal(gw1.Sku.Capacity, gw2.Sku.Capacity); //Assert.Equal(gw1.GatewayIPConfigurations.Count, gw2.GatewayIPConfigurations.Count); //Assert.Equal(gw1.FrontendIPConfigurations.Count, gw2.FrontendIPConfigurations.Count); Assert.Equal(gw1.FrontendPorts.Count, gw2.FrontendPorts.Count); Assert.Equal(gw1.SslCertificates.Count, gw2.SslCertificates.Count); Assert.Equal(gw1.BackendAddressPools.Count, gw2.BackendAddressPools.Count); Assert.Equal(gw1.BackendHttpSettingsCollection.Count, gw2.BackendHttpSettingsCollection.Count); Assert.Equal(gw1.HttpListeners.Count, gw2.HttpListeners.Count); Assert.Equal(gw1.RequestRoutingRules.Count, gw2.RequestRoutingRules.Count); }
public async Task TestVMScaleSetWithApplciationGateway() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var vnetResponse = await CreateVNETWithSubnets(rgName, 2); var gatewaySubnet = vnetResponse.Subnets[0]; var vmssSubnet = vnetResponse.Subnets[1]; ApplicationGateway appgw = await CreateApplicationGateway(rgName, gatewaySubnet); Azure.ResourceManager.Compute.Models.SubResource backendAddressPool = new Azure.ResourceManager.Compute.Models.SubResource() { Id = appgw.BackendAddressPools[0].Id }; var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName : rgName, vmssName : vmssName, storageAccount : storageAccountOutput, imageRef : imageRef, vmScaleSetCustomizer : (virtualMachineScaleSet) => virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations[0] .ApplicationGatewayBackendAddressPools.Add(backendAddressPool), createWithPublicIpAddress : false, subnet : vmssSubnet); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var getGwResponse = (await ApplicationGatewaysOperations.GetAsync(rgName, appgw.Name)).Value; Assert.True(2 == getGwResponse.BackendAddressPools[0].BackendIPConfigurations.Count); passed = true; Assert.True(passed); }
public virtual ApplicationGatewaysCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (applicationGatewayName == null) { throw new ArgumentNullException(nameof(applicationGatewayName)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _clientDiagnostics.CreateScope("ApplicationGatewaysClient.StartCreateOrUpdate"); scope.Start(); try { var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, applicationGatewayName, parameters, cancellationToken); return(new ApplicationGatewaysCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, applicationGatewayName, parameters).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }
protected ApplicationGateway CreateApplicationGateway(string rgName, Subnet subnet, string gatewayName = null) { gatewayName = gatewayName ?? ComputeManagementTestUtilities.GenerateName("gw"); var gatewayIPConfigName = ComputeManagementTestUtilities.GenerateName("gwIp"); var frontendIPConfigName = ComputeManagementTestUtilities.GenerateName("fIp"); var frontendPortName = ComputeManagementTestUtilities.GenerateName("fPort"); var backendAddressPoolName = ComputeManagementTestUtilities.GenerateName("pool"); var backendHttpSettingsName = ComputeManagementTestUtilities.GenerateName("setting"); var requestRoutingRuleName = ComputeManagementTestUtilities.GenerateName("rule"); var httpListenerName = ComputeManagementTestUtilities.GenerateName("listener"); var gatewayIPConfig = new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new Microsoft.Azure.Management.Network.Models.SubResource { Id = subnet.Id }, }; var frontendIPConfig = new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, Subnet = new Microsoft.Azure.Management.Network.Models.SubResource { Id = subnet.Id } }; ApplicationGatewayFrontendPort frontendPort = new ApplicationGatewayFrontendPort() { Name = frontendPortName, Port = 80 }; var backendAddressPool = new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, }; var backendHttpSettings = new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettingsName, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled, }; var httpListener = new ApplicationGatewayHttpListener() { Name = httpListenerName, FrontendPort = new Microsoft.Azure.Management.Network.Models.SubResource { Id = GetChildAppGwResourceId(m_subId, rgName, gatewayName, "frontendPorts", frontendPortName) }, FrontendIPConfiguration = new Microsoft.Azure.Management.Network.Models.SubResource { Id = GetChildAppGwResourceId(m_subId, rgName, gatewayName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http }; var requestRoutingRules = new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRuleName, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new Microsoft.Azure.Management.Network.Models.SubResource { Id = GetChildAppGwResourceId(m_subId, rgName, gatewayName, "httpListeners", httpListenerName) }, BackendAddressPool = new Microsoft.Azure.Management.Network.Models.SubResource { Id = GetChildAppGwResourceId(m_subId, rgName, gatewayName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new Microsoft.Azure.Management.Network.Models.SubResource { Id = GetChildAppGwResourceId(m_subId, rgName, gatewayName, "backendHttpSettingsCollection", backendHttpSettingsName) } }; var appGw = new ApplicationGateway() { Location = m_location, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.StandardSmall, Tier = ApplicationGatewayTier.Standard, Capacity = 2 }, GatewayIPConfigurations = new List <ApplicationGatewayIPConfiguration>() { gatewayIPConfig, }, FrontendIPConfigurations = new List <ApplicationGatewayFrontendIPConfiguration>() { frontendIPConfig, }, FrontendPorts = new List <ApplicationGatewayFrontendPort> { frontendPort, }, BackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { backendAddressPool, }, BackendHttpSettingsCollection = new List <ApplicationGatewayBackendHttpSettings> { backendHttpSettings, }, HttpListeners = new List <ApplicationGatewayHttpListener> { httpListener, }, RequestRoutingRules = new List <ApplicationGatewayRequestRoutingRule>() { requestRoutingRules, } }; var putGwResponse = m_NrpClient.ApplicationGateways.CreateOrUpdate(rgName, gatewayName, appGw); var getGwResponse = m_NrpClient.ApplicationGateways.Get(rgName, gatewayName); return(getGwResponse); }
private ApplicationGateway CreateApplicationGateway(string location, Subnet subnet, string resourceGroupName, string appGwName, string subscriptionId) { var gatewayIPConfigName = TestUtilities.GenerateName(); var frontendIPConfigName = TestUtilities.GenerateName(); var frontendPort1Name = TestUtilities.GenerateName(); var frontendPort2Name = TestUtilities.GenerateName(); var backendAddressPoolName = TestUtilities.GenerateName(); var nicBackendAddressPoolName = TestUtilities.GenerateName(); var backendHttpSettings1Name = TestUtilities.GenerateName(); var backendHttpSettings2Name = TestUtilities.GenerateName(); var requestRoutingRule1Name = TestUtilities.GenerateName(); var requestRoutingRule2Name = TestUtilities.GenerateName(); var httpListener1Name = TestUtilities.GenerateName(); var httpListener2Name = TestUtilities.GenerateName(); var probeName = TestUtilities.GenerateName(); var sslCertName = TestUtilities.GenerateName(); var authCertName = TestUtilities.GenerateName(); //var httpListenerMultiHostingName = TestUtilities.GenerateName(); //var frontendPortMultiHostingName = TestUtilities.GenerateName(); //var urlPathMapName = TestUtilities.GenerateName(); //var imagePathRuleName = TestUtilities.GenerateName(); //var videoPathRuleName = TestUtilities.GenerateName(); //var requestRoutingRuleMultiHostingName = TestUtilities.GenerateName(); string certPath = System.IO.Path.Combine("Tests", "Data", "ApplicationGatewayAuthCert.cer"); Console.WriteLine("Certificate Path: {0}", certPath); var x509AuthCertificate = new X509Certificate2(certPath); var authCertList = new List <ApplicationGatewayAuthenticationCertificate>() { new ApplicationGatewayAuthenticationCertificate() { Name = authCertName, Data = Convert.ToBase64String(x509AuthCertificate.Export(X509ContentType.Cert)) } }; var appGw = new ApplicationGateway() { Location = location, SslPolicy = new ApplicationGatewaySslPolicy() { DisabledSslProtocols = new List <string>() { ApplicationGatewaySslProtocol.TLSv10, ApplicationGatewaySslProtocol.TLSv11 } }, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.StandardSmall, Tier = ApplicationGatewayTier.Standard, Capacity = 2 }, GatewayIPConfigurations = new List <ApplicationGatewayIPConfiguration>() { new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new SubResource() { Id = subnet.Id } } }, FrontendIPConfigurations = new List <ApplicationGatewayFrontendIPConfiguration>() { new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, Subnet = new SubResource() { Id = subnet.Id } } }, FrontendPorts = new List <ApplicationGatewayFrontendPort> { new ApplicationGatewayFrontendPort() { Name = frontendPort1Name, Port = 80 }, new ApplicationGatewayFrontendPort() { Name = frontendPort2Name, Port = 88 }, //new ApplicationGatewayFrontendPort() //{ // Name = frontendPortMultiHostingName, // Port = 8080 //} }, Probes = new List <ApplicationGatewayProbe> { new ApplicationGatewayProbe() { Name = probeName, Protocol = ApplicationGatewayProtocol.Http, Host = "probe.com", Path = "/path/path.htm", Interval = 17, Timeout = 17, UnhealthyThreshold = 5 } }, BackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = new List <ApplicationGatewayBackendAddress>() { new ApplicationGatewayBackendAddress() { IpAddress = "104.42.6.202" }, new ApplicationGatewayBackendAddress() { IpAddress = "23.99.1.115" } } }, new ApplicationGatewayBackendAddressPool() { Name = nicBackendAddressPoolName, } }, BackendHttpSettingsCollection = new List <ApplicationGatewayBackendHttpSettings> { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings1Name, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled, RequestTimeout = 69, Probe = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "probes", probeName) } }, new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings2Name, Port = 443, Protocol = ApplicationGatewayProtocol.Https, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Enabled, AuthenticationCertificates = new List <SubResource>() { new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "authenticationCertificates", authCertName) } } } }, HttpListeners = new List <ApplicationGatewayHttpListener> { new ApplicationGatewayHttpListener() { Name = httpListener1Name, FrontendPort = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort1Name) }, FrontendIPConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http }, new ApplicationGatewayHttpListener() { Name = httpListener2Name, FrontendPort = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort2Name) }, FrontendIPConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http }, //new ApplicationGatewayHttpListener() //{ // Name = httpListenerMultiHostingName, // FrontendPort = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "frontendPorts", frontendPortMultiHostingName) // }, // FrontendIPConfiguration = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) // }, // SslCertificate = null, // Protocol = ApplicationGatewayProtocol.Http //} }, //UrlPathMaps = new List<ApplicationGatewayUrlPathMap>() // { // new ApplicationGatewayUrlPathMap() // { // Name = urlPathMapName, // DefaultBackendAddressPool = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) // }, // DefaultBackendHttpSettings = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName) // }, // PathRules = new List<ApplicationGatewayPathRule>() // { // new ApplicationGatewayPathRule() // { // Name = imagePathRuleName, // Paths = new List<string>() { "/images*" }, // BackendAddressPool = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) // }, // BackendHttpSettings = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName) // } // }, // new ApplicationGatewayPathRule() // { // Name = videoPathRuleName, // Paths = new List<string>() { "/videos*" }, // BackendAddressPool = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) // }, // BackendHttpSettings = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName) // } // } // } // } // }, RequestRoutingRules = new List <ApplicationGatewayRequestRoutingRule>() { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule1Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener1Name) }, BackendAddressPool = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings1Name) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule2Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener2Name) }, BackendAddressPool = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings2Name) } }, //new ApplicationGatewayRequestRoutingRule() //{ // Name = requestRoutingRuleMultiHostingName, // RuleType = ApplicationGatewayRequestRoutingRuleType.PathBasedRouting, // HttpListener = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "httpListeners", httpListenerMultiHostingName) // }, // UrlPathMap = new SubResource() // { // Id = GetChildAppGwResourceId(subscriptionId, // resourceGroupName, appGwName, "urlPathMaps", urlPathMapName) // } //} }, AuthenticationCertificates = authCertList }; return(appGw); }
public MyStack() { var config = new Config(); var environment = Deployment.Instance.StackName; // Create an Azure Resource Group var resourceGroup = new ResourceGroup("rg", new ResourceGroupArgs { Name = NamingConvention.GetResourceGroupName(environment) }); var vnet = new VirtualNetwork("vnet", new VirtualNetworkArgs { Name = NamingConvention.GetVNetName(environment), ResourceGroupName = resourceGroup.Name, AddressSpaces = { config.Require("vnet.addressSpaces") } }); // Create a Subnet for the cluster var apimSubnet = new Subnet("apim-net", new SubnetArgs { Name = "apim-net", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = vnet.Name, AddressPrefixes = { config.Require("vnet.subnets.apim.addressPrefixes") }, }); // Create a Subnet for the afw var firewallSubnet = new Subnet("afw-net", new SubnetArgs { Name = "AzureFirewallSubnet", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = vnet.Name, AddressPrefixes = { config.Require("vnet.subnets.afw.addressPrefixes") }, }); var agwSubnet = new Subnet("agw-net", new SubnetArgs { Name = "agw-net", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = vnet.Name, AddressPrefixes = { config.Require("vnet.subnets.agw.addressPrefixes") }, }); var privateEndpointSubnet = new Subnet("functions-net", new SubnetArgs { Name = "functions-net", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = vnet.Name, AddressPrefixes = { config.Require("vnet.subnets.functions.addressPrefixes") }, }); var eventHubNamespace = new EventHubNamespace("ehn", new EventHubNamespaceArgs { Name = "iac-apim-logging-ns", Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, Sku = "Standard", Capacity = 1 }); var eventHub = new EventHub("eh", new EventHubArgs { Name = "apim-logging", NamespaceName = eventHubNamespace.Name, ResourceGroupName = resourceGroup.Name, PartitionCount = 2, MessageRetention = 1, }); var apimExternal = new Service("apim-external", new ServiceArgs { Name = "iac-dev-ext-apim", ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, PublisherName = "IaC", PublisherEmail = "*****@*****.**", SkuName = "Developer_1", Identity = new ServiceIdentityArgs { Type = "SystemAssigned" }, VirtualNetworkType = "External", VirtualNetworkConfiguration = new ServiceVirtualNetworkConfigurationArgs { SubnetId = apimSubnet.Id }, HostnameConfiguration = new ServiceHostnameConfigurationArgs { Proxies = new [] { new ServiceHostnameConfigurationProxyArgs { HostName = "iac-dev-ext-apim.azure-api.net", DefaultSslBinding = false, NegotiateClientCertificate = false }, new ServiceHostnameConfigurationProxyArgs { HostName = "api.iac-labs.com", KeyVaultId = config.Require("certificate.keyvaultid"), DefaultSslBinding = true, NegotiateClientCertificate = false }, new ServiceHostnameConfigurationProxyArgs { HostName = "api29cc67d2.iac-labs.com", KeyVaultId = config.Require("certificate.keyvaultid"), DefaultSslBinding = true, NegotiateClientCertificate = false } } } }); var apimInternal = new Service("apim-int", new ServiceArgs { Name = NamingConvention.GetApimName(environment), ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, PublisherName = "IaC", PublisherEmail = "*****@*****.**", SkuName = "Developer_1", Identity = new ServiceIdentityArgs { Type = "SystemAssigned" }, VirtualNetworkType = "Internal", VirtualNetworkConfiguration = new ServiceVirtualNetworkConfigurationArgs { SubnetId = apimSubnet.Id }, HostnameConfiguration = new ServiceHostnameConfigurationArgs { Proxies = new [] { new ServiceHostnameConfigurationProxyArgs { HostName = "iac-dev-apim.azure-api.net", DefaultSslBinding = false, NegotiateClientCertificate = false }, new ServiceHostnameConfigurationProxyArgs { HostName = "api.iac-labs.com", KeyVaultId = config.Require("certificate.keyvaultid"), DefaultSslBinding = true, NegotiateClientCertificate = false }, new ServiceHostnameConfigurationProxyArgs { HostName = "api29cc67d2.iac-labs.com", KeyVaultId = config.Require("certificate.keyvaultid"), DefaultSslBinding = true, NegotiateClientCertificate = false }, new ServiceHostnameConfigurationProxyArgs { HostName = "api-internal.iac-labs.com", KeyVaultId = config.Require("certificate.keyvaultid"), DefaultSslBinding = true, NegotiateClientCertificate = false } } } }); var apim1 = Output.Create(GetService.InvokeAsync(new GetServiceArgs { Name = "iac-dev-apim1", ResourceGroupName = "iac-dev-rg", })); if (config.RequireBoolean("firstTimeAPIM")) { var apimInternal1 = new Service("apim-int1", new ServiceArgs { Name = "iac-dev-apim1", ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, PublisherName = "IaC", PublisherEmail = "*****@*****.**", SkuName = "Developer_1", Identity = new ServiceIdentityArgs { Type = "SystemAssigned" }, VirtualNetworkType = "Internal", VirtualNetworkConfiguration = new ServiceVirtualNetworkConfigurationArgs { SubnetId = apimSubnet.Id } }); } else { var apimInternal1 = new Service("apim-int1", new ServiceArgs { Name = "iac-dev-apim1", ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, PublisherName = "IaC", PublisherEmail = "*****@*****.**", SkuName = "Developer_1", Identity = new ServiceIdentityArgs { Type = "SystemAssigned" }, VirtualNetworkType = "Internal", VirtualNetworkConfiguration = new ServiceVirtualNetworkConfigurationArgs { SubnetId = apimSubnet.Id }, HostnameConfiguration = new ServiceHostnameConfigurationArgs { Proxies = new [] { new ServiceHostnameConfigurationProxyArgs { HostName = "iac-dev-apim1.azure-api.net", DefaultSslBinding = false, NegotiateClientCertificate = false }, new ServiceHostnameConfigurationProxyArgs { HostName = "api.iac-labs.com", KeyVaultId = config.Require("certificate.keyvaultid"), DefaultSslBinding = true, NegotiateClientCertificate = false }, } } }); } var ehLogger = new Logger("ehLogger", new LoggerArgs { Name = "ehLogger", ResourceGroupName = resourceGroup.Name, ApiManagementName = apimInternal.Name, Eventhub = new LoggerEventhubArgs { Name = eventHub.Name, ConnectionString = eventHubNamespace.DefaultPrimaryConnectionString } }); var agwName = NamingConvention.GetAGWName("api", environment); var agwPublicIp = new PublicIp("agw-api-pip", new PublicIpArgs { Name = NamingConvention.GetPublicIpName("agw-api", environment), ResourceGroupName = resourceGroup.Name, Sku = "Standard", AllocationMethod = "Static", DomainNameLabel = agwName }); var agwMI = new UserAssignedIdentity("agw-mi", new UserAssignedIdentityArgs { Name = NamingConvention.GetManagedIdentityName("agw", environment), ResourceGroupName = resourceGroup.Name }); var apiAgw = new ApplicationGateway("agw-api", new ApplicationGatewayArgs { Name = agwName, ResourceGroupName = resourceGroup.Name, Identity = new ApplicationGatewayIdentityArgs { Type = "UserAssigned", IdentityIds = agwMI.Id }, Sku = new ApplicationGatewaySkuArgs { Name = "WAF_v2", Tier = "WAF_v2", Capacity = 1 }, SslCertificates = new [] { new ApplicationGatewaySslCertificateArgs { Name = "gateway-listener", KeyVaultSecretId = config.Require("certificate.keyvaultid") } }, FrontendPorts = new [] { new ApplicationGatewayFrontendPortArgs { Name = "port443", Port = 443 }, new ApplicationGatewayFrontendPortArgs { Name = "port80", Port = 80 } }, GatewayIpConfigurations = new [] { new ApplicationGatewayGatewayIpConfigurationArgs { Name = "appGatewayIpConfig", SubnetId = agwSubnet.Id } }, FrontendIpConfigurations = new [] { new ApplicationGatewayFrontendIpConfigurationArgs { Name = "frontendIP", PublicIpAddressId = agwPublicIp.Id } }, HttpListeners = new [] { new ApplicationGatewayHttpListenerArgs { Name = "default", FrontendIpConfigurationName = "frontendIP", FrontendPortName = "port443", Protocol = "Https", HostName = "api.iac-labs.com", RequireSni = true, SslCertificateName = "gateway-listener" } }, BackendAddressPools = new[] { new ApplicationGatewayBackendAddressPoolArgs { Name = "apim", IpAddresses = apimInternal.PrivateIpAddresses //config.RequireSecret("apim.backend.ip") } }, Probes = new[] { new ApplicationGatewayProbeArgs { Name = "apim-probe-default", Protocol = "Https", Path = "/status-0123456789abcdef", Host = "api.iac-labs.com", Interval = 30, Timeout = 120, UnhealthyThreshold = 8, PickHostNameFromBackendHttpSettings = false, MinimumServers = 0 } }, BackendHttpSettings = new [] { new ApplicationGatewayBackendHttpSettingArgs { Name = "apim-settings-default", Port = 443, Protocol = "Https", CookieBasedAffinity = "Disabled", PickHostNameFromBackendAddress = false, RequestTimeout = 30, ProbeName = "apim-probe-default" } }, RequestRoutingRules = new[] { new ApplicationGatewayRequestRoutingRuleArgs { Name = "default", RuleType = "Basic", HttpListenerName = "default", BackendAddressPoolName = "apim", BackendHttpSettingsName = "apim-settings-default" } } }); // var la = new AnalyticsWorkspace("la", new AnalyticsWorkspaceArgs // { // Name = NamingConvention.GetLogAnalyticsName(environment), // ResourceGroupName = resourceGroup.Name, // Location = resourceGroup.Location, // Sku = "PerGB2018" // }); // var firewallName = NamingConvention.GetFirewallName(environment); // // var afwPublicIp = new PublicIp("afw-pip", new PublicIpArgs // { // Location = resourceGroup.Location, // ResourceGroupName = resourceGroup.Name, // AllocationMethod = "Static", // Sku = "Standard", // DomainNameLabel = firewallName // }); // // var afw = new Firewall("afw", new FirewallArgs // { // Name = firewallName, // Location = resourceGroup.Location, // ResourceGroupName = resourceGroup.Name, // IpConfigurations = // { // new FirewallIpConfigurationArgs // { // Name = "configuration", // SubnetId = firewallSubnet.Id, // PublicIpAddressId = afwPublicIp.Id, // }, // }, // }); // // var afwNatRuleCollection = new FirewallNatRuleCollection("apim-dnat", new FirewallNatRuleCollectionArgs // { // Name = "apim-dnat", // AzureFirewallName = afw.Name, // ResourceGroupName = resourceGroup.Name, // Priority = 100, // Action = "Dnat", // Rules = // { // new FirewallNatRuleCollectionRuleArgs // { // Name = "apim", // SourceAddresses = "*", // DestinationPorts = // { // "443", // }, // DestinationAddresses = // { // afwPublicIp.IpAddress, // }, // TranslatedPort = "443", // TranslatedAddress = apimInternal.PrivateIpAddresses.First(), // Protocols = // { // "UDP", // "TCP", // } // } // } // }); // var afwDiagnosticSetting = new DiagnosticSetting("afw-diagnostics", new DiagnosticSettingArgs // { // Name = "diagnostics", // TargetResourceId = afw.Id, // LogAnalyticsWorkspaceId = la.Id, // Logs = // { // new DiagnosticSettingLogArgs // { // Category = "AzureFirewallApplicationRule", // Enabled = true, // RetentionPolicy = new DiagnosticSettingLogRetentionPolicyArgs // { // Enabled = false // } // }, // new DiagnosticSettingLogArgs // { // Category = "AzureFirewallNetworkRule", // Enabled = true, // RetentionPolicy = new DiagnosticSettingLogRetentionPolicyArgs // { // Enabled = false // } // }, // new DiagnosticSettingLogArgs // { // Category = "AzureFirewallDnsProxy", // Enabled = true, // RetentionPolicy = new DiagnosticSettingLogRetentionPolicyArgs // { // Enabled = false, // } // } // }, // Metrics = // { // new DiagnosticSettingMetricArgs // { // Category = "AllMetrics", // Enabled = true, // RetentionPolicy = new DiagnosticSettingMetricRetentionPolicyArgs // { // Enabled = false, // } // } // } // }); }
/// <summary> /// The Put ApplicationGateway operation creates/updates a /// ApplicationGateway /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Network.IApplicationGatewayOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='applicationGatewayName'> /// Required. The name of the ApplicationGateway. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create/update /// ApplicationGateway operation /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request and error information regarding /// the failure. /// </returns> public static AzureAsyncOperationResponse CreateOrUpdate(this IApplicationGatewayOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters) { return(Task.Factory.StartNew((object s) => { return ((IApplicationGatewayOperations)s).CreateOrUpdateAsync(resourceGroupName, applicationGatewayName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
private ApplicationGateway CreateApplicationGateway(string location, Subnet subnet, string resourceGroupName, string subscriptionId) { var appGwName = TestUtilities.GenerateName(); var gatewayIPConfigName = TestUtilities.GenerateName(); var frontendIPConfigName = TestUtilities.GenerateName(); var frontendPortName = TestUtilities.GenerateName(); var backendAddressPoolName = TestUtilities.GenerateName(); var backendHttpSettingsName = TestUtilities.GenerateName(); var requestRoutingRuleName = TestUtilities.GenerateName(); var httpListenerName = TestUtilities.GenerateName(); var appGw = new ApplicationGateway() { Location = location, Name = appGwName, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.StandardSmall, Tier = ApplicationGatewayTier.Standard, Capacity = 2 }, GatewayIPConfigurations = new List <ApplicationGatewayIPConfiguration>() { new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new ResourceId() { Id = subnet.Id } } }, FrontendIPConfigurations = new List <ApplicationGatewayFrontendIPConfiguration>() { new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IpAllocationMethod.Dynamic, Subnet = new ResourceId() { Id = subnet.Id } } }, FrontendPorts = new List <ApplicationGatewayFrontendPort> { new ApplicationGatewayFrontendPort() { Name = frontendPortName, Port = 80 } }, BackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = new List <ApplicationGatewayBackendAddress>() { new ApplicationGatewayBackendAddress() { IpAddress = "104.42.6.202" }, new ApplicationGatewayBackendAddress() { IpAddress = "23.99.1.115" } } } }, BackendHttpSettingsCollection = new List <ApplicationGatewayBackendHttpSettings> { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettingsName, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled } }, HttpListeners = new List <ApplicationGatewayHttpListener> { new ApplicationGatewayHttpListener() { Name = httpListenerName, FrontendPort = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPortName) }, FrontendIPConfiguration = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http } }, RequestRoutingRules = new List <ApplicationGatewayRequestRoutingRule>() { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRuleName, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListenerName) }, BackendAddressPool = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName) } } } }; return(appGw); }
public MyStack() { // Retrieve options from config, optionally using defaults var config = new Pulumi.Config(); var region = config.Get("region") ?? "CentralUS"; // App Gateway Options InputList <string> addressSpace = (config.Get("addressSpace") ?? "10.0.0.0/16").Split(','); var privateSubnetPrefix = config.Get("privateSubnet") ?? "10.0.2.0/24"; var publicSubnetPrefix = config.Get("publicSubnet") ?? "10.0.1.0/24"; var dnsPrefix = config.Get("dnsPrefix") ?? "aspnettodo"; var backendPort = config.GetInt32("backendPort") ?? 80; var backendProtocol = config.Get("backendProtocol") ?? "HTTP"; var frontendPort = config.GetInt32("frontendPort") ?? backendPort; var frontendProtocol = config.Get("frontendProtocol") ?? backendProtocol; // VMSS options var instanceCount = config.GetInt32("instanceCount") ?? 2; InputList <string> zones = (config.Get("zones") ?? "1,2").Split(','); var instanceSize = config.Get("instanceSize") ?? "Standard_B1s"; var instanceNamePrefix = config.Get("instanceNamePrefix") ?? "web"; var adminUser = config.Get("adminUser") ?? "webadmin"; var adminPassword = config.Get("adminPassword"); // Create an Azure Resource Group var resourceGroup = new ResourceGroup($"{stackId}-rg", new ResourceGroupArgs { Location = region }); // Create Networking components var vnet = new VirtualNetwork($"{stackId}-vnet", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, AddressSpaces = addressSpace }); // Create a private subnet for the VMSS var privateSubnet = new Subnet($"{stackId}-privateSubnet", new SubnetArgs { ResourceGroupName = resourceGroup.Name, AddressPrefix = privateSubnetPrefix, VirtualNetworkName = vnet.Name }); // Create a public subnet for the Application Gateway var publicSubnet = new Subnet($"{stackId}-publicSubnet", new SubnetArgs { ResourceGroupName = resourceGroup.Name, AddressPrefix = publicSubnetPrefix, VirtualNetworkName = vnet.Name }); // Create a public IP and App Gateway var publicIp = new PublicIp($"{stackId}-pip", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, Sku = "Basic", AllocationMethod = "Dynamic", DomainNameLabel = dnsPrefix }, new CustomResourceOptions { DeleteBeforeReplace = true }); var appGw = new ApplicationGateway($"{stackId}-appgw", new ApplicationGatewayArgs { ResourceGroupName = resourceGroup.Name, Sku = new ApplicationGatewaySkuArgs { Tier = "Standard", Name = "Standard_Small", Capacity = 1 }, FrontendIpConfigurations = new InputList <Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendIpConfigurationsArgs> { new Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendIpConfigurationsArgs { Name = $"{stackId}-appgw-ipconfig-0", PublicIpAddressId = publicIp.Id, } }, FrontendPorts = new InputList <Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendPortsArgs> { new Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendPortsArgs { Name = $"Port{frontendPort}", Port = frontendPort } }, BackendAddressPools = new InputList <Pulumi.Azure.Network.Inputs.ApplicationGatewayBackendAddressPoolsArgs> { new Pulumi.Azure.Network.Inputs.ApplicationGatewayBackendAddressPoolsArgs { Name = $"{stackId}-bepool-0", } }, BackendHttpSettings = new InputList <ApplicationGatewayBackendHttpSettingsArgs> { new ApplicationGatewayBackendHttpSettingsArgs { Name = $"{backendProtocol}Settings", Protocol = backendProtocol, Port = backendPort, CookieBasedAffinity = "Disabled" } }, GatewayIpConfigurations = new InputList <ApplicationGatewayGatewayIpConfigurationsArgs> { new ApplicationGatewayGatewayIpConfigurationsArgs { Name = "IPConfiguration", SubnetId = publicSubnet.Id } }, HttpListeners = new InputList <ApplicationGatewayHttpListenersArgs> { new ApplicationGatewayHttpListenersArgs { Name = $"{frontendProtocol}Listener", Protocol = frontendProtocol, FrontendIpConfigurationName = $"{stackId}-appgw-ipconfig-0", FrontendPortName = $"Port{frontendPort}" } }, RequestRoutingRules = new InputList <ApplicationGatewayRequestRoutingRulesArgs> { new ApplicationGatewayRequestRoutingRulesArgs { Name = "Default", BackendAddressPoolName = $"{stackId}-bepool-0", HttpListenerName = $"{frontendProtocol}Listener", RuleType = "Basic", BackendHttpSettingsName = $"{backendProtocol}Settings" } } }); // Create the scale set var scaleSet = new ScaleSet($"{stackId}-vmss", new ScaleSetArgs { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Zones = new InputList <string> { "1", "2" }, NetworkProfiles = { new ScaleSetNetworkProfilesArgs { AcceleratedNetworking = false, IpConfigurations = { new ScaleSetNetworkProfilesIpConfigurationsArgs { Name = "IPConfiguration", Primary = true, SubnetId = privateSubnet.Id, // Associate scaleset with app gateway ApplicationGatewayBackendAddressPoolIds = new InputList <string> { appGw.BackendAddressPools.Apply(bePools => bePools[0].Id) } } }, Name = "networkprofile", Primary = true } }, OsProfile = new ScaleSetOsProfileArgs { AdminUsername = adminUser, AdminPassword = adminPassword, ComputerNamePrefix = instanceNamePrefix }, Sku = new ScaleSetSkuArgs { Capacity = instanceCount, Name = instanceSize, Tier = "Standard", }, StorageProfileImageReference = new ScaleSetStorageProfileImageReferenceArgs { Offer = "WindowsServer", Publisher = "MicrosoftWindowsServer", Sku = "2019-Datacenter-Core", Version = "latest", }, StorageProfileOsDisk = new ScaleSetStorageProfileOsDiskArgs { Caching = "ReadWrite", CreateOption = "FromImage", ManagedDiskType = "Standard_LRS", Name = "", }, // Enable VM agent and script extension UpgradePolicyMode = "Automatic", OsProfileWindowsConfig = new ScaleSetOsProfileWindowsConfigArgs { ProvisionVmAgent = true }, Extensions = new InputList <ScaleSetExtensionsArgs> { new ScaleSetExtensionsArgs { Publisher = "Microsoft.Compute", Name = "IIS-Script-Extension", Type = "CustomScriptExtension", TypeHandlerVersion = "1.4", // Settings is a JSON string // This command uses powershell to install windows webserver features Settings = "{\"commandToExecute\":\"powershell Add-WindowsFeature Web-Server,Web-Asp-Net45,NET-Framework-Features\"}" } } }); this.PublicUrl = publicIp.Fqdn; }
/// <summary> /// The Put ApplicationGateway operation creates/updates a /// ApplicationGateway /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Network.IApplicationGatewayOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='applicationGatewayName'> /// Required. The name of the ApplicationGateway. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create/delete /// ApplicationGateway operation /// </param> /// <returns> /// Response of Put ApplicationGateway operation /// </returns> public static Task <ApplicationGatewayPutResponse> BeginCreateOrUpdatingAsync(this IApplicationGatewayOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters) { return(operations.BeginCreateOrUpdatingAsync(resourceGroupName, applicationGatewayName, parameters, CancellationToken.None)); }
public async Task ApplicationGatewayApiTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = "West US"; await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); string vnetName = Recording.GenerateAssetName("azsmnet"); string gwSubnetName = Recording.GenerateAssetName("azsmnet"); string subnet2Name = Recording.GenerateAssetName("azsmnet"); string appGwName = Recording.GenerateAssetName("azsmnet"); VirtualNetwork vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = { "10.1.1.1", "10.1.2.4" } }, Subnets = { new Subnet() { Name = gwSubnetName, AddressPrefix = "10.0.0.0/24" }, new Subnet() { Name = subnet2Name, AddressPrefix = "10.0.1.0/24" } } }; VirtualNetworksCreateOrUpdateOperation putVnetResponseOperation = await NetworkManagementClient.VirtualNetworks.StartCreateOrUpdateAsync(resourceGroupName, vnetName, vnet); await WaitForCompletionAsync(putVnetResponseOperation); Response <VirtualNetwork> getVnetResponse = await NetworkManagementClient.VirtualNetworks.GetAsync(resourceGroupName, vnetName); Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, gwSubnetName); Console.WriteLine("Virtual Network GatewaySubnet Id: {0}", getSubnetResponse.Value.Id); Response <Subnet> gwSubnet = getSubnetResponse; ApplicationGateway appGw = CreateApplicationGateway(location, gwSubnet, resourceGroupName, appGwName, TestEnvironment.SubscriptionId); // Put AppGw Operation <ApplicationGateway> putAppGw = await NetworkManagementClient.ApplicationGateways.StartCreateOrUpdateAsync(resourceGroupName, appGwName, appGw); Response <ApplicationGateway> putAppGwResponse = await WaitForCompletionAsync(putAppGw); Assert.AreEqual("Succeeded", putAppGwResponse.Value.ProvisioningState.ToString()); // Get AppGw Response <ApplicationGateway> getGateway = await NetworkManagementClient.ApplicationGateways.GetAsync(resourceGroupName, appGwName); Assert.AreEqual(appGwName, getGateway.Value.Name); CompareApplicationGateway(appGw, getGateway); // Get available WAF rule sets (validate first result set/group) Response <ApplicationGatewayAvailableWafRuleSetsResult> availableWAFRuleSets = await NetworkManagementClient.ApplicationGateways.ListAvailableWafRuleSetsAsync(); Assert.NotNull(availableWAFRuleSets); Assert.IsNotEmpty(availableWAFRuleSets.Value.Value); Assert.NotNull(availableWAFRuleSets.Value.Value[0].Name); Assert.NotNull(availableWAFRuleSets.Value.Value[0].RuleSetType); Assert.NotNull(availableWAFRuleSets.Value.Value[0].RuleSetVersion); Assert.IsNotEmpty(availableWAFRuleSets.Value.Value[0].RuleGroups); Assert.NotNull(availableWAFRuleSets.Value.Value[0].RuleGroups[0].RuleGroupName); Assert.IsNotEmpty(availableWAFRuleSets.Value.Value[0].RuleGroups[0].Rules); // Assert.NotNull(availableWAFRuleSets.Value[0].RuleGroups[0].Rules[0].RuleId); // Get availalbe SSL options Response <ApplicationGatewayAvailableSslOptions> sslOptions = await NetworkManagementClient.ApplicationGateways.ListAvailableSslOptionsAsync(); Assert.NotNull(sslOptions.Value.DefaultPolicy); Assert.NotNull(sslOptions.Value.AvailableCipherSuites); Assert.NotNull(sslOptions.Value.AvailableCipherSuites[20]); AsyncPageable <ApplicationGatewaySslPredefinedPolicy> policies = NetworkManagementClient.ApplicationGateways.ListAvailableSslPredefinedPoliciesAsync(); IAsyncEnumerator <ApplicationGatewaySslPredefinedPolicy> enumerator = policies.GetAsyncEnumerator(); Assert.True(enumerator.MoveNextAsync().Result); Assert.NotNull(enumerator.Current.Name); Task <Response <ApplicationGatewaySslPredefinedPolicy> > policy = NetworkManagementClient.ApplicationGateways.GetSslPredefinedPolicyAsync(ApplicationGatewaySslPolicyName.AppGwSslPolicy20150501.ToString()); Assert.NotNull(policy.Result.Value.MinProtocolVersion); Assert.NotNull(policy.Result.Value.CipherSuites); Assert.NotNull(policy.Result.Value.CipherSuites[20]); // Create Nics string nic1name = Recording.GenerateAssetName("azsmnet"); string nic2name = Recording.GenerateAssetName("azsmnet"); Task <NetworkInterface> nic1 = CreateNetworkInterface( nic1name, resourceGroupName, null, getVnetResponse.Value.Subnets[1].Id, location, "ipconfig", NetworkManagementClient); Task <NetworkInterface> nic2 = CreateNetworkInterface( nic2name, resourceGroupName, null, getVnetResponse.Value.Subnets[1].Id, location, "ipconfig", NetworkManagementClient); // Add NIC to application gateway backend address pool. nic1.Result.IpConfigurations[0].ApplicationGatewayBackendAddressPools.Add(getGateway.Value.BackendAddressPools[1]); nic2.Result.IpConfigurations[0].ApplicationGatewayBackendAddressPools.Add(getGateway.Value.BackendAddressPools[1]); // Put Nics NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation1 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic1name, nic1.Result); await WaitForCompletionAsync(createOrUpdateOperation1); NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation2 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic2name, nic2.Result); await WaitForCompletionAsync(createOrUpdateOperation2); // Get AppGw backend health Operation <ApplicationGatewayBackendHealth> backendHealthOperation = await NetworkManagementClient.ApplicationGateways.StartBackendHealthAsync(resourceGroupName, appGwName, "true"); Response <ApplicationGatewayBackendHealth> backendHealth = await WaitForCompletionAsync(backendHealthOperation); Assert.AreEqual(2, backendHealth.Value.BackendAddressPools.Count); Assert.AreEqual(1, backendHealth.Value.BackendAddressPools[0].BackendHttpSettingsCollection.Count); Assert.AreEqual(1, backendHealth.Value.BackendAddressPools[1].BackendHttpSettingsCollection.Count); Assert.True(backendHealth.Value.BackendAddressPools[1].BackendAddressPool.BackendIPConfigurations.Any()); //Start AppGw await NetworkManagementClient.ApplicationGateways.StartStartAsync(resourceGroupName, appGwName); // Get AppGw and make sure nics are added to backend getGateway = await NetworkManagementClient.ApplicationGateways.GetAsync(resourceGroupName, appGwName); Assert.AreEqual(2, getGateway.Value.BackendAddressPools[1].BackendIPConfigurations.Count); //Stop AppGw await NetworkManagementClient.ApplicationGateways.StartStopAsync(resourceGroupName, appGwName); // Delete AppGw await NetworkManagementClient.ApplicationGateways.StartDeleteAsync(resourceGroupName, appGwName); }
private void BuildAppGateway() { var examplePublicIp = new PublicIp("examplePublicIp2", new PublicIpArgs { ResourceGroupName = _ResourceGroup.Name, Location = _ResourceGroup.Location, AllocationMethod = "Dynamic", }); var backendAddressPoolName = _vnet.Name.Apply(name => $"{name}-beap"); var frontendPortName = _vnet.Name.Apply(name => $"{name}-feport"); var frontendIpConfigurationName = _vnet.Name.Apply(name => $"{name}-feip"); var httpSettingName = _vnet.Name.Apply(name => $"{name}-be-htst"); var listenerName = _vnet.Name.Apply(name => $"{name}-httplstn"); var requestRoutingRuleName = _vnet.Name.Apply(name => $"{name}-rqrt"); var redirectConfigurationName = _vnet.Name.Apply(name => $"{name}-rdrcfg"); var appGtwy = new ApplicationGateway("appGtwy12", new ApplicationGatewayArgs { Name = "appGtwy12", ResourceGroupName = _ResourceGroup.Name, Location = _ResourceGroup.Location, Sku = new ApplicationGatewaySkuArgs { Name = "Standard_Small", Tier = "Standard", Capacity = 2, }, GatewayIpConfigurations = { new ApplicationGatewayGatewayIpConfigurationArgs { Name = "my-gateway-ip-configuration", SubnetId = _Subnets["AppGtwySubnet"].Id, }, }, FrontendPorts = { new ApplicationGatewayFrontendPortArgs { Name = frontendPortName, Port = 80, }, }, FrontendIpConfigurations = { new ApplicationGatewayFrontendIpConfigurationArgs { Name = frontendIpConfigurationName, PublicIpAddressId = examplePublicIp.Id, }, }, BackendAddressPools = { new ApplicationGatewayBackendAddressPoolArgs { Name = backendAddressPoolName, }, }, BackendHttpSettings = { new ApplicationGatewayBackendHttpSettingArgs { Name = httpSettingName, CookieBasedAffinity = "Disabled", Path = "/path1/", Port = 80, Protocol = "Http", RequestTimeout = 60, }, }, HttpListeners = { new ApplicationGatewayHttpListenerArgs { Name = listenerName, FrontendIpConfigurationName = frontendIpConfigurationName, FrontendPortName = frontendPortName, Protocol = "Http", }, }, RequestRoutingRules = { new ApplicationGatewayRequestRoutingRuleArgs { Name = requestRoutingRuleName, RuleType = "Basic", HttpListenerName = listenerName, BackendAddressPoolName = backendAddressPoolName, BackendHttpSettingsName = httpSettingName, }, }, }); }
private void TestVMScaleSetAppGwWithASTests( MockContext context, string priority, string evictionPolicy = null, string vmssSkuTier = "Standard", string vmssASMin = "1", string vmssASMax = "100", string vmssSize = VirtualMachineSizeTypes.StandardA1, bool hasManagedDisks = false, bool hasSPG = true, int vmssSkuCapacity = 2, int AppGWMin = 2, int AppGWMax = 10 ) { string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); // Create resource group var rgName = TestUtilities.GenerateName(TestPrefix); var vmssName = TestUtilities.GenerateName("vmss"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; try { Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "centralus"); EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist"); // AppGW Configuration var vnetResponse = CreateVNETWithSubnets(rgName, 2); var gatewaySubnet = vnetResponse.Subnets[0]; var vmssSubnet = vnetResponse.Subnets[1]; ApplicationGateway appgw = CreateApplicationGateway(rgName, gatewaySubnet); appgw.AutoscaleConfiguration = new ApplicationGatewayAutoscaleConfiguration(AppGWMin, AppGWMax); Microsoft.Azure.Management.Compute.Models.SubResource backendAddressPool = new Microsoft.Azure.Management.Compute.Models.SubResource() { Id = appgw.BackendAddressPools[0].Id }; var getResponse = CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, out inputVMScaleSet, null, (vmScaleSet) => { vmScaleSet.Overprovision = true; vmScaleSet.VirtualMachineProfile.Priority = priority; vmScaleSet.VirtualMachineProfile.EvictionPolicy = evictionPolicy; vmScaleSet.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations[0] .ApplicationGatewayBackendAddressPools.Add(backendAddressPool); vmScaleSet.Sku.Name = vmssSize; vmScaleSet.Sku.Tier = vmssSkuTier; vmScaleSet.Sku.Capacity = vmssSkuCapacity; }, machineSizeType: vmssSize, createWithManagedDisks: hasManagedDisks, singlePlacementGroup: hasSPG, subnet: vmssSubnet); AutoscaleSettingResource resource = CreateAutoscale(rgName, vmssName, "VMSS", vmssASMin, vmssASMax); var getGwResponse = m_NrpClient.ApplicationGateways.Get(rgName, appgw.Name); Assert.True(2 == getGwResponse.BackendAddressPools[0].BackendIPConfigurations.Count); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks); var getInstanceViewResponse = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName); Assert.NotNull(getInstanceViewResponse); ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse); var listResponse = m_CrpClient.VirtualMachineScaleSets.List(rgName); ValidateVMScaleSet( inputVMScaleSet, listResponse.FirstOrDefault(x => x.Name == vmssName), hasManagedDisks); var listSkusResponse = m_CrpClient.VirtualMachineScaleSets.ListSkus(rgName, vmssName); Assert.NotNull(listSkusResponse); Assert.NotNull(resource); Assert.False(listSkusResponse.Count() == 0); Assert.Same(inputVMScaleSet.VirtualMachineProfile.Priority.ToString(), priority); m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmssName); passed = true; } finally { Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); //Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose //of the test to cover deletion. CSM does persistent retrying over all RG resources. m_ResourcesClient.ResourceGroups.Delete(rgName); } Assert.True(passed); }
/// <summary> /// The Put ApplicationGateway operation creates/updates a ApplicationGateway /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='applicationGatewayName'> /// The name of the ApplicationGateway. /// </param> /// <param name='parameters'> /// Parameters supplied to the create/delete ApplicationGateway operation /// </param> public static ApplicationGateway BeginCreateOrUpdate(this IApplicationGatewaysOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters) { return(Task.Factory.StartNew(s => ((IApplicationGatewaysOperations)s).BeginCreateOrUpdateAsync(resourceGroupName, applicationGatewayName, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Creates or updates the specified application gateway. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='applicationGatewayName'> /// The name of the application gateway. /// </param> /// <param name='parameters'> /// Parameters supplied to the create or update application gateway operation. /// </param> public static ApplicationGateway BeginCreateOrUpdate(this IApplicationGatewaysOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters) { return(operations.BeginCreateOrUpdateAsync(resourceGroupName, applicationGatewayName, parameters).GetAwaiter().GetResult()); }
private ApplicationGateway CreateApplicationGateway() { var appGwName = "azsmnet_appGw"; var gatewayIpConfigName = "azsmnet_gatewayIpConfigName"; var frontendIpConfigName = "azsmnet_frontendIpConfigName"; var frontendPortName = "azsmnet_frontendPortName"; var backendAddressPoolName = "azsmnet_backendAddressPoolName"; var backendHttpSettingsName = "azsmnet_backendHttpSettingsName"; var requestRoutingRuleName = "azsmnet_requestRoutingRuleName"; var httpListenerName = "azsmnet_httpListenerName"; var appGw = new ApplicationGateway() { Location = location, Name = appGwName, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.StandardMedium, Tier = ApplicationGatewayTier.Standard, Capacity = 2 }, GatewayIpConfigurations = new List <ApplicationGatewayIpConfiguration>() { new ApplicationGatewayIpConfiguration() { Name = gatewayIpConfigName, Subnet = new ResourceId() { Id = subnet.Id } } }, FrontendIpConfigurations = new List <ApplicationGatewayFrontendIpConfiguration>() { new ApplicationGatewayFrontendIpConfiguration() { Name = frontendIpConfigName, PrivateIpAllocationMethod = IpAllocationMethod.Dynamic, Subnet = new ResourceId() { Id = subnet.Id } } }, FrontendPorts = new List <ApplicationGatewayFrontendPort> { new ApplicationGatewayFrontendPort() { Name = frontendPortName, Port = 80 } }, BackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = new List <ApplicationGatewayBackendAddress>() { new ApplicationGatewayBackendAddress() { IpAddress = "10.2.0.1" }, new ApplicationGatewayBackendAddress() { IpAddress = "10.2.0.2" } } } }, BackendHttpSettingsCollection = new List <ApplicationGatewayBackendHttpSettings> { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettingsName, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Enabled } }, HttpListeners = new List <ApplicationGatewayHttpListener> { new ApplicationGatewayHttpListener() { Name = httpListenerName, FrontendPort = new ResourceId() { Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPortName) }, FrontendIpConfiguration = new ResourceId() { Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIpConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http } }, RequestRoutingRules = new List <ApplicationGatewayRequestRoutingRule>() { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRuleName, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new ResourceId() { Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId, resourceGroupName, appGwName, "httpListeners", httpListenerName) }, BackendAddressPool = new ResourceId() { Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new ResourceId() { Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName) } } } }; return(appGw); }
private ApplicationGateway CreateApplicationGateway(string location, Subnet subnet, string resourceGroupName, string appGwName, string subscriptionId) { string gatewayIPConfigName = Recording.GenerateAssetName("azsmnet"); string frontendIPConfigName = Recording.GenerateAssetName("azsmnet"); string frontendPort1Name = Recording.GenerateAssetName("azsmnet"); string frontendPort2Name = Recording.GenerateAssetName("azsmnet"); string frontendPort3Name = Recording.GenerateAssetName("azsmnet"); string frontendPort4Name = Recording.GenerateAssetName("azsmnet"); string backendAddressPoolName = Recording.GenerateAssetName("azsmnet"); string nicBackendAddressPoolName = Recording.GenerateAssetName("azsmnet"); string backendHttpSettings1Name = Recording.GenerateAssetName("azsmnet"); string backendHttpSettings2Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule1Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule2Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule3Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule4Name = Recording.GenerateAssetName("azsmnet"); string httpListener1Name = Recording.GenerateAssetName("azsmnet"); string httpListener2Name = Recording.GenerateAssetName("azsmnet"); string httpListener3Name = Recording.GenerateAssetName("azsmnet"); string httpListener4Name = Recording.GenerateAssetName("azsmnet"); string probeName = Recording.GenerateAssetName("azsmnet"); string sslCertName = Recording.GenerateAssetName("azsmnet"); string authCertName = Recording.GenerateAssetName("azsmnet"); string redirectConfiguration1Name = Recording.GenerateAssetName("azsmnet"); string redirectConfiguration2Name = Recording.GenerateAssetName("azsmnet"); string urlPathMapName = Recording.GenerateAssetName("azsmnet"); string pathRuleName = Recording.GenerateAssetName("azsmnet"); ApplicationGateway appGw = new ApplicationGateway() { Location = location, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.WAFMedium, Tier = ApplicationGatewayTier.WAF, Capacity = 2 }, GatewayIPConfigurations = { new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new SubResource() { Id = subnet.Id } } }, FrontendIPConfigurations = { new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, Subnet = new SubResource() { Id = subnet.Id } } }, FrontendPorts = { new ApplicationGatewayFrontendPort() { Name = frontendPort1Name, Port = 80 }, new ApplicationGatewayFrontendPort() { Name = frontendPort2Name, Port = 443 }, new ApplicationGatewayFrontendPort() { Name = frontendPort3Name, Port = 8080 }, new ApplicationGatewayFrontendPort() { Name = frontendPort4Name, Port = 8081 } }, Probes = { new ApplicationGatewayProbe() { Name = probeName, Protocol = ApplicationGatewayProtocol.Http, Path = "/path/path.htm", Interval = 17, Timeout = 17, UnhealthyThreshold = 5, PickHostNameFromBackendHttpSettings = true, Match = new ApplicationGatewayProbeHealthResponseMatch { Body = "helloworld", StatusCodes ={ "200-300", "403" } } } }, BackendAddressPools = { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = { new ApplicationGatewayBackendAddress() { IpAddress = "hello1.azurewebsites.net" }, new ApplicationGatewayBackendAddress() { IpAddress = "hello2.azurewebsites.net" } } }, new ApplicationGatewayBackendAddressPool() { Name = nicBackendAddressPoolName } }, BackendHttpSettingsCollection = { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings1Name, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled, RequestTimeout = 69, Probe = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "probes", probeName) }, ConnectionDraining = new ApplicationGatewayConnectionDraining(true, 42), ProbeEnabled = true, PickHostNameFromBackendAddress = true }, new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings2Name, Port = 443, Protocol = ApplicationGatewayProtocol.Https, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Enabled, AuthenticationCertificates = { new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "authenticationCertificates", authCertName) } } } }, HttpListeners = { new ApplicationGatewayHttpListener() { Name = httpListener1Name, FrontendPort = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort1Name) }, FrontendIPConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http }, new ApplicationGatewayHttpListener() { Name = httpListener2Name, FrontendPort = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort2Name) }, FrontendIPConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https }, new ApplicationGatewayHttpListener() { Name = httpListener3Name, FrontendPort = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort3Name) }, FrontendIPConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https }, new ApplicationGatewayHttpListener() { Name = httpListener4Name, FrontendPort = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort4Name) }, FrontendIPConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https } }, UrlPathMaps = { new ApplicationGatewayUrlPathMap { Name = urlPathMapName, DefaultRedirectConfiguration = new SubResource { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "redirectConfigurations", redirectConfiguration2Name) }, PathRules = { new ApplicationGatewayPathRule { Name = pathRuleName, Paths = { "/paa"}, BackendAddressPool = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings1Name) } } } } }, RequestRoutingRules = { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule1Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener1Name) }, BackendAddressPool = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings1Name) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule2Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener2Name) }, RedirectConfiguration = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "redirectConfigurations", redirectConfiguration1Name) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule3Name, RuleType = ApplicationGatewayRequestRoutingRuleType.PathBasedRouting, HttpListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener3Name) }, UrlPathMap = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "urlPathMaps", urlPathMapName) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule4Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener4Name) }, BackendAddressPool = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", nicBackendAddressPoolName) }, BackendHttpSettings = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings2Name) } }, }, AuthenticationCertificates = { CreateAuthCertificate(authCertName) }, WebApplicationFirewallConfiguration = new ApplicationGatewayWebApplicationFirewallConfiguration(true, ApplicationGatewayFirewallMode.Prevention, "OWASP", "2.2.9") { DisabledRuleGroups = { new ApplicationGatewayFirewallDisabledRuleGroup("crs_41_sql_injection_attacks") { Rules ={ 981318, 981320 } }, new ApplicationGatewayFirewallDisabledRuleGroup("crs_35_bad_robots") } }, SslPolicy = new ApplicationGatewaySslPolicy() { PolicyType = "Predefined", PolicyName = "AppGwSslPolicy20170401" }, RedirectConfigurations = { new ApplicationGatewayRedirectConfiguration { Name = redirectConfiguration1Name, RedirectType = ApplicationGatewayRedirectType.Permanent, TargetListener = new SubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener1Name) }, }, new ApplicationGatewayRedirectConfiguration { Name = redirectConfiguration2Name, RedirectType = ApplicationGatewayRedirectType.Permanent, TargetUrl = "http://www.bing.com" } }, //SslCertificates = CreateSslCertificate(sslCertName, "abc") }; return(appGw); }
/// <summary> /// Creates or updates the specified application gateway. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='applicationGatewayName'> /// The name of the application gateway. /// </param> /// <param name='parameters'> /// Parameters supplied to the create or update application gateway operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ApplicationGateway> BeginCreateOrUpdateAsync(this IApplicationGatewaysOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, applicationGatewayName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }