Attaching subnets to a routing table
When you view details of a routing table, you can also view details of attached subnets, or attach a subnet to apply routing table routes to a particular subnet. Note that a routing table can be associated with multiple subnets. However, each subnet can be assigned only one routing table. By default, any subnet that is not associated with a routing table is associated with the default routing table. You can also reassign the routing table of a subnet to another subnet.
You can attach a subnet to a routing table, or reassign a routing table to a particular subnet by using the console, CLI, API, or Terraform.
Attaching subnets to a routing table in the console
To attach a routing table to a subnet in the console, follow these steps:
- From the IBM Cloud console, select the Navigation Menu
, then click Infrastructure
> Network > Routing tables. The Routing tables for VPC page appears.
- Click the name of the routing table in which you want to view subnet details. Alternatively, you can click the number of attached subnets.
- From the Subnets tab, click Attach subnet. The Attach subnets to routing table side panel appears.
- Select a subnet from the drop-down list. The current routing table, IP range, and location of the subnet shows.
- Click Attach.
To reassign a routing table to a subnet, follow these steps:
- From the routing table details page, click the Subnets tab.
- Click the Actions menu
next to the subnet, then click Reassign routing table.
- From the Reassign subnet routing table side panel, click the subnet that you want to assign to this routing table.
- Click Reassign.
Attaching subnets to a routing table from the CLI
Before you begin, set up your CLI environment.
To attach subnets to a routing table from the CLI, run the following command:
ibmcloud is subnet-update SUBNET_ID --routing-table-id ROUTING_TABLE_ID
Where:
SUBNET_ID
- Is the ID or name of the subnet you want to update.
ROUTING_TABLE_ID
- Is the ID or name of the routing table that you want to assign the subnet to.
Attaching subnets to a routing table with the API
To attach subnets to a routing table with the API, follow these steps:
-
Set up your API environment.
-
Store the
VpcId
value in a variable to be used in the API command:export VpcId=<your_vpc_id>
-
Attach a subnet to a routing table:
curl -X PUT "$vpc_api_endpoint/v1/subnets/$subnet_id/routing_table?version=$api_version&generation=2" -H "Authorization: $iam_token" -d '{ "id": "37491549-51c0-4acc-9e7b-9ab3628e1a68" }'
Attaching subnets to a routing table with Terraform
To view details of all or a specific routing table with Terraform, follow these steps:
-
Set up your Terraform environment.
-
Use one of the following examples:
-
To attach a subnet to a routing table:
resource "ibm_is_subnet_routing_table_attachment" "example" { subnet = ibm_is_subnet.example.id routing_table = ibm_is_vpc_routing_table.example.routing_table }
For more information about the
ibm_is_subnet_routing_table_attachment
resource, see the Terraform Registry. -
On an existing subnet resource, update the
routing_table
attribute that is specified by the identifier:resource "ibm_is_subnet" "example" { name = "example-subnet" vpc = ibm_is_vpc.example.id zone = "us-south-1" ipv4_cidr_block = "10.240.0.0/24" routing_table = ibm_is_vpc_routing_table.example.routing_table }
For more information about the
routing_table
resource, see the Terraform Registry.
-