1. Packages
  2. Packages
  3. Azure Classic
  4. API Docs
  5. network
  6. SubnetRouteTableAssociation

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

    Associates a Route Table with a Subnet within a Virtual Network.

    Example Usage

    using Pulumi;
    using Azure = Pulumi.Azure;
    
    class MyStack : Stack
    {
        public MyStack()
        {
            var exampleResourceGroup = new Azure.Core.ResourceGroup("exampleResourceGroup", new Azure.Core.ResourceGroupArgs
            {
                Location = "West Europe",
            });
            var exampleVirtualNetwork = new Azure.Network.VirtualNetwork("exampleVirtualNetwork", new Azure.Network.VirtualNetworkArgs
            {
                AddressSpaces = 
                {
                    "10.0.0.0/16",
                },
                Location = exampleResourceGroup.Location,
                ResourceGroupName = exampleResourceGroup.Name,
            });
            var exampleSubnet = new Azure.Network.Subnet("exampleSubnet", new Azure.Network.SubnetArgs
            {
                ResourceGroupName = exampleResourceGroup.Name,
                VirtualNetworkName = exampleVirtualNetwork.Name,
                AddressPrefixes = 
                {
                    "10.0.2.0/24",
                },
            });
            var exampleRouteTable = new Azure.Network.RouteTable("exampleRouteTable", new Azure.Network.RouteTableArgs
            {
                Location = exampleResourceGroup.Location,
                ResourceGroupName = exampleResourceGroup.Name,
                Routes = 
                {
                    new Azure.Network.Inputs.RouteTableRouteArgs
                    {
                        Name = "example",
                        AddressPrefix = "10.100.0.0/14",
                        NextHopType = "VirtualAppliance",
                        NextHopInIpAddress = "10.10.1.1",
                    },
                },
            });
            var exampleSubnetRouteTableAssociation = new Azure.Network.SubnetRouteTableAssociation("exampleSubnetRouteTableAssociation", new Azure.Network.SubnetRouteTableAssociationArgs
            {
                SubnetId = exampleSubnet.Id,
                RouteTableId = exampleRouteTable.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/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		exampleResourceGroup, err := core.NewResourceGroup(ctx, "exampleResourceGroup", &core.ResourceGroupArgs{
    			Location: pulumi.String("West Europe"),
    		})
    		if err != nil {
    			return err
    		}
    		exampleVirtualNetwork, err := network.NewVirtualNetwork(ctx, "exampleVirtualNetwork", &network.VirtualNetworkArgs{
    			AddressSpaces: pulumi.StringArray{
    				pulumi.String("10.0.0.0/16"),
    			},
    			Location:          exampleResourceGroup.Location,
    			ResourceGroupName: exampleResourceGroup.Name,
    		})
    		if err != nil {
    			return err
    		}
    		exampleSubnet, err := network.NewSubnet(ctx, "exampleSubnet", &network.SubnetArgs{
    			ResourceGroupName:  exampleResourceGroup.Name,
    			VirtualNetworkName: exampleVirtualNetwork.Name,
    			AddressPrefixes: pulumi.StringArray{
    				pulumi.String("10.0.2.0/24"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		exampleRouteTable, err := network.NewRouteTable(ctx, "exampleRouteTable", &network.RouteTableArgs{
    			Location:          exampleResourceGroup.Location,
    			ResourceGroupName: exampleResourceGroup.Name,
    			Routes: network.RouteTableRouteArray{
    				&network.RouteTableRouteArgs{
    					Name:               pulumi.String("example"),
    					AddressPrefix:      pulumi.String("10.100.0.0/14"),
    					NextHopType:        pulumi.String("VirtualAppliance"),
    					NextHopInIpAddress: pulumi.String("10.10.1.1"),
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = network.NewSubnetRouteTableAssociation(ctx, "exampleSubnetRouteTableAssociation", &network.SubnetRouteTableAssociationArgs{
    			SubnetId:     exampleSubnet.ID(),
    			RouteTableId: exampleRouteTable.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    

    Example coming soon!

    import * as pulumi from "@pulumi/pulumi";
    import * as azure from "@pulumi/azure";
    
    const exampleResourceGroup = new azure.core.ResourceGroup("exampleResourceGroup", {location: "West Europe"});
    const exampleVirtualNetwork = new azure.network.VirtualNetwork("exampleVirtualNetwork", {
        addressSpaces: ["10.0.0.0/16"],
        location: exampleResourceGroup.location,
        resourceGroupName: exampleResourceGroup.name,
    });
    const exampleSubnet = new azure.network.Subnet("exampleSubnet", {
        resourceGroupName: exampleResourceGroup.name,
        virtualNetworkName: exampleVirtualNetwork.name,
        addressPrefixes: ["10.0.2.0/24"],
    });
    const exampleRouteTable = new azure.network.RouteTable("exampleRouteTable", {
        location: exampleResourceGroup.location,
        resourceGroupName: exampleResourceGroup.name,
        routes: [{
            name: "example",
            addressPrefix: "10.100.0.0/14",
            nextHopType: "VirtualAppliance",
            nextHopInIpAddress: "10.10.1.1",
        }],
    });
    const exampleSubnetRouteTableAssociation = new azure.network.SubnetRouteTableAssociation("exampleSubnetRouteTableAssociation", {
        subnetId: exampleSubnet.id,
        routeTableId: exampleRouteTable.id,
    });
    
    import pulumi
    import pulumi_azure as azure
    
    example_resource_group = azure.core.ResourceGroup("exampleResourceGroup", location="West Europe")
    example_virtual_network = azure.network.VirtualNetwork("exampleVirtualNetwork",
        address_spaces=["10.0.0.0/16"],
        location=example_resource_group.location,
        resource_group_name=example_resource_group.name)
    example_subnet = azure.network.Subnet("exampleSubnet",
        resource_group_name=example_resource_group.name,
        virtual_network_name=example_virtual_network.name,
        address_prefixes=["10.0.2.0/24"])
    example_route_table = azure.network.RouteTable("exampleRouteTable",
        location=example_resource_group.location,
        resource_group_name=example_resource_group.name,
        routes=[azure.network.RouteTableRouteArgs(
            name="example",
            address_prefix="10.100.0.0/14",
            next_hop_type="VirtualAppliance",
            next_hop_in_ip_address="10.10.1.1",
        )])
    example_subnet_route_table_association = azure.network.SubnetRouteTableAssociation("exampleSubnetRouteTableAssociation",
        subnet_id=example_subnet.id,
        route_table_id=example_route_table.id)
    

    Example coming soon!

    Create SubnetRouteTableAssociation Resource

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

    Constructor syntax

    new SubnetRouteTableAssociation(name: string, args: SubnetRouteTableAssociationArgs, opts?: CustomResourceOptions);
    @overload
    def SubnetRouteTableAssociation(resource_name: str,
                                    args: SubnetRouteTableAssociationArgs,
                                    opts: Optional[ResourceOptions] = None)
    
    @overload
    def SubnetRouteTableAssociation(resource_name: str,
                                    opts: Optional[ResourceOptions] = None,
                                    route_table_id: Optional[str] = None,
                                    subnet_id: Optional[str] = None)
    func NewSubnetRouteTableAssociation(ctx *Context, name string, args SubnetRouteTableAssociationArgs, opts ...ResourceOption) (*SubnetRouteTableAssociation, error)
    public SubnetRouteTableAssociation(string name, SubnetRouteTableAssociationArgs args, CustomResourceOptions? opts = null)
    public SubnetRouteTableAssociation(String name, SubnetRouteTableAssociationArgs args)
    public SubnetRouteTableAssociation(String name, SubnetRouteTableAssociationArgs args, CustomResourceOptions options)
    
    type: azure:network:SubnetRouteTableAssociation
    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 SubnetRouteTableAssociationArgs
    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 SubnetRouteTableAssociationArgs
    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 SubnetRouteTableAssociationArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args SubnetRouteTableAssociationArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args SubnetRouteTableAssociationArgs
    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 subnetRouteTableAssociationResource = new Azure.Network.SubnetRouteTableAssociation("subnetRouteTableAssociationResource", new()
    {
        RouteTableId = "string",
        SubnetId = "string",
    });
    
    example, err := network.NewSubnetRouteTableAssociation(ctx, "subnetRouteTableAssociationResource", &network.SubnetRouteTableAssociationArgs{
    	RouteTableId: pulumi.String("string"),
    	SubnetId:     pulumi.String("string"),
    })
    
    var subnetRouteTableAssociationResource = new SubnetRouteTableAssociation("subnetRouteTableAssociationResource", SubnetRouteTableAssociationArgs.builder()
        .routeTableId("string")
        .subnetId("string")
        .build());
    
    subnet_route_table_association_resource = azure.network.SubnetRouteTableAssociation("subnetRouteTableAssociationResource",
        route_table_id="string",
        subnet_id="string")
    
    const subnetRouteTableAssociationResource = new azure.network.SubnetRouteTableAssociation("subnetRouteTableAssociationResource", {
        routeTableId: "string",
        subnetId: "string",
    });
    
    type: azure:network:SubnetRouteTableAssociation
    properties:
        routeTableId: string
        subnetId: string
    

    SubnetRouteTableAssociation 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 SubnetRouteTableAssociation resource accepts the following input properties:

    RouteTableId string
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the Subnet. Changing this forces a new resource to be created.
    RouteTableId string
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the Subnet. Changing this forces a new resource to be created.
    routeTableId String
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnetId String
    The ID of the Subnet. Changing this forces a new resource to be created.
    routeTableId string
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnetId string
    The ID of the Subnet. Changing this forces a new resource to be created.
    route_table_id str
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnet_id str
    The ID of the Subnet. Changing this forces a new resource to be created.
    routeTableId String
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnetId String
    The ID of the Subnet. Changing this forces a new resource to be created.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the SubnetRouteTableAssociation 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 SubnetRouteTableAssociation Resource

    Get an existing SubnetRouteTableAssociation 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?: SubnetRouteTableAssociationState, opts?: CustomResourceOptions): SubnetRouteTableAssociation
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            route_table_id: Optional[str] = None,
            subnet_id: Optional[str] = None) -> SubnetRouteTableAssociation
    func GetSubnetRouteTableAssociation(ctx *Context, name string, id IDInput, state *SubnetRouteTableAssociationState, opts ...ResourceOption) (*SubnetRouteTableAssociation, error)
    public static SubnetRouteTableAssociation Get(string name, Input<string> id, SubnetRouteTableAssociationState? state, CustomResourceOptions? opts = null)
    public static SubnetRouteTableAssociation get(String name, Output<String> id, SubnetRouteTableAssociationState state, CustomResourceOptions options)
    resources:  _:    type: azure:network:SubnetRouteTableAssociation    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:
    RouteTableId string
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the Subnet. Changing this forces a new resource to be created.
    RouteTableId string
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    SubnetId string
    The ID of the Subnet. Changing this forces a new resource to be created.
    routeTableId String
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnetId String
    The ID of the Subnet. Changing this forces a new resource to be created.
    routeTableId string
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnetId string
    The ID of the Subnet. Changing this forces a new resource to be created.
    route_table_id str
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnet_id str
    The ID of the Subnet. Changing this forces a new resource to be created.
    routeTableId String
    The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.
    subnetId String
    The ID of the Subnet. Changing this forces a new resource to be created.

    Import

    Subnet Route Table Associations can be imported using the resource id of the Subnet, e.g.

     $ pulumi import azure:network/subnetRouteTableAssociation:SubnetRouteTableAssociation association1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1
    

    To learn more about importing existing cloud resources, see Importing resources.

    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.

      Start free trial