Пример #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 <PrivateEndpointResource> CreateDefaultPrivateEndpoint(ManagedInstanceResource managedInstance, VirtualNetworkResource vnet, AzureLocation location, ResourceGroupResource resourceGroup)
        {
            // Add new subnet
            SubnetData subnetData = new SubnetData()
            {
                AddressPrefix = "10.10.5.0/24",
                PrivateEndpointNetworkPolicies = "Disabled"
            };
            var privateEndpointSubnet = await vnet.GetSubnets().CreateOrUpdateAsync(WaitUntil.Completed, $"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(WaitUntil.Completed, privateEndpointName, data);

            return(privateEndpoint.Value);
        }
Пример #2
0
        public async Task Get()
        {
            #region Snippet:Managing_Sql_GetAManagedInstance
            ManagedInstanceCollection managedInstanceCollection = resourceGroup.GetManagedInstances();

            ManagedInstanceResource managedInstance = await managedInstanceCollection.GetAsync("myManagedInstance");

            Console.WriteLine(managedInstance.Data.Name);
            #endregion
        }
Пример #3
0
        public async Task DeleteManagedInstance()
        {
            #region Snippet:Managing_Sql_DeleteAManagedInstance
            ManagedInstanceCollection managedInstanceCollection = resourceGroup.GetManagedInstances();

            ManagedInstanceResource managedInstance = await managedInstanceCollection.GetAsync("myManagedInstance");

            await managedInstance.DeleteAsync(WaitUntil.Completed);

            #endregion
        }
Пример #4
0
        public async Task CreateOrUpdate()
        {
            #region Snippet:Managing_Sql_CreateAManagedInstance
            //1. create NetworkSecurityGroup
            NetworkSecurityGroupData networkSecurityGroupData = new NetworkSecurityGroupData()
            {
                Location = AzureLocation.WestUS2,
            };
            string networkSecurityGroupName = "myNetworkSecurityGroup";
            var    networkSecurityGroup     = await resourceGroup.GetNetworkSecurityGroups().CreateOrUpdateAsync(WaitUntil.Completed, networkSecurityGroupName, networkSecurityGroupData);

            //2. create Route table
            RouteTableData routeTableData = new RouteTableData()
            {
                Location = AzureLocation.WestUS2,
            };
            string routeTableName = "myRouteTable";
            var    routeTable     = await resourceGroup.GetRouteTables().CreateOrUpdateAsync(WaitUntil.Completed, routeTableName, routeTableData);

            //3. create vnet(subnet binding NetworkSecurityGroup and RouteTable)
            var vnetData = new VirtualNetworkData()
            {
                Location = AzureLocation.WestUS2,
                Subnets  =
                {
                    new SubnetData()
                    {
                        Name          = "ManagedInstance",
                        AddressPrefix = "10.10.2.0/24",
                        Delegations   =
                        {
                            new Delegation()
                            {
                                ServiceName = "Microsoft.Sql/managedInstances", Name = "Microsoft.Sql/managedInstances", ResourceType = "Microsoft.Sql"
                            }
                        },
                        RouteTable = new RouteTableData()
                        {
                            Id = routeTable.Value.Data.Id
                        },
                        NetworkSecurityGroup = new NetworkSecurityGroupData()
                        {
                            Id = networkSecurityGroup.Value.Data.Id
                        },
                    }
                },
            };
            vnetData.AddressPrefixes.Add("10.10.0.0/16");
            string vnetName = "myVnet";
            var    vnet     = await resourceGroup.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, vnetName, vnetData);

            string subnetId = $"{vnet.Value.Data.Id}/subnets/ManagedInstance";

            //4. create ManagedInstance
            ManagedInstanceData data = new ManagedInstanceData(AzureLocation.WestUS2)
            {
                AdministratorLogin         = "******",
                AdministratorLoginPassword = "******",
                SubnetId = subnetId,
                PublicDataEndpointEnabled  = false,
                MaintenanceConfigurationId = "/subscriptions/0000-0000-0000-0000/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default",
                ProxyOverride = new ManagedInstanceProxyOverride("Proxy")
                {
                },
                TimezoneId    = "UTC",
                ZoneRedundant = false,
            };
            string managedInstanceName = "myManagedInstance";
            var    managedInstanceLro  = await resourceGroup.GetManagedInstances().CreateOrUpdateAsync(WaitUntil.Completed, managedInstanceName, data);

            ManagedInstanceResource managedInstance = managedInstanceLro.Value;
            #endregion
        }
        protected async Task initialize()
        {
            ArmClient            armClient    = new ArmClient(new DefaultAzureCredential());
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();

            ResourceGroupCollection rgCollection = subscription.GetResourceGroups();
            // With the collection, we can create a new resource group with an specific name
            string                rgName        = "myRgName";
            AzureLocation         location      = AzureLocation.WestUS2;
            ResourceGroupResource resourceGroup = await rgCollection.CreateOrUpdate(WaitUntil.Completed, rgName, new ResourceGroupData(location)).WaitForCompletionAsync();

            this.resourceGroup = resourceGroup;

            //1. create NetworkSecurityGroup
            NetworkSecurityGroupData networkSecurityGroupData = new NetworkSecurityGroupData()
            {
                Location = AzureLocation.WestUS2,
            };
            string networkSecurityGroupName = "myNetworkSecurityGroup";
            var    networkSecurityGroup     = await resourceGroup.GetNetworkSecurityGroups().CreateOrUpdateAsync(WaitUntil.Completed, networkSecurityGroupName, networkSecurityGroupData);

            //2. create Route table
            RouteTableData routeTableData = new RouteTableData()
            {
                Location = AzureLocation.WestUS2,
            };
            string routeTableName = "myRouteTable";
            var    routeTable     = await resourceGroup.GetRouteTables().CreateOrUpdateAsync(WaitUntil.Completed, routeTableName, routeTableData);

            //3. create vnet(subnet binding NetworkSecurityGroup and RouteTable)
            var vnetData = new VirtualNetworkData()
            {
                Location = AzureLocation.WestUS2,
                Subnets  =
                {
                    new SubnetData()
                    {
                        Name          = "ManagedInstance",
                        AddressPrefix = "10.10.2.0/24",
                        Delegations   =
                        {
                            new Delegation()
                            {
                                ServiceName = "Microsoft.Sql/managedInstances", Name = "Microsoft.Sql/managedInstances", ResourceType = "Microsoft.Sql"
                            }
                        },
                        RouteTable = new RouteTableData()
                        {
                            Id = routeTable.Value.Data.Id.ToString()
                        },
                        NetworkSecurityGroup = new NetworkSecurityGroupData()
                        {
                            Id = networkSecurityGroup.Value.Data.Id.ToString()
                        },
                    }
                },
            };

            vnetData.AddressPrefixes.Add("10.10.0.0/16");
            string vnetName = "myVnet";
            var    vnet     = await resourceGroup.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, vnetName, vnetData);

            string subnetId = $"{vnet.Value.Data.Id}/subnets/ManagedInstance";

            //4. create ManagedInstance
            ManagedInstanceData data = new ManagedInstanceData(AzureLocation.WestUS2)
            {
                AdministratorLogin         = "******",
                AdministratorLoginPassword = "******",
                SubnetId = subnetId,
                PublicDataEndpointEnabled  = false,
                MaintenanceConfigurationId = "/subscriptions/0000-0000-0000-0000/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default",
                ProxyOverride = new ManagedInstanceProxyOverride("Proxy")
                {
                },
                TimezoneId         = "UTC",
                StorageAccountType = new StorageAccountType("GRS"),
                ZoneRedundant      = false,
            };
            string managedInstanceName = "myManagedInstance";
            var    managedInstanceLro  = await resourceGroup.GetManagedInstances().CreateOrUpdateAsync(WaitUntil.Completed, managedInstanceName, data);

            managedInstance = managedInstanceLro.Value;
        }