1. Packages
  2. Azure Classic
  3. API Docs
  4. sql
  5. VirtualNetworkRule

We recommend using Azure Native.

Viewing docs for Azure v4.42.0 (Older version)
published on Monday, Mar 9, 2026 by Pulumi
azure logo

We recommend using Azure Native.

Viewing docs for Azure v4.42.0 (Older version)
published on Monday, Mar 9, 2026 by Pulumi

    Import

    SQL Virtual Network Rules can be imported using the resource id, e.g.

     $ pulumi import azure:sql/virtualNetworkRule:VirtualNetworkRule rule1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Sql/servers/myserver/virtualNetworkRules/vnetrulename
    

    Example Usage

    using Pulumi;
    using Azure = Pulumi.Azure;
    
    class MyStack : Stack
    {
        public MyStack()
        {
            var example = new Azure.Core.ResourceGroup("example", new Azure.Core.ResourceGroupArgs
            {
                Location = "West Europe",
            });
            var vnet = new Azure.Network.VirtualNetwork("vnet", new Azure.Network.VirtualNetworkArgs
            {
                AddressSpaces = 
                {
                    "10.7.29.0/29",
                },
                Location = example.Location,
                ResourceGroupName = example.Name,
            });
            var subnet = new Azure.Network.Subnet("subnet", new Azure.Network.SubnetArgs
            {
                ResourceGroupName = example.Name,
                VirtualNetworkName = vnet.Name,
                AddressPrefixes = 
                {
                    "10.7.29.0/29",
                },
                ServiceEndpoints = 
                {
                    "Microsoft.Sql",
                },
            });
            var sqlserver = new Azure.Sql.SqlServer("sqlserver", new Azure.Sql.SqlServerArgs
            {
                ResourceGroupName = example.Name,
                Location = example.Location,
                Version = "12.0",
                AdministratorLogin = "4dm1n157r470r",
                AdministratorLoginPassword = "4-v3ry-53cr37-p455w0rd",
            });
            var sqlvnetrule = new Azure.Sql.VirtualNetworkRule("sqlvnetrule", new Azure.Sql.VirtualNetworkRuleArgs
            {
                ResourceGroupName = example.Name,
                ServerName = sqlserver.Name,
                SubnetId = subnet.Id,
            });
        }
    
    }
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azure/sdk/v4/go/azure/core"
    	"github.com/pulumi/pulumi-azure/sdk/v4/go/azure/network"
    	"github.com/pulumi/pulumi-azure/sdk/v4/go/azure/sql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := core.NewResourceGroup(ctx, "example", &core.ResourceGroupArgs{
    			Location: pulumi.String("West Europe"),
    		})
    		if err != nil {
    			return err
    		}
    		vnet, err := network.NewVirtualNetwork(ctx, "vnet", &network.VirtualNetworkArgs{
    			AddressSpaces: pulumi.StringArray{
    				pulumi.String("10.7.29.0/29"),
    			},
    			Location:          example.Location,
    			ResourceGroupName: example.Name,
    		})
    		if err != nil {
    			return err
    		}
    		subnet, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
    			ResourceGroupName:  example.Name,
    			VirtualNetworkName: vnet.Name,
    			AddressPrefixes: pulumi.StringArray{
    				pulumi.String("10.7.29.0/29"),
    			},
    			ServiceEndpoints: pulumi.StringArray{
    				pulumi.String("Microsoft.Sql"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		sqlserver, err := sql.NewSqlServer(ctx, "sqlserver", &sql.SqlServerArgs{
    			ResourceGroupName:          example.Name,
    			Location:                   example.Location,
    			Version:                    pulumi.String("12.0"),
    			AdministratorLogin:         pulumi.String("4dm1n157r470r"),
    			AdministratorLoginPassword: pulumi.String("4-v3ry-53cr37-p455w0rd"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = sql.NewVirtualNetworkRule(ctx, "sqlvnetrule", &sql.VirtualNetworkRuleArgs{
    			ResourceGroupName: example.Name,
    			ServerName:        sqlserver.Name,
    			SubnetId:          subnet.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    

    Example coming soon!

    import * as pulumi from "@pulumi/pulumi";
    import * as azure from "@pulumi/azure";
    
    const example = new azure.core.ResourceGroup("example", {location: "West Europe"});
    const vnet = new azure.network.VirtualNetwork("vnet", {
        addressSpaces: ["10.7.29.0/29"],
        location: example.location,
        resourceGroupName: example.name,
    });
    const subnet = new azure.network.Subnet("subnet", {
        resourceGroupName: example.name,
        virtualNetworkName: vnet.name,
        addressPrefixes: ["10.7.29.0/29"],
        serviceEndpoints: ["Microsoft.Sql"],
    });
    const sqlserver = new azure.sql.SqlServer("sqlserver", {
        resourceGroupName: example.name,
        location: example.location,
        version: "12.0",
        administratorLogin: "4dm1n157r470r",
        administratorLoginPassword: "4-v3ry-53cr37-p455w0rd",
    });
    const sqlvnetrule = new azure.sql.VirtualNetworkRule("sqlvnetrule", {
        resourceGroupName: example.name,
        serverName: sqlserver.name,
        subnetId: subnet.id,
    });
    
    import pulumi
    import pulumi_azure as azure
    
    example = azure.core.ResourceGroup("example", location="West Europe")
    vnet = azure.network.VirtualNetwork("vnet",
        address_spaces=["10.7.29.0/29"],
        location=example.location,
        resource_group_name=example.name)
    subnet = azure.network.Subnet("subnet",
        resource_group_name=example.name,
        virtual_network_name=vnet.name,
        address_prefixes=["10.7.29.0/29"],
        service_endpoints=["Microsoft.Sql"])
    sqlserver = azure.sql.SqlServer("sqlserver",
        resource_group_name=example.name,
        location=example.location,
        version="12.0",
        administrator_login="4dm1n157r470r",
        administrator_login_password="4-v3ry-53cr37-p455w0rd")
    sqlvnetrule = azure.sql.VirtualNetworkRule("sqlvnetrule",
        resource_group_name=example.name,
        server_name=sqlserver.name,
        subnet_id=subnet.id)
    

    Example coming soon!

    Create VirtualNetworkRule Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new VirtualNetworkRule(name: string, args: VirtualNetworkRuleArgs, opts?: CustomResourceOptions);
    @overload
    def VirtualNetworkRule(resource_name: str,
                           args: VirtualNetworkRuleArgs,
                           opts: Optional[ResourceOptions] = None)
    
    @overload
    def VirtualNetworkRule(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           resource_group_name: Optional[str] = None,
                           server_name: Optional[str] = None,
                           subnet_id: Optional[str] = None,
                           ignore_missing_vnet_service_endpoint: Optional[bool] = None,
                           name: Optional[str] = None)
    func NewVirtualNetworkRule(ctx *Context, name string, args VirtualNetworkRuleArgs, opts ...ResourceOption) (*VirtualNetworkRule, error)
    public VirtualNetworkRule(string name, VirtualNetworkRuleArgs args, CustomResourceOptions? opts = null)
    public VirtualNetworkRule(String name, VirtualNetworkRuleArgs args)
    public VirtualNetworkRule(String name, VirtualNetworkRuleArgs args, CustomResourceOptions options)
    
    type: azure:sql:VirtualNetworkRule
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args VirtualNetworkRuleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args VirtualNetworkRuleArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args VirtualNetworkRuleArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args VirtualNetworkRuleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args VirtualNetworkRuleArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule = new Azure.Sql.VirtualNetworkRule("examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule", new()
    {
        ResourceGroupName = "string",
        ServerName = "string",
        SubnetId = "string",
        IgnoreMissingVnetServiceEndpoint = false,
        Name = "string",
    });
    
    example, err := sql.NewVirtualNetworkRule(ctx, "examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule", &sql.VirtualNetworkRuleArgs{
    	ResourceGroupName:                pulumi.String("string"),
    	ServerName:                       pulumi.String("string"),
    	SubnetId:                         pulumi.String("string"),
    	IgnoreMissingVnetServiceEndpoint: pulumi.Bool(false),
    	Name:                             pulumi.String("string"),
    })
    
    var examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule = new com.pulumi.azure.sql.VirtualNetworkRule("examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule", com.pulumi.azure.sql.VirtualNetworkRuleArgs.builder()
        .resourceGroupName("string")
        .serverName("string")
        .subnetId("string")
        .ignoreMissingVnetServiceEndpoint(false)
        .name("string")
        .build());
    
    examplevirtual_network_rule_resource_resource_from_sqlvirtual_network_rule = azure.sql.VirtualNetworkRule("examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule",
        resource_group_name="string",
        server_name="string",
        subnet_id="string",
        ignore_missing_vnet_service_endpoint=False,
        name="string")
    
    const examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule = new azure.sql.VirtualNetworkRule("examplevirtualNetworkRuleResourceResourceFromSqlvirtualNetworkRule", {
        resourceGroupName: "string",
        serverName: "string",
        subnetId: "string",
        ignoreMissingVnetServiceEndpoint: false,
        name: "string",
    });
    
    type: azure:sql:VirtualNetworkRule
    properties:
        ignoreMissingVnetServiceEndpoint: false
        name: string
        resourceGroupName: string
        serverName: string
        subnetId: string
    

    VirtualNetworkRule Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The VirtualNetworkRule resource accepts the following input properties:

    ResourceGroupName string
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    ServerName string
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the subnet that the SQL server will be connected to.
    IgnoreMissingVnetServiceEndpoint bool
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    Name string
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    ResourceGroupName string
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    ServerName string
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the subnet that the SQL server will be connected to.
    IgnoreMissingVnetServiceEndpoint bool
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    Name string
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resourceGroupName String
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    serverName String
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnetId String
    The ID of the subnet that the SQL server will be connected to.
    ignoreMissingVnetServiceEndpoint Boolean
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name String
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resourceGroupName string
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    serverName string
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnetId string
    The ID of the subnet that the SQL server will be connected to.
    ignoreMissingVnetServiceEndpoint boolean
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name string
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resource_group_name str
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    server_name str
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnet_id str
    The ID of the subnet that the SQL server will be connected to.
    ignore_missing_vnet_service_endpoint bool
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name str
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resourceGroupName String
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    serverName String
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnetId String
    The ID of the subnet that the SQL server will be connected to.
    ignoreMissingVnetServiceEndpoint Boolean
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name String
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the VirtualNetworkRule resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing VirtualNetworkRule Resource

    Get an existing VirtualNetworkRule resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: VirtualNetworkRuleState, opts?: CustomResourceOptions): VirtualNetworkRule
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            ignore_missing_vnet_service_endpoint: Optional[bool] = None,
            name: Optional[str] = None,
            resource_group_name: Optional[str] = None,
            server_name: Optional[str] = None,
            subnet_id: Optional[str] = None) -> VirtualNetworkRule
    func GetVirtualNetworkRule(ctx *Context, name string, id IDInput, state *VirtualNetworkRuleState, opts ...ResourceOption) (*VirtualNetworkRule, error)
    public static VirtualNetworkRule Get(string name, Input<string> id, VirtualNetworkRuleState? state, CustomResourceOptions? opts = null)
    public static VirtualNetworkRule get(String name, Output<String> id, VirtualNetworkRuleState state, CustomResourceOptions options)
    resources:  _:    type: azure:sql:VirtualNetworkRule    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    IgnoreMissingVnetServiceEndpoint bool
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    Name string
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    ResourceGroupName string
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    ServerName string
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the subnet that the SQL server will be connected to.
    IgnoreMissingVnetServiceEndpoint bool
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    Name string
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    ResourceGroupName string
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    ServerName string
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the subnet that the SQL server will be connected to.
    ignoreMissingVnetServiceEndpoint Boolean
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name String
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resourceGroupName String
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    serverName String
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnetId String
    The ID of the subnet that the SQL server will be connected to.
    ignoreMissingVnetServiceEndpoint boolean
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name string
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resourceGroupName string
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    serverName string
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnetId string
    The ID of the subnet that the SQL server will be connected to.
    ignore_missing_vnet_service_endpoint bool
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name str
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resource_group_name str
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    server_name str
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnet_id str
    The ID of the subnet that the SQL server will be connected to.
    ignoreMissingVnetServiceEndpoint Boolean
    Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.
    name String
    The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.
    resourceGroupName String
    The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.
    serverName String
    The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.
    subnetId String
    The ID of the subnet that the SQL server will be connected to.

    Package Details

    Repository
    Azure Classic pulumi/pulumi-azure
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the azurerm Terraform Provider.
    azure logo

    We recommend using Azure Native.

    Viewing docs for Azure v4.42.0 (Older version)
    published on Monday, Mar 9, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.