Enterprise Edition トランジットルーターを使用することで、異なるリージョンにある VPC 間の IPv6 通信を有効にできます。
このトピックのサンプルコードは、ワンクリック実行に対応しています。今すぐ実行
シナリオ
ある企業には 2 つの IPv4 VPC があります。China (Shanghai) リージョンの VPC1 と、China (Hangzhou) リージョンの VPC2 です。どちらの VPC にも、アプリケーションがデプロイされている ECS インスタンスが含まれています。同社は、ビジネスの成長を支えるため、これらの VPC 間の IPv6 通信を有効にする必要があります。
手順
コンソールと Terraform の 2 つの設定方法を利用できます。ニーズに合った方法を選択してください。
コンソール
前提条件
-
中国 (杭州) リージョンと中国 (上海) リージョンにそれぞれ IPv4 が有効な Virtual Private Cloud (VPC) を作成済みであること。両方の VPC には、アプリケーションがデプロイされた Elastic Compute Service (ECS) インスタンスがあります。詳細については、「IPv4 CIDR ブロックを持つ VPC の作成」をご参照ください。
-
Cloud Enterprise Network (CEN) インスタンスを作成済みであること。詳細については、「CEN インスタンスの作成」をご参照ください。
ステップ 1: VPC の IPv6 を有効にする
IPv6 通信を有効にするには、まず VPC1 と VPC2 の両方で IPv6 を有効にします。
VPC と vSwitch の作成時に IPv6 を有効にすることができます。既に IPv6 を有効にし、VPC と vSwitch に IPv6 CIDR ブロックを割り当てている場合は、このステップをスキップできます。
-
VPC コンソール にログインします。
-
上部メニューで、VPC が配置されているリージョンを選択します。
-
[VPC] ページで、対象の VPC を見つけ、[IPv6 CIDR ブロック] 列の [IPv6 CIDR ブロックの有効化] をクリックします。
-
[IPv6 CIDR ブロックの有効化] ダイアログボックスで、[IPv6 CIDR ブロックタイプ] を [BGP (Multi-ISP) の割り当て] に設定し、[VPC 内のすべての vSwitch の IPv6 を自動的に有効にする] を選択してから、[OK] をクリックします。
-
[VPC 内のすべての vSwitch の IPv6 を自動的に有効にする] を選択しない場合は、各 vSwitch に対して個別に IPv6 を有効にする必要があります。詳細については、「vSwitch の IPv6 を有効にする」をご参照ください。
-
VPC とその vSwitch で IPv6 を有効にすると、システムはそれぞれに IPv6 CIDR ブロックを割り当てます。割り当てられた IPv6 CIDR ブロックは、[VPC] ページと [vSwitch] ページの [IPv6 CIDR ブロック] 列で確認できます。
-
ステップ 2: ECS インスタンスの IPv6 アドレスを設定する
IPv6 で通信するリソースには、IPv6 アドレスが必要です。このシナリオでは、ECS1 と ECS2 に IPv6 アドレスを設定します。両方のインスタンスは、Alibaba Cloud Linux 3.2104 LTS 64 ビットオペレーティングシステムを使用しています。
-
各 ECS インスタンスに IPv6 アドレスを割り当てます。詳細については、「既存のインスタンスに IPv6 アドレスを割り当てる」をご参照ください。
説明ECS インスタンスの作成時に既に IPv6 アドレスを割り当てている場合は、このステップをスキップできます。
-
各 ECS インスタンスで IPv6 アドレスを設定します。詳細については、「IPv6 通信を有効にする」をご参照ください。
設定後、ECS1 と ECS2 の IPv6 アドレスは次の図のようになります。
ECS1 の IPv6 アドレス
[root@iZ5txxx ipZ ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.xxx.109 netmask 255.255.255.0 broadcast 10.xxx.255 inet6 240b:xxx:b0b6:838 prefixlen 128 scopeid 0x0<global> inet6 fe80::xxx:44b2 prefixlen 64 scopeid 0x20<link> ether 00:xxx:44:b2 txqueuelen 1000 (Ethernet) RX packets 2864 bytes 476397 (465.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3255 bytes 475131 (463.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0出力の
inet6 240b:xxx:b0b6:838は ECS1 が取得したグローバル IPv6 アドレスです。ECS2 の IPv6 アドレス
[root@iZxxx byZ ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.xxx.27 netmask 255.255.255.0 broadcast 192.xxx.255 inet6 fe80::xxx:0:21c prefixlen 64 scopeid 0x20<link> inet6 240b:xxx:xxx:a97c:9875 prefixlen 128 scopeid 0x0<global> ether xxx:1c txqueuelen 1000 (Ethernet) RX packets 2063 bytes 387038 (377.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2560 bytes 378127 (369.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0出力の
inet6 240b:xxx:xxx:a97c:9875 prefixlen 128 scopeid 0x0<global>は ECS2 に割り当てられた IPv6 グローバルアドレスです。
ステップ 3: トランジットルーターインスタンスを作成する
CEN インスタンスに、中国 (杭州) リージョンと中国 (上海) リージョンにそれぞれトランジットルーターを作成します。これらのトランジットルーターにより、VPC 間のリージョン間通信が可能になります。
- CEN コンソールにログインします。
- [インスタンス] ページで、管理するCENインスタンスを見つけ、インスタンスIDをクリックします。
-
タブで、[トランジットルーターの作成] をクリックします。
-
[トランジットルーターの作成] ダイアログボックスで、トランジットルーターを設定してから、[OK] をクリックします。
トランジットルーターインスタンスの作成時には、[リージョン] のみを設定します。その他のパラメータはデフォルト値のままにします。詳細については、「トランジットルーターインスタンスの作成」をご参照ください。
ステップ 4: VPC 接続を作成する
リージョン間通信を確立するには、まず VPC をそれぞれのトランジットルーターに接続します。
- CEN コンソールにログインします。
- [インスタンス] ページで、管理するCENインスタンスを見つけ、インスタンスIDをクリックします。
-
タブで、ステップ 3 で作成したいずれかのトランジットルーターを見つけます。[アクション] 列で、[接続の作成] をクリックします。
-
[ピアネットワークインスタンスとの接続] ページで、接続設定を行ってから、[OK] をクリックします。
次のパラメータを使用して、VPC1 を中国 (杭州) リージョンのトランジットルーターに接続し、VPC2 を中国 (上海) リージョンのトランジットルーターに接続します。その他のパラメータはデフォルト値のままにします。詳細については、「VPC 接続の作成」をご参照ください。
パラメータ
説明
VPC1
VPC2
[ネットワークタイプ]
[仮想プライベートクラウド (VPC)] を選択します。
[リージョン]
接続するネットワークインスタンスのリージョンを選択します。
[中国 (杭州)] を選択します。
[中国 (上海)] を選択します。
[IPv6 のサポート]
VPC 接続の IPv6 を有効にします。デフォルトでは無効です。
この機能を有効にすると、Enterprise Edition トランジットルーター経由で IPv6 通信が可能になります。
説明既存の VPC 接続に対して IPv6 機能を有効にすることができます。詳細については、「既存の VPC 接続の IPv6 を有効にする」をご参照ください。
この機能を有効にします。
この機能を有効にします。
[トランジットルーター]
現在のリージョンで作成されたトランジットルーターが自動的に表示されます。
[リソース所有者 ID]
ネットワークインスタンスを所有するアカウントのタイプを選択します。
[現在のアカウント] を選択します。
[現在のアカウント] を選択します。
[ネットワーク]
接続する VPC を選択します。
VPC1 を選択します。
VPC2 を選択します。
[vSwitch]
トランジットルーターがサポートするアベイラビリティーゾーンから vSwitch を選択します。
-
Enterprise Edition トランジットルーターが現在のリージョンで 1 つのアベイラビリティーゾーンのみをサポートしている場合は、そのアベイラビリティーゾーンで 1 つの vSwitch を選択する必要があります。
-
Enterprise Edition トランジットルーターが現在のリージョンで複数のアベイラビリティーゾーンをサポートしている場合は、少なくとも 2 つの異なるアベイラビリティーゾーンでそれぞれ少なくとも 1 つの vSwitch を選択する必要があります。これらの vSwitch により、VPC とトランジットルーター間のトラフィックに対してゾーンレベルのディザスタリカバリが可能になります。各アベイラビリティーゾーンで 1 つの vSwitch を選択することで、トラフィックの迂回を減らし、伝送遅延を低減し、パフォーマンスを向上させます。
必要なアベイラビリティーゾーンに vSwitch がない場合は、作成する必要があります。詳細については、「vSwitch の作成」をご参照ください。
[詳細設定]
デフォルト設定のままにします。これにより、3 つの高度な機能が有効になります。
-
ステップ 5: リージョン間接続を作成する
VPC をそれぞれの Enterprise Edition トランジットルーターに接続した後、リージョン間接続を作成してそれらの間の通信を有効にします。
- CEN コンソールにログインします。
- [インスタンス] ページで、管理するCENインスタンスを見つけ、インスタンスIDをクリックします。
-
タブで、ステップ 3 で作成したいずれかのトランジットルーターを見つけます。トランジットルーターの [アクション] 列で、[接続の作成] をクリックします。
-
[ピアネットワークインスタンスとの接続] ページで、リージョン間接続を設定してから、[OK] をクリックします。
次の表には、主要なパラメータのみを示します。その他のパラメータはデフォルト値のままにします。詳細については、「Enterprise Edition トランジットルーターを使用したリージョン間接続の作成」をご参照ください。
パラメータ
説明
[ネットワークタイプ]
[リージョン間接続] を選択します。
[リージョン]
接続するリージョンのいずれかを選択します。
このトピックでは、[中国 (杭州)] を選択します。
[ピアリージョン]
接続するもう一方のリージョンを選択します。
このトピックでは、[中国 (上海)] を選択します。
[帯域幅割り当てモード]
リージョン間接続の帯域幅割り当てモードを選択します。
このトピックでは、[データ転送量課金] を選択します。リージョン間接続を経由する実際のデータ転送量に応じて課金されます。
[帯域幅]
リージョン間接続の帯域幅の値を入力します。単位: Mbit/s。
帯域幅割り当てモードとして [データ転送量課金] を選択した場合、この値はリージョン間接続のピーク帯域幅になります。
[デフォルトのリンクタイプ]
リージョン間接続の回線タイプを選択します。
デフォルト値のままにします。回線タイプの詳細については、「回線タイプ」をご参照ください。
[詳細設定]
デフォルト設定のままにします。これにより、3 つの高度な機能が有効になります。
ステップ 6: ルート同期を有効にする
VPC1 と VPC2 の両方の接続に対してルート同期を有効にし、トランジットルーターが IPv6 ルートを VPC にアドバタイズできるようにします。
-
CEN コンソール にログインします。
-
[インスタンス] ページで、対象の CEN インスタンスを見つけ、その ID をクリックします。
-
タブで、中国 (杭州) リージョンのトランジットルーターを見つけ、その ID をクリックします。
-
[リージョン内接続数] タブで、VPC1 の接続を見つけ、[ルート同期] 列でネットワークインスタンスのルート同期を有効にします。
-
同じ手順を繰り返して、中国 (上海) リージョンのトランジットルーターで VPC2 接続のルート同期を有効にします。
ルート同期が有効になると、Enterprise Edition トランジットルーターは自動的にルートをネットワークインスタンスに同期します。[ルート同期] 列の [詳細] をクリックして [ルーティング情報] タブに移動し、同期ステータスを確認できます。
VPC1 のルートエントリ
トランジットルーターの ネットワークインスタンスルート情報 タブで、VPC1 のネットワークインスタンスをフィルタリングします。VPC1 は、CEN 経由で中国 (上海) リージョンの VPC から次のルートエントリを学習しました:
-
IPv4 ルート:
172.16.0.0/24と172.16.1.0/24。ルートタイプは CEN、ネクストホップは中国 (上海)、ネクストホップタイプは VPC です。 -
IPv6 ルート: 2 つの
240b:xxxx:xxxx::/64ルート。ルートタイプは CEN、ネクストホップは中国 (上海)、ネクストホップタイプは VPC です。
VPC2 のルートエントリ
VPC2 のネットワークインスタンスルート情報において、ルートタイプが CEN、ネクストホップが 中国 (杭州)、ネクストホップタイプが VPC であるルートエントリは、VPC1 から学習したルートです。これらには、IPv4 CIDR ブロック (
10.0.0.0/24や10.0.1.0/24など) と、240b で始まる IPv6 /64 CIDR ブロックが含まれます。これらのエントリのステータスは 利用可能 であり、VPC2 が VPC1 によって公開されたルートを正常に受信したことを示しています。 -
ステップ 7: 接続性のテスト
VPC1 と VPC2 の間の IPv6 通信が有効になりました。次のように接続性を確認します。
デフォルトでは、セキュリティグループルールは IPv6 トラフィックを許可しません。続行する前に、ECS1 と ECS2 のセキュリティグループルールが IPv6 通信を許可していることを確認してください。詳細については、「セキュリティグループルールの表示」および「セキュリティグループルールの追加」をご参照ください。
たとえば、::/0 CIDR ブロックからのインバウンド ICMP (IPv6) トラフィックを許可するセキュリティグループルールを追加して、IPv6 接続性をテストします。
-
VPC1 の ECS1 インスタンスにログインします。詳細については、「接続方法」をご参照ください。
-
次のコマンドを実行して、ECS1 インスタンスから VPC2 の ECS2 インスタンスに ping を実行し、接続性を確認します。
ping6 <ECS2 の IPv6 アドレス>図に示されている応答は、VPC 間の IPv6 通信が成功したことを示します。
[root@iZ5ts hipZ ~]# ping6 240b:xxx:xxx:xxx:xxx:a97c:9875 PING 240b:xxx:xxx:xxx:xxx:a97c:9875 (240b:xxx:xxx:xxx:xxx:a97c:9875) 56 data bytes 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=1 ttl=62 time=192 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=2 ttl=62 time=191 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=3 ttl=62 time=191 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=4 ttl=62 time=191 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=5 ttl=62 time=191 ms ^Z [2]+ Stopped ping6 240b:xxx:xxx:xxx:xxx:a97c:9875
Terraform
Terraform を使用して、このシナリオの環境を構築できます。Terraform のインストールと設定方法については、Terraform のインストールをご参照ください。
以下の手順では、Linux ホストで Terraform v1.9.8 を実行する方法について説明します。開始する前に、認証を完了していることを確認してください。
このチュートリアルの一部のリソースには料金が発生します。不要になったら解放して、不要なコストを回避してください。
ステップ 1:リソースの作成
-
このシナリオ用のディレクトリを作成し、そのディレクトリに移動します。
mkdir tf-CenIpv6 && cd tf-CenIpv6 -
リソースを定義する
main.tfファイルを作成します。touch main.tf -
main.tfファイルを開き、次のコードをコピーして貼り付け、ファイルを保存します。このファイルには、このシナリオのリソースとその設定が含まれています。variable "pname" { description = "リソースのプレフィックス名" type = string default = "tf-CenIpv6" } variable "default_region_id" { description = "デフォルトのリージョン ID" type = string default = "cn-hangzhou" } variable "hangzhou_region_id" { description = "杭州のリージョン ID" type = string default = "cn-hangzhou" } variable "shanghai_region_id" { description = "上海のリージョン ID" type = string default = "cn-shanghai" } variable "hangzhou_az_list" { description = "使用するアベイラビリティゾーンのリスト" type = list(string) default = ["cn-hangzhou-j", "cn-hangzhou-k"] } variable "shanghai_az_list" { description = "使用するアベイラビリティゾーンのリスト" type = list(string) default = ["cn-shanghai-m", "cn-shanghai-n"] } # --- プロバイダー --- provider "alicloud" { # デフォルトは杭州 region = var.default_region_id } provider "alicloud" { alias = "hangzhou" region = var.hangzhou_region_id } provider "alicloud" { alias = "shanghai" region = var.shanghai_region_id } # --- 2 つの VPC と 4 つの vSwitch --- resource "alicloud_vpc" "vpc1" { provider = alicloud.hangzhou vpc_name = "${var.pname}-vpc1" cidr_block = "10.0.0.0/16" enable_ipv6 = true } resource "alicloud_vpc" "vpc2" { provider = alicloud.shanghai vpc_name = "${var.pname}-vpc2" cidr_block = "172.16.0.0/16" enable_ipv6 = true } resource "alicloud_vswitch" "vsw1-1" { provider = alicloud.hangzhou vpc_id = alicloud_vpc.vpc1.id cidr_block = "10.0.0.0/24" zone_id = var.hangzhou_az_list[0] vswitch_name = "${var.pname}-vsw1-1" enable_ipv6 = true ipv6_cidr_block_mask = 1 # vSwitch の IPv6 CIDR ブロックのマスク } resource "alicloud_vswitch" "vsw1-2" { provider = alicloud.hangzhou vpc_id = alicloud_vpc.vpc1.id cidr_block = "10.0.1.0/24" zone_id = var.hangzhou_az_list[1] vswitch_name = "${var.pname}-vsw1-2" enable_ipv6 = true ipv6_cidr_block_mask = 2 } resource "alicloud_vswitch" "vsw2-1" { provider = alicloud.shanghai vpc_id = alicloud_vpc.vpc2.id cidr_block = "172.16.0.0/24" zone_id = var.shanghai_az_list[0] vswitch_name = "${var.pname}-vsw2-1" enable_ipv6 = true ipv6_cidr_block_mask = 3 } resource "alicloud_vswitch" "vsw2-2" { provider = alicloud.shanghai vpc_id = alicloud_vpc.vpc2.id cidr_block = "172.16.1.0/24" zone_id = var.shanghai_az_list[1] vswitch_name = "${var.pname}-vsw2-2" enable_ipv6 = true ipv6_cidr_block_mask = 4 } # --- ecs1 --- resource "alicloud_instance" "ecs1" { provider = alicloud.hangzhou instance_name = "${var.pname}-ecs1" instance_type = "ecs.e-c1m1.large" security_groups = [alicloud_security_group.sg1.id] vswitch_id = alicloud_vswitch.vsw1-1.id image_id = "aliyun_3_x64_20G_qboot_alibase_20230727.vhd" system_disk_category = "cloud_essd" private_ip = "10.0.0.1" ipv6_address_count = 1 instance_charge_type = "PostPaid" user_data = base64encode(<<-EOT #!/bin/bash echo ecs_ok > /root/ok.txt sudo acs-plugin-manager --exec --plugin=ecs-utils-ipv6 EOT ) } # --- ecs2 --- resource "alicloud_instance" "ecs2" { provider = alicloud.shanghai instance_name = "${var.pname}-ecs2" instance_type = "ecs.e-c1m1.large" security_groups = [alicloud_security_group.sg2.id] vswitch_id = alicloud_vswitch.vsw2-1.id image_id = "aliyun_3_x64_20G_qboot_alibase_20230727.vhd" system_disk_category = "cloud_essd" private_ip = "172.16.0.1" ipv6_address_count = 1 instance_charge_type = "PostPaid" user_data = base64encode(<<-EOT #!/bin/bash echo ecs_ok > /root/ok.txt sudo acs-plugin-manager --exec --plugin=ecs-utils-ipv6 EOT ) } # セキュリティグループ resource "alicloud_security_group" "sg1" { provider = alicloud.hangzhou name = "${var.pname}-sg1" vpc_id = alicloud_vpc.vpc1.id } resource "alicloud_security_group_rule" "allow_inbound_ssh1" { provider = alicloud.hangzhou type = "ingress" ip_protocol = "tcp" nic_type = "intranet" policy = "accept" port_range = "22/22" priority = 1 security_group_id = alicloud_security_group.sg1.id cidr_ip = "0.0.0.0/0" } resource "alicloud_security_group_rule" "allow_inbound_icmp1" { provider = alicloud.hangzhou type = "ingress" ip_protocol = "icmp" nic_type = "intranet" policy = "accept" port_range = "-1/-1" priority = 1 security_group_id = alicloud_security_group.sg1.id cidr_ip = "0.0.0.0/0" } resource "alicloud_security_group_rule" "allow_inbound_ipv6_icmp1" { provider = alicloud.hangzhou type = "ingress" ip_protocol = "all" nic_type = "intranet" policy = "accept" port_range = "-1/-1" priority = 1 security_group_id = alicloud_security_group.sg1.id ipv6_cidr_ip = "::/0" } resource "alicloud_security_group" "sg2" { provider = alicloud.shanghai name = "${var.pname}-sg2" vpc_id = alicloud_vpc.vpc2.id } resource "alicloud_security_group_rule" "allow_inbound_ssh2" { provider = alicloud.shanghai type = "ingress" ip_protocol = "tcp" nic_type = "intranet" policy = "accept" port_range = "22/22" priority = 1 security_group_id = alicloud_security_group.sg2.id cidr_ip = "0.0.0.0/0" } resource "alicloud_security_group_rule" "allow_inbound_icmp2" { provider = alicloud.shanghai type = "ingress" ip_protocol = "icmp" nic_type = "intranet" policy = "accept" port_range = "-1/-1" priority = 1 security_group_id = alicloud_security_group.sg2.id cidr_ip = "0.0.0.0/0" } resource "alicloud_security_group_rule" "allow_inbound_ipv6_icmp2" { provider = alicloud.shanghai type = "ingress" ip_protocol = "all" nic_type = "intranet" policy = "accept" port_range = "-1/-1" priority = 1 security_group_id = alicloud_security_group.sg2.id ipv6_cidr_ip = "::/0" } # --- CEN とトランジットルーター --- resource "alicloud_cen_instance" "cen1" { cen_instance_name = "${var.pname}-cen1" } resource "alicloud_cen_transit_router" "tr1" { provider = alicloud.hangzhou transit_router_name = "${var.pname}-tr1" cen_id = alicloud_cen_instance.cen1.id } resource "alicloud_cen_transit_router" "tr2" { provider = alicloud.shanghai transit_router_name = "${var.pname}-tr2" cen_id = alicloud_cen_instance.cen1.id } # トランジットルーターのシステムルートテーブル ID を取得します。 data "alicloud_cen_transit_router_route_tables" "tr1" { # トランジットルーターのシステムルートテーブルを取得します。 transit_router_id = alicloud_cen_transit_router.tr1.transit_router_id transit_router_route_table_type = "System" } data "alicloud_cen_transit_router_route_tables" "tr2" { transit_router_id = alicloud_cen_transit_router.tr2.transit_router_id transit_router_route_table_type = "System" } # トランジットルーターピア resource "alicloud_cen_transit_router_peer_attachment" "peer" { provider = alicloud.hangzhou cen_id = alicloud_cen_instance.cen1.id transit_router_id = alicloud_cen_transit_router.tr1.transit_router_id peer_transit_router_region_id = var.shanghai_region_id peer_transit_router_id = alicloud_cen_transit_router.tr2.transit_router_id bandwidth_type = "DataTransfer" bandwidth = 1 auto_publish_route_enabled = true # デフォルトは false } resource "alicloud_cen_transit_router_route_table_association" "ass_peer1" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr1.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_peer_attachment.peer.transit_router_attachment_id } resource "alicloud_cen_transit_router_route_table_propagation" "propa_peer1" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr1.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_peer_attachment.peer.transit_router_attachment_id } resource "alicloud_cen_transit_router_route_table_association" "ass_peer2" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr2.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_peer_attachment.peer.transit_router_attachment_id } resource "alicloud_cen_transit_router_route_table_propagation" "propa_peer2" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr2.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_peer_attachment.peer.transit_router_attachment_id } # CIDR リスト variable "cidr_list" { description = "プライベート CIDR ブロックのリスト" type = list(string) default = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"] } # アタッチメント 1 resource "alicloud_cen_transit_router_vpc_attachment" "attach1" { provider = alicloud.hangzhou cen_id = alicloud_cen_instance.cen1.id transit_router_id = alicloud_cen_transit_router.tr1.transit_router_id vpc_id = alicloud_vpc.vpc1.id zone_mappings { zone_id = var.hangzhou_az_list[0] vswitch_id = alicloud_vswitch.vsw1-1.id } zone_mappings { zone_id = var.hangzhou_az_list[1] vswitch_id = alicloud_vswitch.vsw1-2.id } transit_router_vpc_attachment_name = "attach1" transit_router_vpc_attachment_options = { ipv6Support : "enable" } auto_publish_route_enabled = true # デフォルトは false } resource "alicloud_cen_transit_router_route_table_association" "ass1" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr1.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_vpc_attachment.attach1.transit_router_attachment_id } resource "alicloud_cen_transit_router_route_table_propagation" "propa1" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr1.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_vpc_attachment.attach1.transit_router_attachment_id } resource "alicloud_route_entry" "vpc1_to_tr1" { provider = alicloud.hangzhou count = 3 route_table_id = alicloud_vpc.vpc1.route_table_id destination_cidrblock = var.cidr_list[count.index] nexthop_type = "Attachment" nexthop_id = alicloud_cen_transit_router_vpc_attachment.attach1.transit_router_attachment_id } # アタッチメント 2 resource "alicloud_cen_transit_router_vpc_attachment" "attach2" { provider = alicloud.shanghai cen_id = alicloud_cen_instance.cen1.id transit_router_id = alicloud_cen_transit_router.tr2.transit_router_id vpc_id = alicloud_vpc.vpc2.id zone_mappings { zone_id = var.shanghai_az_list[0] vswitch_id = alicloud_vswitch.vsw2-1.id } zone_mappings { zone_id = var.shanghai_az_list[1] vswitch_id = alicloud_vswitch.vsw2-2.id } transit_router_vpc_attachment_name = "attach2" transit_router_vpc_attachment_options = { ipv6Support : "enable" } auto_publish_route_enabled = true # デフォルトは false } resource "alicloud_cen_transit_router_route_table_association" "ass2" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr2.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_vpc_attachment.attach2.transit_router_attachment_id } resource "alicloud_cen_transit_router_route_table_propagation" "propa2" { transit_router_route_table_id = data.alicloud_cen_transit_router_route_tables.tr2.tables[0].id transit_router_attachment_id = alicloud_cen_transit_router_vpc_attachment.attach2.transit_router_attachment_id } resource "alicloud_route_entry" "vpc2_to_tr2" { provider = alicloud.shanghai count = 3 route_table_id = alicloud_vpc.vpc2.route_table_id destination_cidrblock = var.cidr_list[count.index] nexthop_type = "Attachment" nexthop_id = alicloud_cen_transit_router_vpc_attachment.attach2.transit_router_attachment_id } output "ecs1_login_address" { value = "https://ecs-workbench.alibabacloud.com/?from=EcsConsole&instanceType=ecs®ionId=${var.hangzhou_region_id}&instanceId=${alicloud_instance.ecs1.id}" } output "ecs2_login_address" { value = "https://ecs-workbench.alibabacloud.com/?from=EcsConsole&instanceType=ecs®ionId=${var.shanghai_region_id}&instanceId=${alicloud_instance.ecs2.id}" } -
ディレクトリ内で Terraform を初期化します。
terraform init -
リソースを作成します。Terraform はまず実行プランをプレビューします。確認後、
yesと入力してリソースの作成を開始します。terraform apply
ステップ 2:接続性の確認
VPC1 と VPC2 の間の IPv6 通信が有効になりました。次のように接続性を確認します。
-
ECS2 インスタンス (インスタンス名:
tf-CenIpv6-ecs2) にログインします。Terraform の出力で、ECS2 のログイン URL を見つけ、ブラウザにコピーして開きます。ログイン時には、認証方法として [一時 SSH キーベース] を選択します。
Outputs: ecs1_login_address = "https://ecs-workbench.alibabacloud.com/?from=EcsConsole&instanceType=ecs®ionId=cn-hangzhou&instanceId=i-bp1g" ecs2_login_address = "https://ecs-workbench.alibabacloud.com/?from=EcsConsole&instanceType=ecs®ionId=cn-shanghai&instanceId=i-uf6j" -
ECS2 インスタンスで、次のコマンドを実行して IPv6 アドレスを確認します。
ifconfig[root@iZxxx byZ ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.xxx.27 netmask 255.255.255.0 broadcast 192.xxx.255 inet6 fe80::xxx:0:21c prefixlen 64 scopeid 0x20<link> inet6 240b:xxx:xxx:a97c:9875 prefixlen 128 scopeid 0x0<global> ether xxx:1c txqueuelen 1000 (Ethernet) RX packets 2063 bytes 387038 (377.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2560 bytes 378127 (369.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0出力の
inet6 240b:xxx:xxx:a97c:9875 prefixlen 128 scopeid 0x0<global>は、ECS2 に割り当てられた IPv6 グローバルアドレスです。 -
ECS1 インスタンス (インスタンス名:
tf-CenIpv6-ecs1) にログインします。Terraform の出力で、ECS1 のログイン URL を見つけ、ブラウザにコピーして開きます。ログイン時には、認証方法として [一時 SSH キーベース] を選択します。
Outputs: ecs1_login_address = "https://ecs-workbench.alibabacloud.com/?from=EcsConsole&instanceType=ecs®ionId=cn-hangzhou&instanceId=i-bp1g4zxxx" ecs2_login_address = "https://ecs-workbench.alibabacloud.com/?from=EcsConsole&instanceType=ecs®ionId=cn-shanghai&instanceId=i-uf6ja1xxx" -
次のコマンドを実行して、ECS1 インスタンスから VPC2 の ECS2 インスタンスに ping を実行し、接続性を確認します。
ping6 <ECS2 の IPv6 アドレス>[root@iZ5ts hipZ ~]# ping6 240b:xxx:xxx:xxx:xxx:a97c:9875 PING 240b: a97c:9875(240b:4xxx:xxx:xxx:xxx:a97c:9875) 56 data bytes 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=1 ttl=62 time=192 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=2 ttl=62 time=191 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=3 ttl=62 time=191 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=4 ttl=62 time=191 ms 64 bytes from 240b:xxx:xxx:xxx:xxx:a97c:9875: icmp_seq=5 ttl=62 time=191 ms ^Z [2]+ Stopped ping6 240b:xxx:xxx:xxx:xxx:a97c:9875図に示されている応答は、VPC 間の IPv6 通信が成功していることを示します。
ステップ 3:リソースの解放
リソースが不要になったら、次のコマンドを実行してリソースを解放します。
terraform destroy --auto-approve