Skip to content

Commit 119834a

Browse files
committed
[fix some format and add cluster_id filter for datasource instance]
1. fix some format issue 2. add cluster_id filter for datasource instance
1 parent 485e902 commit 119834a

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

examples/tencentcloud-cynosdb/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resource "tencentcloud_cynosdb_cluster" "foo" {
1313
password = "cynos@123"
1414
instance_maintain_duration = 7200
1515
instance_maintain_start_time = 10800
16-
instance_maintain_weekdays = [
16+
instance_maintain_weekdays = [
1717
"Fri",
1818
"Mon",
1919
"Sat",
@@ -49,7 +49,7 @@ resource "tencentcloud_cynosdb_readonly_instance" "foo" {
4949

5050
instance_maintain_duration = 3600
5151
instance_maintain_start_time = 10800
52-
instance_maintain_weekdays = [
52+
instance_maintain_weekdays = [
5353
"Fri",
5454
"Mon",
5555
"Sat",

tencentcloud/data_source_tc_cynosdb_clusters.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Example Usage
55
66
```hcl
77
data "tencentcloud_cynosdb_clusters" "foo" {
8-
cluster_id = "cynosdbmysql-dzj5l8gz"
9-
project_id = 0
10-
db_type = "MYSQL"
8+
cluster_id = "cynosdbmysql-dzj5l8gz"
9+
project_id = 0
10+
db_type = "MYSQL"
1111
cluster_name = "test"
1212
}
1313
```

tencentcloud/data_source_tc_cynosdb_clusters_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func TestAccTencentCloudCynosdbClustersDataSource_full(t *testing.T) {
3939
func testAccCynosdbClusterstDataSource_full() string {
4040
return testAccCynosdbCluster + `
4141
data "tencentcloud_cynosdb_clusters" "cluster_full" {
42-
cluster_id = tencentcloud_cynosdb_cluster.foo.id
43-
project_id = 0
44-
db_type = "MYSQL"
42+
cluster_id = tencentcloud_cynosdb_cluster.foo.id
43+
project_id = 0
44+
db_type = "MYSQL"
4545
cluster_name = "tf-cynosdb"
4646
}`
4747
}

tencentcloud/data_source_tc_cynosdb_instances.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Example Usage
55
66
```hcl
77
data "tencentcloud_cynosdb_instances" "foo" {
8-
instance_id = "cynosdbmysql-ins-0wln9u6w"
9-
project_id = 0
10-
db_type = "MYSQL"
8+
instance_id = "cynosdbmysql-ins-0wln9u6w"
9+
project_id = 0
10+
db_type = "MYSQL"
1111
instance_name = "test"
1212
}
1313
```
@@ -34,6 +34,11 @@ func dataSourceTencentCloudCynosdbInstances() *schema.Resource {
3434
Optional: true,
3535
Description: "Type of CynosDB, and available values include `MYSQL`, `POSTGRESQL`.",
3636
},
37+
"cluster_id": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
Description: "ID of the cluster.",
41+
},
3742
"instance_id": {
3843
Type: schema.TypeString,
3944
Optional: true,
@@ -128,6 +133,10 @@ func dataSourceTencentCloudCynosdbInstancesRead(d *schema.ResourceData, meta int
128133
if v, ok := d.GetOkExists("project_id"); ok {
129134
params["ProjectId"] = fmt.Sprintf("%d", v.(int))
130135
}
136+
var clusterId string
137+
if v, ok := d.GetOk("cluster_id"); ok {
138+
clusterId = v.(string)
139+
}
131140

132141
cynosdbService := CynosdbService{
133142
client: meta.(*TencentCloudClient).apiV3Conn,
@@ -141,6 +150,10 @@ func dataSourceTencentCloudCynosdbInstancesRead(d *schema.ResourceData, meta int
141150
ids := make([]string, 0, len(instances))
142151
instanceList := make([]map[string]interface{}, 0, len(instances))
143152
for _, instance := range instances {
153+
if clusterId != "" && *instance.ClusterId != clusterId {
154+
continue
155+
}
156+
144157
mapping := map[string]interface{}{
145158
"cluster_id": instance.ClusterId,
146159
"instance_id": instance.InstanceId,

tencentcloud/data_source_tc_cynosdb_instances_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ func TestAccTencentCloudCynosdbInstancesDataSource_full(t *testing.T) {
3434
func testAccCynosdbInstancestDataSource_full() string {
3535
return testAccCynosdbReadonlyInstance + `
3636
data "tencentcloud_cynosdb_instances" "instances" {
37-
instance_id = tencentcloud_cynosdb_readonly_instance.foo.id
38-
project_id = 0
39-
db_type = "MYSQL"
37+
instance_id = tencentcloud_cynosdb_readonly_instance.foo.id
38+
project_id = 0
39+
db_type = "MYSQL"
40+
cluster_id = tencentcloud_cynosdb_readonly_instance.foo.cluster_id
4041
instance_name = "tf-cynosdb-readonly-instance"
4142
}`
4243
}

website/docs/d/cynosdb_instances.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ data "tencentcloud_cynosdb_instances" "foo" {
2626

2727
The following arguments are supported:
2828

29+
* `cluster_id` - (Optional) ID of the cluster.
2930
* `db_type` - (Optional) Type of CynosDB, and available values include `MYSQL`, `POSTGRESQL`.
3031
* `instance_id` - (Optional) ID of the Cynosdb instance to be queried.
3132
* `instance_name` - (Optional) Name of the Cynosdb instance to be queried.

0 commit comments

Comments
 (0)