private Firewall Firewall(ResourceGroup resourceGroup, Subnet snet, int vnetRangePrefix) { var publicIp = new PublicIp($"ip-fw-{DeploymentName}{vnetRangePrefix / 2 + 1}", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Sku = "Standard", AllocationMethod = "Static" }); var firewall = new Firewall($"fw-{DeploymentName}{vnetRangePrefix / 2 + 1}", new FirewallArgs { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, IpConfigurations = { new FirewallIpConfigurationArgs { Name = $"fw-config-{DeploymentName}{vnetRangePrefix / 2 + 1}", SubnetId = snet.Id, PublicIpAddressId = publicIp.Id } } }); return(firewall); }
internal void Bind(PublicIp publicIp, TargetTreeView targetTreeView) { try { this.IsBinding = true; _PublicIp = publicIp; _TargetTreeView = targetTreeView; txtTargetName.Text = _PublicIp.TargetName; txtDomainNameLabel.Text = _PublicIp.DomainNameLabel; int allocationMethodIndex = cmbPublicIpAllocation.FindString(_PublicIp.IPAllocationMethod.ToString()); if (allocationMethodIndex >= 0) { cmbPublicIpAllocation.SelectedIndex = allocationMethodIndex; } else { cmbPublicIpAllocation.SelectedIndex = 0; } } finally { this.IsBinding = false; } }
public void Save() { var writer = XmlWriter.Create(pathName, new XmlWriterSettings() { Indent = true, IndentChars = @" " }); writer.WriteStartElement(@"settings"); writer.WriteElementString(@"publicIp", PublicIp.ToString()); writer.WriteElementString(@"turnUdpPort", TurnUdpPort.ToString()); writer.WriteElementString(@"turnTcpPort", TurnTcpPort.ToString()); writer.WriteElementString(@"turnTlsPort", TurnTlsPort.ToString()); writer.WriteElementString(@"minPort", MinPort.ToString()); writer.WriteElementString(@"maxPort", MaxPort.ToString()); writer.WriteElementString(@"realm", Realm); writer.WriteElementString(@"key1", Convert.ToBase64String(Key1)); writer.WriteElementString(@"key2", Convert.ToBase64String(Key2)); writer.WriteElementString(@"adminName", AdminName); writer.WriteElementString(@"adminPass", AdminPass); writer.WriteEndElement(); writer.Flush(); writer.Close(); }
public static object ToObject() { var data = new { publicIp = PublicIp.Trim(), networkDevices = NetworkComputers, macAddress = MacAddress, internalIp = InternalIp }; return(data); }
private static void CreateVirtualMachine(string suffix, ResourceGroup resourceGroup, CreateVirtualNetworkResult network) { var publicip = new PublicIp($"pip-{suffix}", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, AllocationMethod = "Static", }); var nic = new NetworkInterface($"nic-{suffix}", new NetworkInterfaceArgs { ResourceGroupName = resourceGroup.Name, IpConfigurations = { new NetworkInterfaceIpConfigurationArgs { Name = "nic-pip-association", SubnetId = network.SubnetId, PrivateIpAddressAllocation = "Dynamic", PublicIpAddressId = publicip.Id, }, }, }); var nicNsgAssociation = new NetworkInterfaceSecurityGroupAssociation($"nic-to-nsg-{suffix}", new NetworkInterfaceSecurityGroupAssociationArgs { NetworkInterfaceId = nic.Id, NetworkSecurityGroupId = network.NetworkSecurityGroupId }); var vm = new LinuxVirtualMachine($"vm-{suffix}", new LinuxVirtualMachineArgs { ResourceGroupName = resourceGroup.Name, NetworkInterfaceIds = { nic.Id }, Size = "Standard_DS1_v2", ComputerName = $"vm-{suffix}", AdminUsername = "******", AdminPassword = "******", DisablePasswordAuthentication = false, OsDisk = new LinuxVirtualMachineOsDiskArgs { Name = "disk0", Caching = "ReadWrite", StorageAccountType = "Premium_LRS" }, SourceImageReference = new LinuxVirtualMachineSourceImageReferenceArgs { Publisher = "Canonical", Offer = "UbuntuServer", Sku = "18_04-lts-gen2", Version = "latest", }, }); }
private async void rbPublicIPInMigration_CheckedChanged(object sender, EventArgs e) { RadioButton rb = (RadioButton)sender; if (rb.Checked) { #region Add "In MigAz Migration" Public Ips to cmbPublicIp cmbPublicIp.Items.Clear(); foreach (Azure.MigrationTarget.PublicIp targetPublicIp in _TargetTreeView.GetPublicIPsInMigration()) { cmbPublicIp.Items.Add(targetPublicIp); } #endregion #region Seek Target Public and Subnet as ComboBox SelectedItems if (_PublicIpTarget != null) { if (_PublicIpTarget.GetType() == typeof(PublicIp)) { PublicIp targetPublicIp = (PublicIp)_PublicIpTarget; // Attempt to match target to list items foreach (Azure.MigrationTarget.PublicIp listPublicIp in cmbPublicIp.Items) { if (listPublicIp == targetPublicIp) { cmbPublicIp.SelectedItem = listPublicIp; break; } } } } #endregion if (cmbPublicIp.SelectedIndex < 0 && cmbPublicIp.Items.Count > 0) { cmbPublicIp.SelectedIndex = 0; } if (!_IsBinding) { PropertyChanged?.Invoke(); } } }
public override PublicIp ReleasePublicIp(VirtualDataCenter virtualDataCenter, PublicIp publicIp) { Contract.Requires(null != virtualDataCenter); Contract.Requires(null != publicIp); return(default(PublicIp)); }
static async Task DoJobAsync() { if (Application.MQTTCLIENT.IsConnected == false) { ConsoleLogger.Log($"[mqtt] mqtt server is unreachable"); return; } var servicesNames = new List <string>(); var antdUnits = Directory.EnumerateFiles("/mnt/cdrom/Units/antd.target.wants").ToArray(); for (var i = 0; i < antdUnits.Length; i++) { servicesNames.Add(Path.GetFileName(antdUnits[i])); } var applicativeUnits = Directory.EnumerateFiles("/mnt/cdrom/Units/applicative.target.wants").ToArray(); for (var i = 0; i < applicativeUnits.Length; i++) { servicesNames.Add(Path.GetFileName(applicativeUnits[i])); } var arrServicesNames = servicesNames.ToArray(); var services = new ServiceStatus[arrServicesNames.Length]; for (var i = 0; i < arrServicesNames.Length; i++) { services[i] = new ServiceStatus { Name = arrServicesNames[i], IsActive = cmds.Systemctl.IsActive(arrServicesNames[i]) }; } var du = DiskUsage.Get(); var dus = new DiskUsageStatus[du.Length]; for (var i = 0; i < du.Length; i++) { dus[i] = new DiskUsageStatus { Device = du[i].MountedOn, Used = int.Parse(du[i].UsePercentage.Replace("%", "")) }; } var free = Free.Get(); var frees = new FreeStatus[free.Length]; for (var i = 0; i < free.Length; i++) { frees[i] = new FreeStatus() { Name = free[i].Name, Total = ParseInt(free[i].Total), Used = ParseInt(free[i].Used), Free = ParseInt(free[i].Free), Shared = ParseInt(free[i].Shared), BuffCache = ParseInt(free[i].BuffCache), Available = ParseInt(free[i].Available) }; } var status = new CurrentMachineStatus() { PublicIp = PublicIp.Get(), MachineId = Application.MACHINE_ID, Date = new DateStatus { Date1 = DateTime.Now, Date2 = Date.Get() }, Free = frees, DiskUsage = dus, Services = services }; var converted = MSG.Serialize(status); var message = new MqttApplicationMessageBuilder() .WithTopic("/status") .WithPayload(converted) .WithExactlyOnceQoS() .WithRetainFlag() .Build(); await Application.MQTTCLIENT.PublishAsync(message); //WriteStatus(status); }
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, // } // } // } // }); }
public Func <RegionalContext, IRegionalEndpoint> BuildVMScaleSetApp(GlobalContext context) { var options = (CustomResourceOptions)ResourceOptions.Merge(context.Options, new CustomResourceOptions { DeleteBeforeReplace = true }); var file = File.ReadAllText("./vm/vmCustomData.yaml"); return((RegionalContext region) => { var location = region.Location; var domainName = $"rnddnplm{location}"; //TODO: random var publicIp = new PublicIp($"pip-{location}", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, Location = location, AllocationMethod = "Static", DomainNameLabel = domainName, }, options); var loadBalancer = new LoadBalancer($"lb-{location}", new LoadBalancerArgs { ResourceGroupName = resourceGroup.Name, Location = location, FrontendIpConfigurations = { new LoadBalancerFrontendIpConfigurationsArgs { Name = "PublicIPAddress", PublicIpAddressId = publicIp.Id, } } }, options); var bpepool = new BackendAddressPool($"bap-{location}", new BackendAddressPoolArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = loadBalancer.Id, }, options); var probe = new Probe($"ssh-probe-{location}".Truncate(16), new ProbeArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = loadBalancer.Id, Port = 80, }, options); var rule = new Rule($"rule-{location}", new RuleArgs { ResourceGroupName = resourceGroup.Name, BackendAddressPoolId = bpepool.Id, BackendPort = 80, FrontendIpConfigurationName = "PublicIPAddress", FrontendPort = 80, LoadbalancerId = loadBalancer.Id, ProbeId = probe.Id, Protocol = "Tcp", }, options); var vnet = new VirtualNetwork($"vnet-{location}", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, Location = location, AddressSpaces = { "10.0.0.0/16" }, }, options); var subnet = new Subnet($"subnet-{location}", new SubnetArgs { ResourceGroupName = resourceGroup.Name, AddressPrefix = "10.0.2.0/24", VirtualNetworkName = vnet.Name, }, options); var customData = Output.All <string>(context.CosmosAccount.Endpoint, context.CosmosAccount.PrimaryMasterKey, context.Database.Name, context.Container.Name) .Apply(values => { return file.Replace("${ENDPOINT}", values[0]) .Replace("${MASTER_KEY}", values[1]) .Replace("${DATABASE}", values[2]) .Replace("${COLLECTION}", values[3]) .Replace("${LOCATION}", location); }); var scaleSet = new ScaleSet($"vmss-{location}", new ScaleSetArgs { ResourceGroupName = resourceGroup.Name, Location = location, NetworkProfiles = { new ScaleSetNetworkProfilesArgs { IpConfigurations = { new ScaleSetNetworkProfilesIpConfigurationsArgs { LoadBalancerBackendAddressPoolIds ={ bpepool.Id }, Name = "IPConfiguration", Primary = true, SubnetId = subnet.Id, } }, Name = "networkprofile", Primary = true, } }, OsProfile = new ScaleSetOsProfileArgs { AdminUsername = "******", AdminPassword = "******", ComputerNamePrefix = "lab", CustomData = customData, }, OsProfileLinuxConfig = new ScaleSetOsProfileLinuxConfigArgs { DisablePasswordAuthentication = false }, Sku = new ScaleSetSkuArgs { Capacity = 1, Name = "Standard_DS1_v2", Tier = "Standard", }, StorageProfileDataDisks = { new ScaleSetStorageProfileDataDisksArgs { Caching = "ReadWrite", CreateOption = "Empty", DiskSizeGb = 10, Lun = 0, } }, StorageProfileImageReference = new ScaleSetStorageProfileImageReferenceArgs { Offer = "UbuntuServer", Publisher = "Canonical", Sku = "18.04-LTS", Version = "latest", }, StorageProfileOsDisk = new ScaleSetStorageProfileOsDiskArgs { Caching = "ReadWrite", CreateOption = "FromImage", ManagedDiskType = "Standard_LRS", Name = "", }, UpgradePolicyMode = "Automatic", }, (CustomResourceOptions)ResourceOptions.Merge(options, new ResourceOptions { DependsOn = { bpepool, rule } })); var autoscale = new AutoscaleSetting($"as-{location}", new AutoscaleSettingArgs { ResourceGroupName = resourceGroup.Name, Location = location, Notification = new AutoscaleSettingNotificationArgs { Email = new AutoscaleSettingNotificationEmailArgs { CustomEmails = { "*****@*****.**" }, SendToSubscriptionAdministrator = true, SendToSubscriptionCoAdministrator = true, }, }, Profiles = { new AutoscaleSettingProfilesArgs { Capacity = new AutoscaleSettingProfilesCapacityArgs { Default = 1, Maximum = 10, Minimum = 1, }, Name = "defaultProfile", Rules = { new AutoscaleSettingProfilesRulesArgs { MetricTrigger = new AutoscaleSettingProfilesRulesMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "GreaterThan", Statistic = "Average", Threshold = 75, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfilesRulesScaleActionArgs { Cooldown = "PT1M", Direction = "Increase", Type = "ChangeCount", Value = 1, }, }, new AutoscaleSettingProfilesRulesArgs { MetricTrigger = new AutoscaleSettingProfilesRulesMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "LessThan", Statistic = "Average", Threshold = 25, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfilesRulesScaleActionArgs { Cooldown = "PT1M", Direction = "Decrease", Type = "ChangeCount", Value = 1, }, }, } } }, TargetResourceId = scaleSet.Id, }, options); return new AzureEndpoint(publicIp.Id); }); }
public VmScalesetStack() { var applicationPort = 80; var resourceGroup = new ResourceGroup("vmss-rg"); var network = new VirtualNetwork("vnet", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, AddressSpaces = { "10.0.0.0/16" } } ); var subnet = new Subnet("subnet", new SubnetArgs { ResourceGroupName = resourceGroup.Name, Name = "default", AddressPrefixes = "10.0.1.0/24", VirtualNetworkName = network.Name }); var publicIp = new PublicIp("public-ip", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, AllocationMethod = "Dynamic" }); var lb = new LoadBalancer("lb", new LoadBalancerArgs { ResourceGroupName = resourceGroup.Name, FrontendIpConfigurations = new List <LoadBalancerFrontendIpConfigurationArgs> { new LoadBalancerFrontendIpConfigurationArgs { Name = "PublicIPAddress", PublicIpAddressId = publicIp.Id } } }); var bpePool = new BackendAddressPool("bpepool", new BackendAddressPoolArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = lb.Id, }); var sshProbe = new Probe("ssh-probe", new ProbeArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = lb.Id, Port = applicationPort, }); var natRule = new Rule("lbnatrule-http", new RuleArgs { ResourceGroupName = resourceGroup.Name, BackendAddressPoolId = bpePool.Id, BackendPort = applicationPort, FrontendIpConfigurationName = "PublicIPAddress", FrontendPort = applicationPort, LoadbalancerId = lb.Id, ProbeId = sshProbe.Id, Protocol = "Tcp", }); var scaleSet = new ScaleSet("vmscaleset", new ScaleSetArgs { ResourceGroupName = resourceGroup.Name, NetworkProfiles = new ScaleSetNetworkProfileArgs { IpConfigurations = new ScaleSetNetworkProfileIpConfigurationArgs[] { new ScaleSetNetworkProfileIpConfigurationArgs { LoadBalancerBackendAddressPoolIds = bpePool.Id, Name = "IPConfiguration", Primary = true, SubnetId = subnet.Id, } }, Name = "networkprofile", Primary = true }, OsProfile = new ScaleSetOsProfileArgs { ComputerNamePrefix = "vmlab", AdminUsername = "******", AdminPassword = "******", CustomData = @"#!/bin/bash echo ""Hello, World by $HOSTNAME!"" > index.html nohup python -m SimpleHTTPServer 80 &" }, OsProfileLinuxConfig = new ScaleSetOsProfileLinuxConfigArgs { DisablePasswordAuthentication = false }, Sku = new ScaleSetSkuArgs { Capacity = 1, Name = "Standard_DS1_v2", Tier = "Standard", }, StorageProfileOsDisk = new ScaleSetStorageProfileOsDiskArgs { Caching = "ReadWrite", CreateOption = "FromImage", ManagedDiskType = "Standard_LRS", Name = "" }, StorageProfileDataDisks = new ScaleSetStorageProfileDataDiskArgs { Caching = "ReadWrite", CreateOption = "Empty", DiskSizeGb = 10, Lun = 0 }, StorageProfileImageReference = new ScaleSetStorageProfileImageReferenceArgs { Offer = "UbuntuServer", Publisher = "Canonical", Sku = "16.04-LTS", Version = "latest", }, UpgradePolicyMode = "Manual" }, new CustomResourceOptions { DeleteBeforeReplace = true, DependsOn = bpePool }); var autoscale = new AutoscaleSetting("vmss-autoscale", new AutoscaleSettingArgs { ResourceGroupName = resourceGroup.Name, Notification = new AutoscaleSettingNotificationArgs { Email = new AutoscaleSettingNotificationEmailArgs { CustomEmails = new string[] { "*****@*****.**" }, SendToSubscriptionAdministrator = true, SendToSubscriptionCoAdministrator = true, }, }, Profiles = new AutoscaleSettingProfileArgs[] { new AutoscaleSettingProfileArgs { Capacity = new AutoscaleSettingProfileCapacityArgs { Default = 2, Maximum = 10, Minimum = 2, }, Name = "defaultProfile", Rules = new AutoscaleSettingProfileRuleArgs[] { new AutoscaleSettingProfileRuleArgs { MetricTrigger = new AutoscaleSettingProfileRuleMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "GreaterThan", Statistic = "Average", Threshold = 75, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfileRuleScaleActionArgs { Cooldown = "PT1M", Direction = "Increase", Type = "ChangeCount", Value = 1, }, }, new AutoscaleSettingProfileRuleArgs { MetricTrigger = new AutoscaleSettingProfileRuleMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "LessThan", Statistic = "Average", Threshold = 25, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfileRuleScaleActionArgs { Cooldown = "PT1M", Direction = "Decrease", Type = "ChangeCount", Value = 1, }, } } } }, TargetResourceId = scaleSet.Id }); // The public IP address is not allocated until the VM is running, so wait for that // resource to create, and then lookup the IP address again to report its public IP. this.IpAddress = Output .Tuple <string, string, string>(scaleSet.Id, publicIp.Name, resourceGroup.Name) .Apply <string>(async t => { (_, string name, string resourceGroupName) = t; var ip = await GetPublicIP.InvokeAsync(new GetPublicIPArgs { Name = name, ResourceGroupName = resourceGroupName }); return(ip.IpAddress); }); }
static Task <int> Main() { return(Deployment.RunAsync(() => { var resourceGroup = new ResourceGroup("server-rg"); var network = new VirtualNetwork("server-network", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, AddressSpaces = { "10.0.0.0/16" }, Subnets = { new VirtualNetworkSubnetsArgs { Name = "default", AddressPrefix = "10.0.1.0/24" } }, } ); var publicIp = new PublicIp("server-ip", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, AllocationMethod = "Dynamic", }); var networkInterface = new NetworkInterface("server-nic", new NetworkInterfaceArgs { ResourceGroupName = resourceGroup.Name, IpConfigurations = { new NetworkInterfaceIpConfigurationsArgs { Name = "webserveripcfg", SubnetId = network.Subnets.Apply(subnets => subnets[0].Id), PrivateIpAddressAllocation = "Dynamic", PublicIpAddressId = publicIp.Id, }, } }); var vm = new VirtualMachine("server-vm", new VirtualMachineArgs { ResourceGroupName = resourceGroup.Name, NetworkInterfaceIds = { networkInterface.Id }, VmSize = "Standard_A0", DeleteDataDisksOnTermination = true, DeleteOsDiskOnTermination = true, OsProfile = new VirtualMachineOsProfileArgs { ComputerName = "hostname", AdminUsername = "******", AdminPassword = "******", CustomData = @"#!/bin/bash echo ""Hello, World!"" > index.html nohup python -m SimpleHTTPServer 80 &", }, OsProfileLinuxConfig = new VirtualMachineOsProfileLinuxConfigArgs { DisablePasswordAuthentication = false, }, StorageOsDisk = new VirtualMachineStorageOsDiskArgs { CreateOption = "FromImage", Name = "myosdisk1", }, StorageImageReference = new VirtualMachineStorageImageReferenceArgs { Publisher = "canonical", Offer = "UbuntuServer", Sku = "16.04-LTS", Version = "latest", }, }, new CustomResourceOptions { DeleteBeforeReplace = true }); // The public IP address is not allocated until the VM is running, so wait for that // resource to create, and then lookup the IP address again to report its public IP. var ipAddress = Output .Tuple <string, string, string>(vm.Id, publicIp.Name, resourceGroup.Name) .Apply <string>(async t => { (_, string name, string resourceGroupName) = t; var ip = await Pulumi.Azure.Network.Invokes.GetPublicIP(new GetPublicIPArgs { Name = name, ResourceGroupName = resourceGroupName }); return ip.IpAddress; }); return new Dictionary <string, object?> { { "ipAddress", ipAddress } }; })); }
public MyStack() { var resourceGroup = new Azure.Core.ResourceGroup("my-group"); var network = new VirtualNetwork("server-network", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, AddressSpaces = { "10.0.0.0/16" }, Subnets = { new VirtualNetworkSubnetsArgs { Name = "default", AddressPrefix = "10.0.1.0/24" } }, }); var publicIp = new PublicIp("server-ip", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, AllocationMethod = "Dynamic", }); var networkInterface = new NetworkInterface("server-nic", new NetworkInterfaceArgs { ResourceGroupName = resourceGroup.Name, IpConfigurations = { new NetworkInterfaceIpConfigurationsArgs { Name = "webserveripcfg", SubnetId = network.Subnets.Apply(subnets => subnets[0].Id), PrivateIpAddressAllocation = "Dynamic", PublicIpAddressId = publicIp.Id, }, } }); var vm = new VirtualMachine("server-vm", new VirtualMachineArgs { ResourceGroupName = resourceGroup.Name, NetworkInterfaceIds = { networkInterface.Id }, VmSize = "Standard_A0", DeleteDataDisksOnTermination = true, DeleteOsDiskOnTermination = true, OsProfile = new VirtualMachineOsProfileArgs { ComputerName = "hostname", AdminUsername = "******", AdminPassword = "******", CustomData = @"#!/bin/bash echo ""Hello, World!"" > index.html nohup python -m SimpleHTTPServer 80 &", }, OsProfileLinuxConfig = new VirtualMachineOsProfileLinuxConfigArgs { DisablePasswordAuthentication = false, }, StorageOsDisk = new VirtualMachineStorageOsDiskArgs { CreateOption = "FromImage", Name = "myosdisk1", }, StorageImageReference = new VirtualMachineStorageImageReferenceArgs { Publisher = "canonical", Offer = "UbuntuServer", Sku = "16.04-LTS", Version = "latest", } }); }
public RoomOperationResult StartGame() { if (currentAccount == null) { return(RoomOperationResult.NotAutheticated); } if (currentAccount.CurrentRoom == null) { return(RoomOperationResult.Invalid); } int portNumber; var room = currentAccount.CurrentRoom; var total = room.Room.Seats.Count(pl => pl.Account != null); var initiator = room.Room.Seats.FirstOrDefault(pl => pl.Account == currentAccount.Account); if (room.Room.State == RoomState.Gaming) { return(RoomOperationResult.Invalid); } if (total <= 1) { return(RoomOperationResult.Invalid); } if (initiator == null || initiator.State != SeatState.Host) { return(RoomOperationResult.Invalid); } if (room.Room.Seats.Any(cs => cs.Account != null && cs.State != SeatState.Host && cs.State != SeatState.GuestReady)) { return(RoomOperationResult.Invalid); } lock (room.Room) { room.Room.State = RoomState.Gaming; foreach (var unready in room.Room.Seats) { if (unready.State == SeatState.GuestReady) { unready.State = SeatState.Gaming; } } var gs = new GameSettings() { TimeOutSeconds = room.Room.Settings.TimeOutSeconds, TotalPlayers = total, CheatEnabled = CheatEnabled, DualHeroMode = room.Room.Settings.IsDualHeroMode, NumHeroPicks = room.Room.Settings.NumHeroPicks, NumberOfDefectors = room.Room.Settings.NumberOfDefectors == 2 ? 2 : 1, GameType = room.Room.Settings.GameType, }; // Load pakcages. if (gs.GameType == GameType.RoleGame) { gs.PackagesEnabled.Add("Sanguosha.Expansions.BasicExpansion"); gs.PackagesEnabled.Add("Sanguosha.Expansions.BattleExpansion"); if ((room.Room.Settings.EnabledPackages & EnabledPackages.Wind) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.WindExpansion"); } if ((room.Room.Settings.EnabledPackages & EnabledPackages.Fire) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.FireExpansion"); } if ((room.Room.Settings.EnabledPackages & EnabledPackages.Woods) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.WoodsExpansion"); } if ((room.Room.Settings.EnabledPackages & EnabledPackages.Hills) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.HillsExpansion"); } if ((room.Room.Settings.EnabledPackages & EnabledPackages.SP) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.SpExpansion"); gs.PackagesEnabled.Add("Sanguosha.Expansions.StarSpExpansion"); } if ((room.Room.Settings.EnabledPackages & EnabledPackages.OverKnightFame) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.OverKnightFame11Expansion"); gs.PackagesEnabled.Add("Sanguosha.Expansions.OverKnightFame12Expansion"); gs.PackagesEnabled.Add("Sanguosha.Expansions.OverKnightFame13Expansion"); } if ((room.Room.Settings.EnabledPackages & EnabledPackages.Others) != 0) { gs.PackagesEnabled.Add("Sanguosha.Expansions.AssasinExpansion"); } } if (gs.GameType == GameType.Pk1v1) { gs.PackagesEnabled.Add("Sanguosha.Expansions.Pk1v1Expansion"); } foreach (var addconfig in room.Room.Seats) { var account = addconfig.Account; if (account != null) { account.LoginToken = new LoginToken() { TokenString = Guid.NewGuid() }; account.IsDead = false; gs.Accounts.Add(account); } } GameService.StartGameService(HostingIp, gs, room.Room.Id, _OnGameEnds, out portNumber); room.Room.IpAddress = PublicIp.ToString(); room.Room.IpPort = portNumber; _NotifyGameStart(room.Room.Id, PublicIp, portNumber); } currentAccount.LastAction = DateTime.Now; return(RoomOperationResult.Success); }
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; }
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, }, }, }); }
public WorkloadStack() { var baseStack = new StackReference("evgenyb/iac-base/lab"); 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), Tags = { { "owner", Constants.TeamPlatform }, { "environment", environment } } }); var vnet = new VirtualNetwork("vnet", new VirtualNetworkArgs { Name = NamingConvention.GetVNetName(environment), ResourceGroupName = resourceGroup.Name, AddressSpaces = { config.Require("vnet.addressSpaces") }, Tags = { { "owner", Constants.TeamPlatform }, { "environment", environment } } }); // Create a Subnet for the cluster var aksSubnet = new Subnet("aks-net", new SubnetArgs { Name = "aks-net", ResourceGroupName = resourceGroup.Name, VirtualNetworkName = vnet.Name, AddressPrefixes = { config.Require("vnet.subnets.aks.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 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("keyVaultSecretId") // } // }, // 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 = "appGatewayFrontendIP", // PublicIpAddressId = agwPublicIp.Id // } // }, // HttpListeners = new [] // { // new ApplicationGatewayHttpListenerArgs // { // Name = "gateway-listener", // FrontendIpConfigurationName = "appGatewayFrontendIP", // FrontendPortName = "port443", // Protocol = "Https", // HostName = "iac-lab-api.iac-labs.com", // RequireSni = true, // SslCertificateName = "gateway-listener" // }, // new ApplicationGatewayHttpListenerArgs // { // Name = "management-listener", // FrontendIpConfigurationName = "appGatewayFrontendIP", // FrontendPortName = "port443", // Protocol = "Https", // HostName = "iac-lab-management.iac-labs.com", // RequireSni = true, // SslCertificateName = "gateway-listener" // }, // new ApplicationGatewayHttpListenerArgs // { // Name = "portal-listener", // FrontendIpConfigurationName = "appGatewayFrontendIP", // FrontendPortName = "port443", // Protocol = "Https", // HostName = "iac-lab-portal.iac-labs.com", // RequireSni = true, // SslCertificateName = "gateway-listener" // } // }, // BackendAddressPools = new[] // { // new ApplicationGatewayBackendAddressPoolArgs // { // Name = "apim-backend-pool", // IpAddresses = config.RequireSecret("apim.backend.ip") // } // }, // Probes = new[] // { // new ApplicationGatewayProbeArgs // { // Name = "apim-probe", // Protocol = "Https", // Path = "/status-0123456789abcdef", // Host = "iac-lab-api.iac-labs.com", // Interval = 30, // Timeout = 120, // UnhealthyThreshold = 8, // PickHostNameFromBackendHttpSettings = false, // MinimumServers = 0 // } // }, // BackendHttpSettings = new [] // { // new ApplicationGatewayBackendHttpSettingArgs // { // Name = "apim-settings", // Port = 443, // Protocol = "Https", // CookieBasedAffinity = "Disabled", // PickHostNameFromBackendAddress = false, // RequestTimeout = 30, // ProbeName = "apim-probe" // } // }, // RequestRoutingRules = new[] // { // new ApplicationGatewayRequestRoutingRuleArgs // { // Name = "gateway", // RuleType = "Basic", // HttpListenerName = "gateway-listener", // BackendAddressPoolName = "apim-backend-pool", // BackendHttpSettingsName = "apim-settings" // }, // new ApplicationGatewayRequestRoutingRuleArgs // { // Name = "management", // RuleType = "Basic", // HttpListenerName = "management-listener", // BackendAddressPoolName = "apim-backend-pool", // BackendHttpSettingsName = "apim-settings" // }, // new ApplicationGatewayRequestRoutingRuleArgs // { // Name = "portal", // RuleType = "Basic", // HttpListenerName = "portal-listener", // BackendAddressPoolName = "apim-backend-pool", // BackendHttpSettingsName = "apim-settings" // }, // } // }); // // var appInsight = new Insights("ai", new InsightsArgs // { // Name = NamingConvention.GetAppInsightName(environment), // ResourceGroupName = resourceGroup.Name, // Location = resourceGroup.Location, // ApplicationType = "web", // // }); // var la = new AnalyticsWorkspace("la", new AnalyticsWorkspaceArgs // { // Name = NamingConvention.GetLogAnalyticsName(environment), // ResourceGroupName = resourceGroup.Name, // Location = resourceGroup.Location, // Sku = "PerGB2018" // }); var aksEgressPublicIp = new PublicIp("aks-egress-pip", new PublicIpArgs { Name = NamingConvention.GetPublicIpName("aks-egress", environment), ResourceGroupName = resourceGroup.Name, Sku = "Standard", AllocationMethod = "Static" }); var logAnalyticsWorkspaceId = baseStack.RequireOutput("LogAnalyticsWorkspaceId").Apply(x => x.ToString()); var aks = new KubernetesCluster("aks", new KubernetesClusterArgs { Name = NamingConvention.GetAksName(environment), ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Identity = new KubernetesClusterIdentityArgs { Type = "SystemAssigned" }, DefaultNodePool = new KubernetesClusterDefaultNodePoolArgs { Name = "aksagentpool", NodeCount = 1, VmSize = "Standard_B2s", OsDiskSizeGb = 30, VnetSubnetId = aksSubnet.Id }, DnsPrefix = "iacpulumiaks", RoleBasedAccessControl = new KubernetesClusterRoleBasedAccessControlArgs { Enabled = true, AzureActiveDirectory = new KubernetesClusterRoleBasedAccessControlAzureActiveDirectoryArgs { AdminGroupObjectIds = config.RequireSecret("teamPlatformAADId"), TenantId = config.RequireSecret("tenantId"), Managed = true } }, NetworkProfile = new KubernetesClusterNetworkProfileArgs { NetworkPlugin = "azure", NetworkPolicy = "calico", DnsServiceIp = "10.2.2.254", ServiceCidr = "10.2.2.0/24", DockerBridgeCidr = "172.17.0.1/16", LoadBalancerProfile = new KubernetesClusterNetworkProfileLoadBalancerProfileArgs { OutboundIpAddressIds = new [] { aksEgressPublicIp.Id } } }, AddonProfile = new KubernetesClusterAddonProfileArgs { OmsAgent = new KubernetesClusterAddonProfileOmsAgentArgs { Enabled = true, LogAnalyticsWorkspaceId = logAnalyticsWorkspaceId }, KubeDashboard = new KubernetesClusterAddonProfileKubeDashboardArgs { Enabled = false } } }); var pool = new KubernetesClusterNodePool("workload-pool", new KubernetesClusterNodePoolArgs { Name = "workload", KubernetesClusterId = aks.Id, Mode = "User", NodeCount = 1, VmSize = "Standard_B2s", OsDiskSizeGb = 30, VnetSubnetId = aksSubnet.Id, NodeLabels = { { "disk", "ssd" }, { "type", "workload" } } }); this.KubeConfig = aks.KubeConfigRaw; }
public MyStack() { // Create an Azure Resource Group var applicationResourceGroup = new ResourceGroup("pulumi-appgateway-hosting-example", new ResourceGroupArgs() { Name = "pulumi-appgateway-hosting-example" }); var registry = new Registry("global", new RegistryArgs { ResourceGroupName = applicationResourceGroup.Name, AdminEnabled = true, Sku = "Premium", }); var dockerImage = new Pulumi.Docker.Image("my-app", new Pulumi.Docker.ImageArgs { ImageName = Output.Format($"{registry.LoginServer}/myapp:v1.0.0"), Build = "./container", Registry = new ImageRegistry { Server = registry.LoginServer, Username = registry.AdminUsername, Password = registry.AdminPassword, }, }, new ComponentResourceOptions { Parent = registry }); var vnet = new VirtualNetwork("vnet", new VirtualNetworkArgs() { AddressSpaces = "10.0.0.0/16", Subnets = new List <VirtualNetworkSubnetsArgs>() { }, ResourceGroupName = applicationResourceGroup.Name, Name = $"vnet" }); var appGatewaySubnet = new Subnet("gateway-subnet", new SubnetArgs() { Name = AzureGatewayNetworkName, VirtualNetworkName = $"vnet", AddressPrefix = "10.0.1.0/24", ResourceGroupName = applicationResourceGroup.Name, }, new CustomResourceOptions() { Parent = vnet }); var applicationSubnet = new Subnet("application-subnet", new SubnetArgs() { Name = "applicationsubnet", VirtualNetworkName = $"vnet", AddressPrefix = "10.0.0.0/24", ResourceGroupName = applicationResourceGroup.Name, Delegations = new SubnetDelegationsArgs() { Name = "SubnetDelegation", ServiceDelegation = new SubnetDelegationsServiceDelegationArgs() { Name = "Microsoft.ContainerInstance/containerGroups", Actions = "Microsoft.Network/virtualNetworks/subnets/join/action" } } }, new CustomResourceOptions() { Parent = vnet }); var applicationNetworkProfile = new Profile("application-networking-profile", new ProfileArgs() { Name = "application-networking-profile", ResourceGroupName = applicationResourceGroup.Name, ContainerNetworkInterface = new ProfileContainerNetworkInterfaceArgs() { Name = "ContainerNetworkInterface", IpConfigurations = new ProfileContainerNetworkInterfaceIpConfigurationsArgs() { Name = "IpConfigurations", SubnetId = applicationSubnet.Id, } } }); var aci = new Group($"aci", new GroupArgs() { Containers = new GroupContainersArgs() { Name = "aci", Memory = 1.5, Cpu = 0.5, Image = dockerImage.ImageName, Ports = new GroupContainersPortsArgs() { Port = 80, Protocol = "TCP" }, }, ImageRegistryCredentials = new GroupImageRegistryCredentialsArgs { Server = registry.LoginServer, Username = registry.AdminUsername, Password = registry.AdminPassword, }, OsType = "Linux", ResourceGroupName = applicationResourceGroup.Name, Name = "application", IpAddressType = "Private", NetworkProfileId = applicationNetworkProfile.Id, }); var publicIp = new PublicIp("gateway-publicip", new PublicIpArgs() { Sku = "Standard", ResourceGroupName = applicationResourceGroup.Name, AllocationMethod = "Static", DomainNameLabel = "application" + Guid.NewGuid().ToString() }); var backendAddressPools = new ApplicationGatewayBackendAddressPoolsArgs() { Name = "applicationBackendPool", IpAddresses = aci.IpAddress }; var frontendPorts = new ApplicationGatewayFrontendPortsArgs() { Name = "applicationfrontendport", Port = 80 }; var frontendIpConfigurations = new ApplicationGatewayFrontendIpConfigurationsArgs() { Name = "applicationFrontEndIpConfig", PublicIpAddressId = publicIp.Id, }; var backendHttpSettings = new ApplicationGatewayBackendHttpSettingsArgs() { Name = "sqBackendHttpSettings", Port = 80, Protocol = "Http", CookieBasedAffinity = "Disabled", RequestTimeout = 30, }; var appgwHttpListener = new ApplicationGatewayHttpListenersArgs() { Name = "appgwhttplistener", FrontendPortId = frontendPorts.Id, FrontendPortName = frontendPorts.Name, HostName = publicIp.Fqdn, Protocol = "Http", FrontendIpConfigurationId = frontendIpConfigurations.Id, FrontendIpConfigurationName = frontendIpConfigurations.Name, }; var requestRoutingRules = new ApplicationGatewayRequestRoutingRulesArgs() { Name = "RoutingRequestRules", BackendAddressPoolId = backendAddressPools.Id, BackendAddressPoolName = backendAddressPools.Name, BackendHttpSettingsId = backendHttpSettings.Id, BackendHttpSettingsName = backendHttpSettings.Name, HttpListenerId = appgwHttpListener.Id, HttpListenerName = appgwHttpListener.Name, RuleType = "Basic", }; new ApplicationGateway($"applicationgateway", new ApplicationGatewayArgs() { ResourceGroupName = applicationResourceGroup.Name, Sku = new ApplicationGatewaySkuArgs() { Name = "Standard_v2", Tier = "Standard_v2", Capacity = 1 }, FrontendIpConfigurations = frontendIpConfigurations, BackendAddressPools = backendAddressPools, BackendHttpSettings = backendHttpSettings, FrontendPorts = frontendPorts, RequestRoutingRules = requestRoutingRules, GatewayIpConfigurations = new ApplicationGatewayGatewayIpConfigurationsArgs() { Name = "gatewayconfig", SubnetId = appGatewaySubnet.Id }, HttpListeners = appgwHttpListener, }); this.ApplicationUrl = publicIp.Fqdn; }