tidbcloud_dedicated_private_endpoint_connection
リソースを使用する
このドキュメントでは、 tidbcloud_dedicated_private_endpoint_connection
リソースを使用してTiDB Cloud専用プライベート エンドポイント接続を管理する方法について説明します。
tidbcloud_dedicated_private_endpoint_connection
リソースの機能は次のとおりです。
- TiDB Cloud Dedicated プライベート エンドポイント接続を作成します。
- TiDB Cloud Dedicated プライベート エンドポイント接続をインポートします。
- TiDB Cloud Dedicated プライベート エンドポイント接続を削除します。
注記:
tidbcloud_dedicated_private_endpoint_connection
リソースは変更できません。TiDB TiDB Cloud Dedicated のプライベートエンドポイント接続を変更するには、既存の接続を削除してから、新しい接続を作成する必要があります。
前提条件
TiDB Cloud Dedicatedプライベートエンドポイント接続を作成する
tidbcloud_dedicated_private_endpoint_connection
リソースを使用して、 TiDB Cloud Dedicated プライベート エンドポイント接続を作成できます。
次の例は、 TiDB Cloud Dedicated プライベート エンドポイント接続を作成する方法を示しています。
TiDB Cloud Dedicated プライベート エンドポイント接続用のディレクトリを作成し、そこに入ります。
private_endpoint_connection.tf
ファイルを作成します。terraform { required_providers { tidbcloud = { source = "tidbcloud/tidbcloud" } } } provider "tidbcloud" { public_key = "your_public_key" private_key = "your_private_key" } resource "tidbcloud_dedicated_private_endpoint_connection" "example" { cluster_id = "your_cluster_id" node_group_id = "your_node_group_id" endpoint_id = "your_endpoint_id" }resource
ブロックを使用して、リソース タイプ、リソース名、リソースの詳細など、 TiDB Cloudのリソースを定義します。tidbcloud_dedicated_private_endpoint_connection
リソースを使用するには、リソース タイプをtidbcloud_dedicated_private_endpoint_connection
に設定します。- リソース名は必要に応じて定義できます。例:
example
。 - 必要な引数の値を取得する方法がわからない場合は、 AWS のプライベートエンドポイント経由でTiDB Cloud専用クラスタに接続する参照してください。
- TiDB Cloud Dedicated プライベート エンドポイント接続仕様情報を取得するには、 tidbcloud_private_endpoint_connection (リソース)参照してください。
terraform apply
コマンドを実行します。リソースを適用する場合はterraform apply --auto-approve
の使用は推奨されません。$ terraform apply Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # tidbcloud_dedicated_private_endpoint_connection.example will be created + resource "tidbcloud_dedicated_private_endpoint_connection" "example" { + account_id = (known after apply) + cloud_provider = (known after apply) + cluster_display_name = (known after apply) + cluster_id = "10757937805044000000" + endpoint_id = "vpce-03367e9618000000" + endpoint_state = (known after apply) + host = (known after apply) + labels = (known after apply) + message = (known after apply) + node_group_id = "1934178998036000000" + port = (known after apply) + private_endpoint_connection_id = (known after apply) + private_link_service_name = (known after apply) + region_display_name = (known after apply) + region_id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value:上記の結果では、Terraform によって実行プランが生成され、Terraform が実行するアクションが記述されます。
- 構成と状態の違いを確認できます。
apply
の結果も確認できます。新しいリソースが追加されますが、リソースは変更または破棄されません。known after apply
apply
後の対応する値が取得されることを示します。
計画の内容がすべて問題ない場合は、「
yes
と入力して続行します。Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes tidbcloud_dedicated_private_endpoint_connection.example: Creating... tidbcloud_dedicated_private_endpoint_connection.example: Creation complete after 10s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.リソースの状態を確認するには、コマンド
terraform show
またはterraform state show tidbcloud_dedicated_private_endpoint_connection.${resource-name}
使用します。コマンド 1 は、すべてのリソースとデータソースの状態を表示します。$ terraform state show tidbcloud_dedicated_private_endpoint_connection.example # tidbcloud_dedicated_private_endpoint_connection.example: resource "tidbcloud_dedicated_private_endpoint_connection" "example" { cloud_provider = "aws" cluster_display_name = "test-tf" cluster_id = "10757937805044000000" endpoint_id = "vpce-03367e96180000000" endpoint_state = "ACTIVE" host = "privatelink-19341000.ubkypd000000.clusters.tidb-cloud.com" labels = { "tidb.cloud/project" = "1372813089454000000" } message = "The VPC Endpoint Id '{vpce-03367e961805e35b6 []}' does not exist" node_group_id = "1934178998036000000" port = 4000 private_endpoint_connection_id = "1934214559409000000" private_link_service_name = "com.amazonaws.vpce.us-west-2.vpce-svc-07468b31cc9000000" region_display_name = "Oregon (us-west-2)" region_id = "aws-us-west-2" }
TiDB Cloud Dedicatedプライベートエンドポイント接続をインポートする
Terraform によって管理されていないTiDB Cloud Dedicated プライベート エンドポイント接続の場合は、インポートすることで Terraform による管理を開始できます。
新しい
tidbcloud_dedicated_private_endpoint_connection
リソースのインポート ブロックを追加します。次のインポート ブロックを
.tf
ファイルに追加し、example
目的のリソース名に置き換え、${id}
cluster_id,dedicated_private_endpoint_connection_id
の形式に置き換えます。import { to = tidbcloud_dedicated_private_endpoint_connection.example id = "${id}" }新しい構成ファイルを生成します。
インポート ブロックに従って、新しい
tidbcloud_dedicated_private_endpoint_connection
リソースの新しい構成ファイルを生成します。terraform plan -generate-config-out=generated.tf上記のコマンドでは、既存の
.tf
名を指定しないでください。指定した場合、Terraform はエラーを返します。次に、インポートされたリソースの構成を含む
generated.tf
ファイルが現在のディレクトリに作成されます。生成された構成を確認して適用します。
生成された構成ファイルを確認し、ニーズを満たしていることを確認してください。必要に応じて、このファイルの内容を任意の場所に移動することもできます。
次に、
terraform apply
を実行してインフラストラクチャをインポートします。適用後の出力例は次のとおりです。tidbcloud_dedicated_private_endpoint_connection.example: Importing... [id=aws-1934187953894000000,example] tidbcloud_dedicated_private_endpoint_connection.example: Import complete [id=aws-19341879538940000000,example] Apply complete! Resources: 1 imported, 0 added, 0 changed, 0 destroyed.これで、インポートしたTiDB Cloud Dedicated プライベート エンドポイント接続を Terraform を使用して管理できるようになりました。
TiDB Cloud Dedicated プライベートエンドポイント接続を削除する
TiDB Cloud Dedicated プライベート エンドポイント接続を削除するには、 tidbcloud_dedicated_private_endpoint_connection
リソースの構成を削除してから、 terraform apply
コマンドを使用してリソースを破棄します。
$ terraform apply
tidbcloud_dedicated_private_endpoint_connection.example: Refreshing state...
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# tidbcloud_dedicated_private_endpoint_connection.example will be destroyed
# (because tidbcloud_dedicated_private_endpoint_connection.example is not in configuration)
- resource "tidbcloud_dedicated_private_endpoint_connection" "example" {
- cloud_provider = "aws" -> null
- cluster_display_name = "test-tf" -> null
- cluster_id = "10757937805044000000" -> null
- endpoint_id = "vpce-03367e96180000000" -> null
- endpoint_state = "ACTIVE" -> null
- host = "privatelink-19341000.ubkypd1sx000.clusters.tidb-cloud.com" -> null
- labels = {
- "tidb.cloud/project" = "1372813089454000000"
} -> null
- message = "The VPC Endpoint Id '{vpce-03367e961805e35b6 []}' does not exist" -> null
- node_group_id = "1934178998036000000" -> null
- port = 4000 -> null
- private_endpoint_connection_id = "1934214559409000000" -> null
- private_link_service_name = "com.amazonaws.vpce.us-west-2.vpce-svc-07468b31cc9000000" -> null
- region_display_name = "Oregon (us-west-2)" -> null
- region_id = "aws-us-west-2" -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
tidbcloud_dedicated_private_endpoint_connection.example: Destroying...
tidbcloud_dedicated_private_endpoint_connection.example: Destruction complete after 1s
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
ここで、コマンドterraform show
実行すると、リソースがクリアされているため何も表示されません。
$ terraform show