Skip to content

azurermSubnetRouteTableAssociation

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

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermRouteTableExample = new azurerm.routeTable.RouteTable(
  this,
  "example_1",
  {
    location: azurermResourceGroupExample.location,
    name: "example-routetable",
    resource_group_name: azurermResourceGroupExample.name,
    route: [
      {
        address_prefix: "10.100.0.0/14",
        name: "example",
        next_hop_in_ip_address: "10.10.1.1",
        next_hop_type: "VirtualAppliance",
      },
    ],
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermRouteTableExample.overrideLogicalId("example");
const azurermVirtualNetworkExample = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "example_2",
  {
    address_space: ["10.0.0.0/16"],
    location: azurermResourceGroupExample.location,
    name: "example-network",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermVirtualNetworkExample.overrideLogicalId("example");
const azurermSubnetExample = new azurerm.subnet.Subnet(this, "example_3", {
  address_prefixes: ["10.0.2.0/24"],
  name: "frontend",
  resource_group_name: azurermResourceGroupExample.name,
  virtual_network_name: azurermVirtualNetworkExample.name,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetExample.overrideLogicalId("example");
const azurermSubnetRouteTableAssociationExample =
  new azurerm.subnetRouteTableAssociation.SubnetRouteTableAssociation(
    this,
    "example_4",
    {
      route_table_id: azurermRouteTableExample.id,
      subnet_id: azurermSubnetExample.id,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetRouteTableAssociationExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • routeTableId - (Required) The ID of the Route Table which should be associated with the Subnet. Changing this forces a new resource to be created.

  • subnetId - (Required) The ID of the Subnet. Changing this forces a new resource to be created.

Attributes Reference

The following attributes are exported:

  • id - The ID of the Subnet.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Subnet Route Table Association.
  • update - (Defaults to 30 minutes) Used when updating the Subnet Route Table Association.
  • read - (Defaults to 5 minutes) Used when retrieving the Subnet Route Table Association.
  • delete - (Defaults to 30 minutes) Used when deleting the Subnet Route Table Association.

Import

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

terraform import azurerm_subnet_route_table_association.association1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1