1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. vpc
  5. RouteTableAttachment
Alibaba Cloud v3.75.0 published on Friday, Mar 7, 2025 by Pulumi

alicloud.vpc.RouteTableAttachment

Explore with Pulumi AI

Provides a VPC Route Table Attachment resource. Routing table associated resource type.

For information about VPC Route Table Attachment and how to use it, see What is Route Table Attachment.

NOTE: Available since v1.194.0.

Example Usage

Basic Usage

import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";

const config = new pulumi.Config();
const name = config.get("name") || "terraform-example";
const foo = new alicloud.vpc.Network("foo", {
    cidrBlock: "172.16.0.0/12",
    vpcName: name,
});
const _default = alicloud.getZones({
    availableResourceCreation: "VSwitch",
});
const fooSwitch = new alicloud.vpc.Switch("foo", {
    vpcId: foo.id,
    cidrBlock: "172.16.0.0/21",
    zoneId: _default.then(_default => _default.zones?.[0]?.id),
    vswitchName: name,
});
const fooRouteTable = new alicloud.vpc.RouteTable("foo", {
    vpcId: foo.id,
    routeTableName: name,
    description: "route_table_attachment",
});
const fooRouteTableAttachment = new alicloud.vpc.RouteTableAttachment("foo", {
    vswitchId: fooSwitch.id,
    routeTableId: fooRouteTable.id,
});
Copy
import pulumi
import pulumi_alicloud as alicloud

config = pulumi.Config()
name = config.get("name")
if name is None:
    name = "terraform-example"
foo = alicloud.vpc.Network("foo",
    cidr_block="172.16.0.0/12",
    vpc_name=name)
default = alicloud.get_zones(available_resource_creation="VSwitch")
foo_switch = alicloud.vpc.Switch("foo",
    vpc_id=foo.id,
    cidr_block="172.16.0.0/21",
    zone_id=default.zones[0].id,
    vswitch_name=name)
foo_route_table = alicloud.vpc.RouteTable("foo",
    vpc_id=foo.id,
    route_table_name=name,
    description="route_table_attachment")
foo_route_table_attachment = alicloud.vpc.RouteTableAttachment("foo",
    vswitch_id=foo_switch.id,
    route_table_id=foo_route_table.id)
Copy
package main

