scenario:
  id: abcf522f5754a26096985d8962f63abc
  context:
    auth:
      type: digest
    base_path: /v1beta1
    host: null
  description: "Auto-generated scenario for Azure 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": "https://dedicated.tidbapi.com/v1beta1/clusters",
        "path_params": {},
        "query_params": {},
        "headers": {},
        "body": {
          "displayName": "sce-privateconnection",
          "labels": {
            "tidb.cloud/project": "{projectId}"
          },
          "port": 4000,
          "regionId": "{regionId}",
          "rootPassword": "31415926",
          "tidbNodeSetting": {
            "nodeSpecKey": "8C32G",
            "tidbNodeGroups": [
              {
                "nodeCount": 1
              }
            ]
          },
          "tikvNodeSetting": {
            "nodeCount": 3,
            "nodeSpecKey": "8C32G",
            "storageSizeGi": 200,
            "storageType": "Basic"
          }
        },
        "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": "https://dedicated.tidbapi.com/v1beta1/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": "https://dedicated.tidbapi.com/v1beta1/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": "service_name", "eval": "body.serviceName" }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 3
  - case_id: GetSubnetFromSUTVnetOnAzure
    operation_id: CloudCLI_GetSubnet
    case_type: supplimental_positive
    request_type: cmd_azure
    request: |-
      {
        "service": "network",
        "name": "az",
        "args": [
          "network",
          "vnet",
          "subnet",
          "list",
          "-g",
          "openapi-test",
          "--vnet-name",
          "openapi-test-vnet",
          "--subscription",
          "85b598b9-a080-4476-bc96-ba89e64f92d1"
        ],
        "args_params": null
      }
    expect: |-
      {
        "exit_code": 0
      }
    save: |-
      {
        "placeholder": [
          { "key": "subnet", "eval": "output[0].id" }
        ]
      }
    description: Get the subnet ID from the subnet name.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: get_subnet_id
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 4
  - case_id: CreateVpcEndpointOnAzure
    operation_id: CloudCLI_CreateVpcEndpoint
    case_type: supplimental_positive
    request_type: cmd_azure
    request: |-
      {
        "service": "network",
        "name": "az",
        "args": [
          "network",
          "private-endpoint",
          "create",
          "--name",
          "example-private-endpoint",
          "--resource-group",
          "openapi-test",
          "--subnet",
          "{subnet}",
          "--private-connection-resource-id",
          "{service_name}",
          "--connection-name",
          "example-connection",
          "--manual-request",
          "1",
          "--subscription",
          "85b598b9-a080-4476-bc96-ba89e64f92d1"
        ],
        "args_params": {
          "service_name": "service_name",
          "subnet": "subnet"
        }
      }
    expect: |-
      {
        "exit_code": 0
      }
    save: |-
      {
        "placeholder": [
          { "key": "vpce_id", "eval": "output.id" },
          { "key": "nic_id", "eval": "output.networkInterfaces[0].id" }
        ]
      }
    description: Get the nic ID from the vpc endpoint.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: get_nic_id
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 5
  - case_id: GetNicOfVpcEndpoint
    operation_id: CloudCLI_GetNicOfVpcEndpoint
    case_type: supplimental_positive
    request_type: cmd_azure
    request: |-
      {
        "service": "network",
        "name": "az",
        "args": [
          "network",
          "nic",
          "show",
          "--ids",
          "{nic_id}"
        ],
        "args_params": {
          "nic_id": "nic_id"
        }
      }
    expect: |-
      {
        "exit_code": 0
      }
    save: |-
      {
        "placeholder": [
          { "key": "dns_ip", "eval": "output.ipConfigurations[0].privateIPAddress" }
        ]
      }
    description: Get the dns ip from the nic.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: get_dns_ip
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 6
  - 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": "https://dedicated.tidbapi.com/v1beta1/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}/privateEndpointConnections",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "endpointId": "{endpointId}",
          "privateIpAddress": "{privateIpAddress}"
        },
        "body_params": {
          "endpointId": "vpce_id",
          "privateIpAddress": "dns_ip"
        }
      }
    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": "https://dedicated.tidbapi.com/v1beta1/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: DeleteVpcEndpointOnAzure
    operation_id: CloudCLI_DeleteVpcEndpoint
    case_type: supplimental_positive
    request_type: cmd_azure
    request: |-
      {
        "service": "network",
        "name": "az",
        "args": [
          "network",
          "private-endpoint",
          "delete",
          "--ids",
          "{vpce_id}"
        ],
        "args_params": {
          "vpce_id": "vpce_id"
        }
      }
    expect: |-
      {
        "exit_code": 0
      }
    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": "https://dedicated.tidbapi.com/v1beta1/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": "https://dedicated.tidbapi.com/v1beta1/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
