public async Task CreateOrUpdate() { #region Snippet:Managing_Networks_CreateAVirtualNetwork VirtualNetworkCollection virtualNetworkCollection = resourceGroup.GetVirtualNetworks(); string vnetName = "myVnet"; // Use the same location as the resource group VirtualNetworkData input = new VirtualNetworkData() { Location = resourceGroup.Data.Location, AddressSpace = new AddressSpace() { AddressPrefixes = { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = { "10.1.1.1", "10.1.2.4" } }, Subnets = { new SubnetData() { Name = "mySubnet", AddressPrefix = "10.0.1.0/24", } } }; VirtualNetworkResource vnet = await virtualNetworkCollection.CreateOrUpdate(WaitUntil.Completed, vnetName, input).WaitForCompletionAsync(); #endregion }
public async Task CreateOrUpdate() { VirtualNetworkCollection virtualNetworkCollection = resourceGroup.GetVirtualNetworks(); string vnetName = "myVnet"; // Use the same location as the resource group VirtualNetworkData vnetInput = new VirtualNetworkData() { Location = resourceGroup.Data.Location, AddressSpace = new AddressSpace() { AddressPrefixes = { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = { "10.1.1.1", "10.1.2.4" } }, Subnets = { new SubnetData() { Name = "mySubnet", AddressPrefix = "10.0.1.0/24" } } }; VirtualNetwork virtualNetwork = await virtualNetworkCollection.CreateOrUpdate(vnetName, vnetInput).WaitForCompletionAsync(); #region Snippet:Managing_Networks_CreateANetworkInterface PublicIPAddressCollection publicIPAddressCollection = resourceGroup.GetPublicIPAddresses(); string publicIPAddressName = "myIPAddress"; PublicIPAddressData publicIPInput = new PublicIPAddressData() { Location = resourceGroup.Data.Location, PublicIPAllocationMethod = IPAllocationMethod.Dynamic, DnsSettings = new PublicIPAddressDnsSettings() { DomainNameLabel = "myDomain" } }; PublicIPAddress publicIPAddress = await publicIPAddressCollection.CreateOrUpdate(publicIPAddressName, publicIPInput).WaitForCompletionAsync(); NetworkInterfaceCollection networkInterfaceCollection = resourceGroup.GetNetworkInterfaces(); string networkInterfaceName = "myNetworkInterface"; NetworkInterfaceData networkInterfaceInput = new NetworkInterfaceData() { Location = resourceGroup.Data.Location, IpConfigurations = { new NetworkInterfaceIPConfiguration() { Name = "ipConfig", PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, PublicIPAddress = new PublicIPAddressData() { Id = publicIPAddress.Id }, Subnet = new SubnetData() { // use the virtual network just created Id = virtualNetwork.Data.Subnets[0].Id } } } }; NetworkInterface networkInterface = await networkInterfaceCollection.CreateOrUpdate(networkInterfaceName, networkInterfaceInput).WaitForCompletionAsync(); #endregion }