import (
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/vpc"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		name := "terraform-example"
		if param := cfg.Get("name"); param != "" {
			name = param
		}
		foo, err := vpc.NewNetwork(ctx, "foo", &vpc.NetworkArgs{
			CidrBlock: pulumi.String("172.16.0.0/12"),
			VpcName:   pulumi.String(name),
		})
		if err != nil {
			return err
		}
		_default, err := alicloud.GetZones(ctx, &alicloud.GetZonesArgs{
			AvailableResourceCreation: pulumi.StringRef("VSwitch"),
		}, nil)
		if err != nil {
			return err
		}
		fooSwitch, err := vpc.NewSwitch(ctx, "foo", &vpc.SwitchArgs{
			VpcId:       foo.ID(),
			CidrBlock:   pulumi.String("172.16.0.0/21"),
			ZoneId:      pulumi.String(_default.Zones[0].Id),
			VswitchName: pulumi.String(name),
		})
		if err != nil {
			return err
		}
		fooRouteTable, err := vpc.NewRouteTable(ctx, "foo", &vpc.RouteTableArgs{
			VpcId:          foo.ID(),
			RouteTableName: pulumi.String(name),
			Description:    pulumi.String("route_table_attachment"),
		})
		if err != nil {
			return err
		}
		_, err = vpc.NewRouteTableAttachment(ctx, "foo", &vpc.RouteTableAttachmentArgs{
			VswitchId:    fooSwitch.ID(),
			RouteTableId: fooRouteTable.ID(),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

return await Deployment.RunAsync(() => 
{
    var config = new Config();
    var name = config.Get("name") ?? "terraform-example";
    var foo = new AliCloud.Vpc.Network("foo", new()
    {
        CidrBlock = "172.16.0.0/12",
        VpcName = name,
    });

    var @default = AliCloud.GetZones.Invoke(new()
    {
        AvailableResourceCreation = "VSwitch",
    });

    var fooSwitch = new AliCloud.Vpc.Switch("foo", new()
    {
        VpcId = foo.Id,
        CidrBlock = "172.16.0.0/21",
        ZoneId = @default.Apply(@default => @default.Apply(getZonesResult => getZonesResult.Zones[0]?.Id)),
        VswitchName = name,
    });

    var fooRouteTable = new AliCloud.Vpc.RouteTable("foo", new()
    {
        VpcId = foo.Id,
        RouteTableName = name,
        Description = "route_table_attachment",
    });

    var fooRouteTableAttachment = new AliCloud.Vpc.RouteTableAttachment("foo", new()
    {
        VswitchId = fooSwitch.Id,
        RouteTableId = fooRouteTable.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.vpc.Network;
import com.pulumi.alicloud.vpc.NetworkArgs;
import com.pulumi.alicloud.AlicloudFunctions;
import com.pulumi.alicloud.inputs.GetZonesArgs;
import com.pulumi.alicloud.vpc.Switch;
import com.pulumi.alicloud.vpc.SwitchArgs;
import com.pulumi.alicloud.vpc.RouteTable;
import com.pulumi.alicloud.vpc.RouteTableArgs;
import com.pulumi.alicloud.vpc.RouteTableAttachment;
import com.pulumi.alicloud.vpc.RouteTableAttachmentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var config = ctx.config();
        final var name = config.get("name").orElse("terraform-example");
        var foo = new Network("foo", NetworkArgs.builder()
            .cidrBlock("172.16.0.0/12")
            .vpcName(name)
            .build());

        final var default = AlicloudFunctions.getZones(GetZonesArgs.builder()
            .availableResourceCreation("VSwitch")
            .build());

        var fooSwitch = new Switch("fooSwitch", SwitchArgs.builder()
            .vpcId(foo.id())
            .cidrBlock("172.16.0.0/21")
            .zoneId(default_.zones()[0].id())
            .vswitchName(name)
            .build());

        var fooRouteTable = new RouteTable("fooRouteTable", RouteTableArgs.builder()
            .vpcId(foo.id())
            .routeTableName(name)
            .description("route_table_attachment")
            .build());

        var fooRouteTableAttachment = new RouteTableAttachment("fooRouteTableAttachment", RouteTableAttachmentArgs.builder()
            .vswitchId(fooSwitch.id())
            .routeTableId(fooRouteTable.id())
            .build());

    }
}
Copy
configuration:
  name:
    type: string
    default: terraform-example
resources:
  foo:
    type: alicloud:vpc:Network
    properties:
      cidrBlock: 172.16.0.0/12
      vpcName: ${name}
  fooSwitch:
    type: alicloud:vpc:Switch
    name: foo
    properties:
      vpcId: ${foo.id}
      cidrBlock: 172.16.0.0/21
      zoneId: ${default.zones[0].id}
      vswitchName: ${name}
  fooRouteTable:
    type: alicloud:vpc:RouteTable
    name: foo
    properties:
      vpcId: ${foo.id}
      routeTableName: ${name}
      description: route_table_attachment
  fooRouteTableAttachment:
    type: alicloud:vpc:RouteTableAttachment
    name: foo
    properties:
      vswitchId: ${fooSwitch.id}
      routeTableId: ${fooRouteTable.id}
variables:
  default:
    fn::invoke:
      function: alicloud:getZones
      arguments:
        availableResourceCreation: VSwitch
Copy

Create RouteTableAttachment Resource

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

Constructor syntax

new RouteTableAttachment(name: string, args: RouteTableAttachmentArgs, opts?: CustomResourceOptions);
@overload
def RouteTableAttachment(resource_name: str,
                         args: RouteTableAttachmentArgs,
                         opts: Optional[ResourceOptions] = None)

@overload
def RouteTableAttachment(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         route_table_id: Optional[str] = None,
                         vswitch_id: Optional[str] = None)
func NewRouteTableAttachment(ctx *Context, name string, args RouteTableAttachmentArgs, opts ...ResourceOption) (*RouteTableAttachment, error)
public RouteTableAttachment(string name, RouteTableAttachmentArgs args, CustomResourceOptions? opts = null)
public RouteTableAttachment(String name, RouteTableAttachmentArgs args)
public RouteTableAttachment(String name, RouteTableAttachmentArgs args, CustomResourceOptions options)
type: alicloud:vpc:RouteTableAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. RouteTableAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. RouteTableAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. RouteTableAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. RouteTableAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. RouteTableAttachmentArgs
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 routeTableAttachmentResource = new AliCloud.Vpc.RouteTableAttachment("routeTableAttachmentResource", new()
{
    RouteTableId = "string",
    VswitchId = "string",
});
Copy
example, err := vpc.NewRouteTableAttachment(ctx, "routeTableAttachmentResource", &vpc.RouteTableAttachmentArgs{
	RouteTableId: pulumi.String("string"),
	VswitchId:    pulumi.String("string"),
})
Copy
var routeTableAttachmentResource = new RouteTableAttachment("routeTableAttachmentResource", RouteTableAttachmentArgs.builder()
    .routeTableId("string")
    .vswitchId("string")
    .build());
Copy
route_table_attachment_resource = alicloud.vpc.RouteTableAttachment("routeTableAttachmentResource",
    route_table_id="string",
    vswitch_id="string")
Copy
const routeTableAttachmentResource = new alicloud.vpc.RouteTableAttachment("routeTableAttachmentResource", {
    routeTableId: "string",
    vswitchId: "string",
});
Copy
type: alicloud:vpc:RouteTableAttachment
properties:
    routeTableId: string
    vswitchId: string
Copy

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

RouteTableId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the route table to be bound to the switch.
VswitchId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the switch to bind the route table.
RouteTableId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the route table to be bound to the switch.
VswitchId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the switch to bind the route table.
routeTableId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the route table to be bound to the switch.
vswitchId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the switch to bind the route table.
routeTableId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the route table to be bound to the switch.
vswitchId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the switch to bind the route table.
route_table_id
This property is required.
Changes to this property will trigger replacement.
str
The ID of the route table to be bound to the switch.
vswitch_id
This property is required.
Changes to this property will trigger replacement.
str
The ID of the switch to bind the route table.
routeTableId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the route table to be bound to the switch.
vswitchId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the switch to bind the route table.

Outputs

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

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

Look up Existing RouteTableAttachment Resource

Get an existing RouteTableAttachment 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?: RouteTableAttachmentState, opts?: CustomResourceOptions): RouteTableAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        route_table_id: Optional[str] = None,
        status: Optional[str] = None,
        vswitch_id: Optional[str] = None) -> RouteTableAttachment
func GetRouteTableAttachment(ctx *Context, name string, id IDInput, state *RouteTableAttachmentState, opts ...ResourceOption) (*RouteTableAttachment, error)
public static RouteTableAttachment Get(string name, Input<string> id, RouteTableAttachmentState? state, CustomResourceOptions? opts = null)
public static RouteTableAttachment get(String name, Output<String> id, RouteTableAttachmentState state, CustomResourceOptions options)
resources:  _:    type: alicloud:vpc:RouteTableAttachment    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 Changes to this property will trigger replacement. string
The ID of the route table to be bound to the switch.
Status string
The status of the resource.
VswitchId Changes to this property will trigger replacement. string
The ID of the switch to bind the route table.
RouteTableId Changes to this property will trigger replacement. string
The ID of the route table to be bound to the switch.
Status string
The status of the resource.
VswitchId Changes to this property will trigger replacement. string
The ID of the switch to bind the route table.
routeTableId Changes to this property will trigger replacement. String
The ID of the route table to be bound to the switch.
status String
The status of the resource.
vswitchId Changes to this property will trigger replacement. String
The ID of the switch to bind the route table.
routeTableId Changes to this property will trigger replacement. string
The ID of the route table to be bound to the switch.
status string
The status of the resource.
vswitchId Changes to this property will trigger replacement. string
The ID of the switch to bind the route table.
route_table_id Changes to this property will trigger replacement. str
The ID of the route table to be bound to the switch.
status str
The status of the resource.
vswitch_id Changes to this property will trigger replacement. str
The ID of the switch to bind the route table.
routeTableId Changes to this property will trigger replacement. String
The ID of the route table to be bound to the switch.
status String
The status of the resource.
vswitchId Changes to this property will trigger replacement. String
The ID of the switch to bind the route table.

Import

VPC Route Table Attachment can be imported using the id, e.g.

$ pulumi import alicloud:vpc/routeTableAttachment:RouteTableAttachment example <route_table_id>:<vswitch_id>
Copy

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

Package Details

Repository
Alibaba Cloud pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.