Skip to content

Commit

Permalink
Support cluster data source (#25)
Browse files Browse the repository at this point in the history
Support cluster datasource
  • Loading branch information
shiyuhang0 authored Nov 15, 2022
1 parent 47f9920 commit 0b7b748
Show file tree
Hide file tree
Showing 34 changed files with 972 additions and 191 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ website/vendor

# Keep windows files with windows line endings
*.winfile eol=crlf

test.tf
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ For general information about Terraform, visit the [official website](https://ww
- [Create an API key](#create-an-api-key)
- [Get TiDB Cloud provider](#get-tidb-cloud-provider)
- [Config the provider](#config-the-provider)
- [Get projectId with project Data Source](#get-projectid-with-project-data-source)
- [Get cluster spec info with cluster-spec Data Source](#get-cluster-spec-info-with-cluster-spec-data-source)
- [Get projectId with projects Data Source](#get-projectid-with-projects-data-source)
- [Get cluster spec info with cluster-specs Data Source](#get-cluster-spec-info-with-cluster-specs-data-source)
- [Create a dedicated cluster with cluster resource](#create-a-dedicated-cluster-with-cluster-resource)
- [Change the dedicated cluster](#change-the-dedicated-cluster)
- [Create a backup with backup resource](#create-a-backup-with-backup-resource)
Expand Down Expand Up @@ -54,10 +54,11 @@ Resources
- [restore](./docs/resources/restore.md) (not support update and delete)

DataSource
- [project](./docs/data-sources/project.md)
- [cluster spec](./docs/data-sources/cluster_spec.md)
- [restore](./docs/data-sources/restore.md)
- [backup](./docs/data-sources/backup.md)
- [projects](./docs/data-sources/projects.md)
- [cluster specs](./docs/data-sources/cluster_specs.md)
- [restores](./docs/data-sources/restores.md)
- [backups](./docs/data-sources/backups.md)
- [clusters](./docs/data-sources/clusters.md)


## Using the provider
Expand Down Expand Up @@ -163,10 +164,10 @@ export TIDBCLOUD_PRIVATE_KEY = ${private_key}

Now, you can use the tidbcloud provider!

### Get projectId with project Data Source
### Get projectId with projects Data Source

Let us get all the projects by project data source first:
- Use `data` block to define the data source of tidbcloud, it consists of the data source type and the data source name. In this example, data source type is `tidbcloud_project` and the name is `example_project`. The prefix of the type maps to the name of the provider.
Let us get all the projects by projects data source first:
- Use `data` block to define the data source of tidbcloud, it consists of the data source type and the data source name. In this example, data source type is `tidbcloud_projects` and the name is `example_project`. The prefix of the type maps to the name of the provider.
- Use `output` block to get the information, and expose information for other Terraform configurations to use. It is similar to return values in programming languages. See [official doc](https://www.terraform.io/language/values/outputs) for more detail

Besides, you can find all the supported configs for the data source and resource [here](./docs)
Expand All @@ -187,22 +188,22 @@ provider "tidbcloud" {
private_key = "fake_private_key"
}
data "tidbcloud_project" "example_project" {
data "tidbcloud_projects" "example_project" {
page = 1
page_size = 10
}
output "projects" {
value = data.tidbcloud_project.example_project.items
value = data.tidbcloud_projects.example_project.items
}
```

Then you can apply the configuration with the `terraform apply`, you need to type `yes` at the confirmation prompt to proceed. Use `terraform apply --auto-approve` to skip the type.

```shell
$ terraform apply --auto-approve
data.tidbcloud_project.example_project: Reading...
data.tidbcloud_project.example_project: Read complete after 1s [id=just for test]
data.tidbcloud_projects.example_project: Reading...
data.tidbcloud_projects.example_project: Read complete after 1s

Changes to Outputs:
+ projects = [
Expand Down Expand Up @@ -252,16 +253,16 @@ projects = tolist([

Now, you get all the available projects, copy one of the id you need. Here we use the default project's ID.

### Get cluster spec info with cluster-spec Data Source
### Get cluster spec info with cluster-specs Data Source

Before creating a TiDB cluster, you may need to get the available config values (providers, regions, etc.) by cluster-spec Data Source:
Before creating a TiDB cluster, you may need to get the available config values (providers, regions, etc.) by cluster-specs Data Source:

```
data "tidbcloud_cluster_spec" "example_cluster_spec" {
data "tidbcloud_cluster_specs" "example_cluster_spec" {
}
output "cluster_spec" {
value = data.tidbcloud_cluster_spec.example_cluster_spec.items
output "cluster_specs" {
value = data.tidbcloud_cluster_specs.example_cluster_spec.items
}
```

Expand Down Expand Up @@ -434,7 +435,7 @@ Execute `terraform apply`, it is not recommended to use `terraform apply --auto-
```shell
$ terraform apply
data.tidbcloud_project.example_project: Reading...
data.tidbcloud_project.example_project: Read complete after 1s [id=just for test]
data.tidbcloud_project.example_project: Read complete after 1s

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Expand Down
16 changes: 8 additions & 8 deletions docs/data-sources/backup.md → docs/data-sources/backups.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "tidbcloud_backup Data Source - terraform-provider-tidbcloud"
page_title: "tidbcloud_backups Data Source - terraform-provider-tidbcloud"
subcategory: ""
description: |-
backup data source
backups data source
---

# tidbcloud_backup (Data Source)
# tidbcloud_backups (Data Source)

backup data source
backups data source

## Example Usage

Expand All @@ -26,15 +26,15 @@ provider "tidbcloud" {
private_key = "fake_private_key"
}
data "tidbcloud_backup" "example" {
data "tidbcloud_backups" "example" {
page = 1
page_size = 10
project_id = "fake_id"
cluster_id = "fake_id"
}
output "output" {
value = data.tidbcloud_backup.example
value = data.tidbcloud_backups.example
}
```

Expand All @@ -44,7 +44,7 @@ output "output" {
### Required

- `cluster_id` (String) The ID of your cluster.
- `project_id` (String) The ID of the project. You can get the project ID from [tidbcloud_project datasource](../project).
- `project_id` (String) The ID of the project. You can get the project ID from [tidbcloud_projects datasource](../datasource/projects.md).

### Optional

Expand All @@ -53,7 +53,7 @@ output "output" {

### Read-Only

- `id` (String) ignore it, it is just for test.
- `id` (String) data source ID
- `items` (Attributes List) (see [below for nested schema](#nestedatt--items))
- `total` (Number) The total number of backups in the project.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "tidbcloud_cluster_spec Data Source - terraform-provider-tidbcloud"
page_title: "tidbcloud_cluster_specs Data Source - terraform-provider-tidbcloud"
subcategory: ""
description: |-
cluster_spec data source
cluster_specs data source
---

# tidbcloud_cluster_spec (Data Source)
# tidbcloud_cluster_specs (Data Source)

cluster_spec data source
cluster_specs data source

## Example Usage

Expand All @@ -26,11 +26,11 @@ provider "tidbcloud" {
private_key = "fake_private_key"
}
data "tidbcloud_cluster_spec" "example" {
data "tidbcloud_cluster_specs" "example" {
}
output "output" {
value = data.tidbcloud_cluster_spec.example
value = data.tidbcloud_cluster_specs.example
}
```

Expand All @@ -39,7 +39,7 @@ output "output" {

### Read-Only

- `id` (String) ignore it, it is just for test.
- `id` (String) data source ID.
- `items` (Attributes List) (see [below for nested schema](#nestedatt--items))
- `total` (Number) the total number of the spec.

Expand Down
170 changes: 170 additions & 0 deletions docs/data-sources/clusters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "tidbcloud_clusters Data Source - terraform-provider-tidbcloud"
subcategory: ""
description: |-
clusters data source
---

# tidbcloud_clusters (Data Source)

clusters data source

## Example Usage

```terraform
terraform {
required_providers {
tidbcloud = {
source = "tidbcloud/tidbcloud"
}
}
}
provider "tidbcloud" {
public_key = "fake_public_key"
private_key = "fake_private_key"
}
data "tidbcloud_clusters" "example" {
project_id = "fake_id"
}
output "output" {
value = data.tidbcloud_clusters.example
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `project_id` (String) The ID of the project

### Optional

- `page` (Number) Default:1 The number of pages.
- `page_size` (Number) Default:10 The size of a pages.

### Read-Only

- `id` (String) data source ID.
- `items` (Attributes List) The items of clusters in the project. (see [below for nested schema](#nestedatt--items))
- `total` (Number) The total number of project clusters.

<a id="nestedatt--items"></a>
### Nested Schema for `items`

Read-Only:

- `cloud_provider` (String) Enum: "AWS" "GCP", The cloud provider on which your TiDB cluster is hosted.
- `cluster_type` (String) The cluster type.
- `config` (Attributes) The configuration of the cluster. (see [below for nested schema](#nestedatt--items--config))
- `create_timestamp` (String) The creation time of the cluster in Unix timestamp seconds (epoch time).
- `id` (String) The ID of the cluster.
- `name` (String) The name of the cluster.
- `project_id` (String) The ID of the project.
- `region` (String) Region of the cluster.
- `status` (Attributes) The status of the cluster. (see [below for nested schema](#nestedatt--items--status))

<a id="nestedatt--items--config"></a>
### Nested Schema for `items.config`

Read-Only:

- `components` (Attributes) The components of the cluster. (see [below for nested schema](#nestedatt--items--config--components))
- `port` (Number) The TiDB port for connection. The port must be in the range of 1024-65535 except 10080, 4000 in default.
- For a Serverless Tier cluster, only port 4000 is available.

<a id="nestedatt--items--config--components"></a>
### Nested Schema for `items.config.components`

Optional:

- `tiflash` (Attributes) The TiFlash component of the cluster. (see [below for nested schema](#nestedatt--items--config--components--tiflash))

Read-Only:

- `tidb` (Attributes) The TiDB component of the cluster (see [below for nested schema](#nestedatt--items--config--components--tidb))
- `tikv` (Attributes) The TiKV component of the cluster (see [below for nested schema](#nestedatt--items--config--components--tikv))

<a id="nestedatt--items--config--components--tiflash"></a>
### Nested Schema for `items.config.components.tikv`

Read-Only:

- `node_quantity` (Number) The number of nodes in the cluster. You can get the minimum and step of a node quantity from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- TiFlash do not support decreasing node quantity.
- `node_size` (String) The size of the TiFlash component in the cluster, You can get the available node size of each region from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- Can not modify node_size of an existing cluster.
- `storage_size_gib` (Number) The storage size of a node in the cluster. You can get the minimum and maximum of storage size from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- Can not modify storage_size_gib of an existing cluster.


<a id="nestedatt--items--config--components--tidb"></a>
### Nested Schema for `items.config.components.tikv`

Read-Only:

- `node_quantity` (Number) The number of nodes in the cluster. You can get the minimum and step of a node quantity from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- `node_size` (String) The size of the TiDB component in the cluster, You can get the available node size of each region from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- If the vCPUs of TiDB or TiKV component is 2 or 4, then their vCPUs need to be the same.
- If the vCPUs of TiDB or TiKV component is 2 or 4, then the cluster does not support TiFlash.
- Can not modify node_size of an existing cluster.


<a id="nestedatt--items--config--components--tikv"></a>
### Nested Schema for `items.config.components.tikv`

Read-Only:

- `node_quantity` (Number) The number of nodes in the cluster. You can get the minimum and step of a node quantity from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- TiKV do not support decreasing node quantity.
- The node_quantity of TiKV must be a multiple of 3.
- `node_size` (String) The size of the TiKV component in the cluster, You can get the available node size of each region from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- If the vCPUs of TiDB or TiKV component is 2 or 4, then their vCPUs need to be the same.
- If the vCPUs of TiDB or TiKV component is 2 or 4, then the cluster does not support TiFlash.
- Can not modify node_size of an existing cluster.
- `storage_size_gib` (Number) The storage size of a node in the cluster. You can get the minimum and maximum of storage size from the [tidbcloud_cluster_specs datasource](../data-sources/cluster_specs.md).
- Can not modify storage_size_gib of an existing cluster.




<a id="nestedatt--items--status"></a>
### Nested Schema for `items.status`

Read-Only:

- `cluster_status` (String) Status of the cluster.
- `connection_strings` (Attributes) Connection strings. (see [below for nested schema](#nestedatt--items--status--connection_strings))
- `tidb_version` (String) TiDB version.

<a id="nestedatt--items--status--connection_strings"></a>
### Nested Schema for `items.status.connection_strings`

Read-Only:

- `default_user` (String) The default TiDB user for connection.
- `standard` (Attributes) Standard connection string. (see [below for nested schema](#nestedatt--items--status--connection_strings--standard))
- `vpc_peering` (Attributes) VPC peering connection string. (see [below for nested schema](#nestedatt--items--status--connection_strings--vpc_peering))

<a id="nestedatt--items--status--connection_strings--standard"></a>
### Nested Schema for `items.status.connection_strings.vpc_peering`

Read-Only:

- `host` (String) The host of standard connection.
- `port` (Number) The TiDB port for connection. The port must be in the range of 1024-65535 except 10080.


<a id="nestedatt--items--status--connection_strings--vpc_peering"></a>
### Nested Schema for `items.status.connection_strings.vpc_peering`

Read-Only:

- `host` (String) The host of VPC peering connection.
- `port` (Number) The TiDB port for connection. The port must be in the range of 1024-65535 except 10080.


Loading

0 comments on commit 0b7b748

Please sign in to comment.