scenario:
  id: abcf522f5754a26096985d8962f63abc
  context:
    auth:
      type: digest
    base_path: /v1beta1
    host: null
  description: "Auto-generated scenario for AWS private endpoint connection"
  name: private_endpoint_connection
steps:
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: ClusterService_CreateCluster
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "POST",
        "path": "/clusters",
        "path_params": {},
        "query_params": {},
        "headers": {},
        "body": {
          "displayName": "sce-privateconnection",
          "labels": {
            "tidb.cloud/project": "{projectId}"
          },
          "port": 4000,
          "regionId": "{regionId}",
          "rootPassword": "31415926",
          "tidbNodeSetting": {
            "nodeSpecKey": "2C8G",
            "tidbNodeGroups": [
              {
                "nodeCount": 1
              }
            ]
          },
          "tikvNodeSetting": {
            "nodeCount": 3,
            "nodeSpecKey": "2C8G",
            "storageSizeGi": 200,
            "storageType": "Standard"
          }
        },
        "body_params": {
          "regionId": "region_id",
          "projectId": "project_id"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"CREATING\""
      }
    description:
      Create a 1 TiDB 3 TiKV dedicated cluster to fulfill the dependency
      for scaling out TiDB nodes.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: |-
      {
        "placeholder": [
          { "key": "cluster_1", "eval": "body.clusterId" }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 1
  - case_id: c37f522f5754a26096985d8962f63aab
    operation_id: ClusterService_GetCluster
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ACTIVE\""
      }
    description: Poll the cluster state until it becomes ACTIVE.
    max_retries: 60
    delay_after: 60
    step_type: defined
    name: wait_for_cluster_active
    save: |-
      {
        "placeholder": [
          { "key": "tidbnodegroup_1", "eval": "body.tidbNodeSetting.tidbNodeGroups[0].tidbNodeGroupId" }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2
  - case_id: GetPrivateLinkService
    operation_id: ClusterService_GetPrivateLinkService
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}/privateLinkService",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ACTIVE\""
      }
    description: Poll the cluster state until it becomes ACTIVE.
    max_retries: 60
    delay_after: 60
    step_type: defined
    name: wait_for_cluster_active
    save: |-
      {
        "placeholder": [
          {
            "key": "private_link_service_1",
            "eval": "body.serviceName"
          }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 3
  - case_id: GetVPCIdFromAWS
    operation_id: CloudCLI_GetVPCId
    case_type: supplimental_positive
    request_type: cmd_aws
    request: |-
      {
        "args": [
          "ec2",
          "describe-vpcs",
          "--region",
          "{region}",
          "--filters", 
          "Name=isDefault,Values=true",
          "--output",
          "json"
        ],
        "args_params": {
          "region":"region"
        },
        "name": "aws"
      }
    expect: |-
      {
        "status_code": 0,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "vpc_id_1",
            "eval": "output.Vpcs[0].VpcId"
          }
        ]
      }
    description: Get the vpc ID from AWS.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: get_vpc_id
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 4
  - case_id: CreateVpcEndpointOnAWS
    operation_id: CloudCLI_CreateVpcEndpoint
    case_type: supplimental_positive
    request_type: cmd_aws
    request: |-
      {
        "args": [
          "ec2",
          "create-vpc-endpoint",
          "--vpc-id",
          "{vpc_id_1}",
          "--service-name",
          "{private_link_service_1}",
          "--vpc-endpoint-type",
          "Interface",
          "--region",
          "{region}"
        ],
        "args_params": {
          "vpc_id_1": "vpc_id_1",
          "private_link_service_1": "private_link_service_1",
          "region":"region"
        },
        "name": "aws"
      }
    expect: |-
      {
        "status_code": 0,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "private_endpoint_1",
            "eval": "output.VpcEndpoint.VpcEndpointId"
          },
          {
            "key": "vpc_1",
            "eval": "output.VpcEndpoint.VpcId"
          }
        ]
      }
    description: Get the vpc ID from the vpc endpoint.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: get_aws_vpc_id
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 5
  - case_id: CreatePrivateEndpointConnection
    operation_id: PrivateEndpointConnectionService_CreatePrivateEndpointConnection
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "POST",
        "path": "/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}/privateEndpointConnections",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "regionId": "{regionId}",
          "endpointId": "{private_endpoint_1}"
        },
        "body_params": {
          "regionId": "region_id",
          "private_endpoint_1": "private_endpoint_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          { "key": "private_endpoint_connection_1", "eval": "body.privateEndpointConnectionId" }
        ]
      }
    description: Create a private endpoint connection.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_private_endpoint_connection
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 7
  - case_id: get_private_endpoint_connection
    operation_id: PrivateEndpointConnectionService_GetPrivateEndpointConnection
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}/privateEndpointConnections/{privateEndpointConnectionId}",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1",
          "privateEndpointConnectionId": "private_endpoint_connection_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.endpointState == \"ACTIVE\" && has(body.host) && body.host != null && body.host.size() > 0"
      }
    description: Get a private endpoint connection.
    max_retries: 60
    delay_after: 60
    step_type: defined
    name: get_private_endpoint_connection
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 7.5
  - case_id: DeleteVpcEndpointOnAWS
    operation_id: CloudCLI_DeleteVpcEndpoint
    case_type: supplimental_positive
    request_type: cmd_aws
    request: |-
      {
        "args": [
          "ec2",
          "delete-vpc-endpoints",
          "--vpc-endpoint-ids",
          "{private_endpoint_1}"
        ],
        "args_params": {
          "private_endpoint_1": "private_endpoint_1"
        },
        "name": "aws"
      }
    expect: |-
      {
        "status_code": 0,
        "cel": ""
      }
    description: Delete the vpc endpoint.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: delete_vpc_endpoint
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 8
  - case_id: delete_private_endpoint_connection
    operation_id: PrivateEndpointConnectionService_DeletePrivateEndpointConnection
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "DELETE",
        "path": "/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}/privateEndpointConnections/{privateEndpointConnectionId}",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1",
          "privateEndpointConnectionId": "private_endpoint_connection_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Delete a private endpoint connection.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: delete_private_endpoint_connection
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 9
  - case_id: cleanup_cluster_1
    operation_id: ClusterService_DeleteCluster
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "DELETE",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Cleanup step for TiDB Cloud cluster with no parent dependency.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Delete TiDB Cloud Cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 10
