Ejemplo n.º 1
0
        public AzureSubnet ConstructSubnet(string name, string cidr, AzureNetworkSecurityGroup group = null)
        {
            var subnet = new Subnet()
            {
                Name          = name,
                AddressPrefix = cidr,
            };

            if (null != group)
            {
                subnet.NetworkSecurityGroup = group.Model;
            }

            return(new AzureSubnet(this, new PhSubnet(subnet, Location)));
        }
        /// <summary>
        /// Create an NSG with the given open TCP ports
        /// </summary>
        /// <param name="openPorts">The set of TCP ports to open</param>
        /// <returns>An NSG, with the given TCP ports open</returns>
        public static AzureNetworkSecurityGroup ConstructNsg(this AzureResourceGroupBase resourceGroup, string nsgName, params int[] openPorts)
        {
            var nsg = new NetworkSecurityGroup {
                Location = resourceGroup.Location
            };
            var index = 0;

            nsg.SecurityRules = openPorts.Select(openPort => new SecurityRule
            {
                Name                     = $"Port{openPort}",
                Priority                 = 1000 + (++index),
                Protocol                 = SecurityRuleProtocol.Tcp,
                Access                   = SecurityRuleAccess.Allow,
                Direction                = SecurityRuleDirection.Inbound,
                SourcePortRange          = "*",
                SourceAddressPrefix      = "*",
                DestinationPortRange     = $"{openPort}",
                DestinationAddressPrefix = "*",
                Description              = $"Port_{openPort}"
            }).ToList();
            var result = new AzureNetworkSecurityGroup(resourceGroup, nsg, nsgName);

            return(result);
        }