示例#1
0
        /// <summary>
        /// create a default private endpoint for managed instance.
        /// please make sure your MI built using CreateDefaultManagedInstance() or vnet AddressPrefixes = 10.10.0.0/16
        /// </summary>
        /// <param name="managedInstance"></param>
        /// <param name="location"></param>
        /// <param name="resourceGroup"></param>
        /// <param name=""></param>
        /// <returns></returns>
        protected async Task <PrivateEndpoint> CreateDefaultPrivateEndpoint(ManagedInstance managedInstance, VirtualNetwork vnet, Location location, ResourceGroup resourceGroup)
        {
            // Add new subnet
            SubnetData subnetData = new SubnetData()
            {
                AddressPrefix = "10.10.5.0/24",
                PrivateEndpointNetworkPolicies = "Disabled"
            };
            var privateEndpointSubnet = await vnet.GetSubnets().CreateOrUpdateAsync($"private-endpoint-subnet", subnetData);

            // Create private endpoint
            string privateEndpointName = $"{managedInstance.Data.Name}-private-endpoint";
            var    endpointCollection  = resourceGroup.GetPrivateEndpoints();
            PrivateEndpointData data   = new PrivateEndpointData()
            {
                Subnet = new SubnetData()
                {
                    Id = privateEndpointSubnet.Value.Data.Id
                },
                Location = location,
                PrivateLinkServiceConnections =
                {
                    new PrivateLinkServiceConnection()
                    {
                        Name = privateEndpointName,
                        PrivateLinkServiceId = managedInstance.Data.Id.ToString(),
                        GroupIds             = { "managedInstance" },
                    }
                },
            };
            var privateEndpoint = await resourceGroup.GetPrivateEndpoints().CreateOrUpdateAsync(privateEndpointName, data);

            return(privateEndpoint.Value);
        }
示例#2
0
        public async Task GlobalSetUp()
        {
            Subscription subscription = await GlobalClient.GetDefaultSubscriptionAsync();

            var rgLro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, SessionRecording.GenerateAssetName("bastionrg-"), new ResourceGroupData(AzureLocation.WestUS2));

            ResourceGroup rg = rgLro.Value;

            _resourceGroupIdentifier = rg.Id;
            VirtualNetworkData vnetData = new VirtualNetworkData();

            vnetData.Location     = AzureLocation.WestUS2;
            vnetData.AddressSpace = new AddressSpace();
            vnetData.AddressSpace.AddressPrefixes.Add("10.0.0.0/16");
            var vnetLro = await rg.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, SessionRecording.GenerateAssetName("vnet-"), vnetData);

            VirtualNetwork vnet       = vnetLro.Value;
            SubnetData     subnetData = new SubnetData();

            subnetData.AddressPrefix = "10.0.0.0/24";
            var subnetLro = await vnet.GetSubnets().CreateOrUpdateAsync(WaitUntil.Completed, "AzureBastionSubnet", subnetData);

            _subnetIdentifier = subnetLro.Value.Id;
            PublicIPAddressData ipData = new PublicIPAddressData();

            ipData.Location = AzureLocation.WestUS2;
            ipData.PublicIPAllocationMethod = IPAllocationMethod.Static;
            ipData.Sku      = new PublicIPAddressSku();
            ipData.Sku.Name = PublicIPAddressSkuName.Standard;
            var ipLro = await rg.GetPublicIPAddresses().CreateOrUpdateAsync(WaitUntil.Completed, SessionRecording.GenerateAssetName("ip-"), ipData);

            _publicIPAddressIdentifier = ipLro.Value.Id;
            _bastionName = SessionRecording.GenerateAssetName("bastion-");
            await StopSessionRecordingAsync();
        }
示例#3
0
        public async Task TestSetUp()
        {
            var client = GetArmClient();

            _resourceGroup = await client.GetResourceGroup(_resourceGroupIdentifier).GetAsync();

            VirtualNetwork vnet = await _resourceGroup.GetVirtualNetworks().GetAsync(_subnetIdentifier.Parent.Name);

            _subnet = await vnet.GetSubnets().GetAsync(_subnetIdentifier.Name);

            _publicIPAddress = await _resourceGroup.GetPublicIPAddresses().GetAsync(_publicIPAddressIdentifier.Name);
        }
示例#4
0
        public async Task TestSetUp()
        {
            var client = GetArmClient();
            var _      = await client.GetDefaultSubscriptionAsync(); // TODO: hack to avoid mismatch of recordings so we don't need to re-record for the change. Remove when you need to run live tests next time.

            _resourceGroup = await client.GetResourceGroup(_resourceGroupIdentifier).GetAsync();

            VirtualNetwork vnet = await _resourceGroup.GetVirtualNetworks().GetAsync(_subnetIdentifier.Parent.Name);

            _subnet = await vnet.GetSubnets().GetAsync(_subnetIdentifier.Name);

            _publicIPAddress = await _resourceGroup.GetPublicIPAddresses().GetAsync(_publicIPAddressIdentifier.Name);
        }