📣

TiDB Cloud Serverless が
Starter
に変わりました!このページは自動翻訳されたものです。
原文はこちらからご覧ください。

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 プライベート エンドポイント接続を作成する方法を示しています。

  1. TiDB Cloud Dedicated プライベート エンドポイント接続用のディレクトリを作成し、そこに入ります。

  2. 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のリソースを定義します。

  3. 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後の対応する値が取得されることを示します。
  4. 計画の内容がすべて問題ない場合は、「 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.
  5. リソースの状態を確認するには、コマンド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 による管理を開始できます。

  1. 新しい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}" }
  2. 新しい構成ファイルを生成します。

    インポート ブロックに従って、新しいtidbcloud_dedicated_private_endpoint_connectionリソースの新しい構成ファイルを生成します。

    terraform plan -generate-config-out=generated.tf

    上記のコマンドでは、既存の.tf名を指定しないでください。指定した場合、Terraform はエラーを返します。

    次に、インポートされたリソースの構成を含むgenerated.tfファイルが現在のディレクトリに作成されます。

  3. 生成された構成を確認して適用します。

    生成された構成ファイルを確認し、ニーズを満たしていることを確認してください。必要に応じて、このファイルの内容を任意の場所に移動することもできます。

    次に、 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

このページは役に立ちましたか?