Skip to content

Commit 911dadb

Browse files
committed
add
1 parent b2d486f commit 911dadb

25 files changed

+2185
-134
lines changed

tencentcloud/connectivity/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package connectivity
22

33
import (
44
"fmt"
5-
cdc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdc/v20201214"
65
"log"
76
"net/http"
87
"net/url"
98
"os"
109
"strconv"
1110
"time"
1211

12+
cdc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdc/v20201214"
13+
1314
csip "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip/v20221121"
1415
cos "github.com/tencentyun/cos-go-sdk-v5"
1516

tencentcloud/provider.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,11 @@ func Provider() *schema.Provider {
990990
"tencentcloud_clickhouse_instance_shards": cdwch.DataSourceTencentCloudClickhouseInstanceShards(),
991991
"tencentcloud_clickhouse_instance_nodes": cdwch.DataSourceTencentCloudClickhouseInstanceNodes(),
992992
"tencentcloud_organization_org_share_area": tco.DataSourceTencentCloudOrganizationOrgShareArea(),
993-
"tencentcloud_kubernetes_cluster_native_node_pools": tke.DataSourceTencentCloudKubernetesClusterNativeNodePools()},
993+
"tencentcloud_kubernetes_cluster_native_node_pools": tke.DataSourceTencentCloudKubernetesClusterNativeNodePools(),
994+
"tencentcloud_cdc_dedicated_cluster_hosts": cdc.DataSourceTencentCloudCdcDedicatedClusterHosts(),
995+
"tencentcloud_cdc_dedicated_cluster_instance_types": cdc.DataSourceTencentCloudCdcDedicatedClusterInstanceTypes(),
996+
"tencentcloud_cdc_dedicated_cluster_orders": cdc.DataSourceTencentCloudCdcDedicatedClusterOrders(),
997+
},
994998

995999
ResourcesMap: map[string]*schema.Resource{
9961000
"tencentcloud_project": project.ResourceTencentCloudProject(),
@@ -1989,6 +1993,7 @@ func Provider() *schema.Provider {
19891993
"tencentcloud_kubernetes_addon_config": tke.ResourceTencentCloudKubernetesAddonConfig(),
19901994
"tencentcloud_kubernetes_native_node_pool": tke.ResourceTencentCloudKubernetesNativeNodePool(),
19911995
"tencentcloud_cdc_site": cdc.ResourceTencentCloudCdcSite(),
1996+
"tencentcloud_cdc_dedicated_cluster": cdc.ResourceTencentCloudCdcDedicatedCluster(),
19921997
},
19931998

19941999
ConfigureFunc: providerConfigure,

tencentcloud/provider.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,4 +2146,15 @@ CDWPG
21462146

21472147
CSIP
21482148
Resource
2149-
tencentcloud_csip_risk_center
2149+
tencentcloud_csip_risk_center
2150+
2151+
CDC
2152+
Data Source
2153+
tencentcloud_cdc_dedicated_cluster_hosts
2154+
tencentcloud_cdc_dedicated_cluster_instance_types
2155+
tencentcloud_cdc_dedicated_cluster_orders
2156+
2157+
Resource
2158+
tencentcloud_cdc_site
2159+
tencentcloud_cdc_dedicated_cluster
2160+
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package cdc
2+
3+
import (
4+
"context"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
cdc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdc/v20201214"
8+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
9+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
10+
)
11+
12+
func DataSourceTencentCloudCdcDedicatedClusterHosts() *schema.Resource {
13+
return &schema.Resource{
14+
Read: DataSourceTencentCloudCdcDedicatedClusterHostsRead,
15+
Schema: map[string]*schema.Schema{
16+
"dedicated_cluster_id": {
17+
Required: true,
18+
Type: schema.TypeString,
19+
Description: "Dedicated Cluster ID.",
20+
},
21+
// computed
22+
"host_info_set": {
23+
Computed: true,
24+
Type: schema.TypeList,
25+
Description: "Dedicated Cluster Host Info.",
26+
Elem: &schema.Resource{
27+
Schema: map[string]*schema.Schema{
28+
"host_ip": {
29+
Type: schema.TypeString,
30+
Computed: true,
31+
Description: "Dedicated Cluster Host Ip (Deprecated).",
32+
},
33+
"service_type": {
34+
Type: schema.TypeString,
35+
Computed: true,
36+
Description: "Dedicated Cluster Service Type.",
37+
},
38+
"host_status": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
Description: "Dedicated Cluster Host Status.",
42+
},
43+
"host_type": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
Description: "Dedicated Cluster Host Type.",
47+
},
48+
"cpu_available": {
49+
Type: schema.TypeInt,
50+
Computed: true,
51+
Description: "Dedicated Cluster Host CPU Available Count.",
52+
},
53+
"cpu_total": {
54+
Type: schema.TypeInt,
55+
Computed: true,
56+
Description: "Dedicated Cluster Host CPU Total Count.",
57+
},
58+
"mem_available": {
59+
Type: schema.TypeInt,
60+
Computed: true,
61+
Description: "Dedicated Cluster Host Memory Available Count (GB).",
62+
},
63+
"mem_total": {
64+
Type: schema.TypeInt,
65+
Computed: true,
66+
Description: "Dedicated Cluster Host Memory Total Count (GB).",
67+
},
68+
"run_time": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
Description: "Dedicated Cluster Host Run Time.",
72+
},
73+
"expire_time": {
74+
Type: schema.TypeString,
75+
Computed: true,
76+
Description: "Dedicated Cluster Host Expire Time.",
77+
},
78+
"host_id": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
Description: "Dedicated Cluster Host ID.",
82+
},
83+
},
84+
},
85+
},
86+
"result_output_file": {
87+
Type: schema.TypeString,
88+
Optional: true,
89+
Description: "Used to save results.",
90+
},
91+
},
92+
}
93+
}
94+
95+
func DataSourceTencentCloudCdcDedicatedClusterHostsRead(d *schema.ResourceData, meta interface{}) error {
96+
defer tccommon.LogElapsed("data_source.tencentcloud_cdc_dedicated_cluster_hosts.read")()
97+
defer tccommon.InconsistentCheck(d, meta)()
98+
99+
var (
100+
logId = tccommon.GetLogId(tccommon.ContextNil)
101+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
102+
service = CdcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
103+
hostInfoSet []*cdc.HostInfo
104+
)
105+
106+
paramMap := make(map[string]interface{})
107+
if v, ok := d.GetOk("dedicated_cluster_id"); ok {
108+
paramMap["DedicatedClusterId"] = helper.String(v.(string))
109+
}
110+
111+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
112+
result, e := service.DescribeCdcHostByFilter(ctx, paramMap)
113+
if e != nil {
114+
return tccommon.RetryError(e)
115+
}
116+
117+
hostInfoSet = result
118+
return nil
119+
})
120+
121+
if err != nil {
122+
return err
123+
}
124+
125+
ids := make([]string, 0, len(hostInfoSet))
126+
tmpList := make([]map[string]interface{}, 0, len(hostInfoSet))
127+
128+
if hostInfoSet != nil {
129+
for _, hostInfo := range hostInfoSet {
130+
hostInfoMap := map[string]interface{}{}
131+
132+
if hostInfo.HostIp != nil {
133+
hostInfoMap["host_ip"] = hostInfo.HostIp
134+
}
135+
136+
if hostInfo.ServiceType != nil {
137+
hostInfoMap["service_type"] = hostInfo.ServiceType
138+
}
139+
140+
if hostInfo.HostStatus != nil {
141+
hostInfoMap["host_status"] = hostInfo.HostStatus
142+
}
143+
144+
if hostInfo.HostType != nil {
145+
hostInfoMap["host_type"] = hostInfo.HostType
146+
}
147+
148+
if hostInfo.CpuAvailable != nil {
149+
hostInfoMap["cpu_available"] = hostInfo.CpuAvailable
150+
}
151+
152+
if hostInfo.CpuTotal != nil {
153+
hostInfoMap["cpu_total"] = hostInfo.CpuTotal
154+
}
155+
156+
if hostInfo.MemAvailable != nil {
157+
hostInfoMap["mem_available"] = hostInfo.MemAvailable
158+
}
159+
160+
if hostInfo.MemTotal != nil {
161+
hostInfoMap["mem_total"] = hostInfo.MemTotal
162+
}
163+
164+
if hostInfo.RunTime != nil {
165+
hostInfoMap["run_time"] = hostInfo.RunTime
166+
}
167+
168+
if hostInfo.ExpireTime != nil {
169+
hostInfoMap["expire_time"] = hostInfo.ExpireTime
170+
}
171+
172+
if hostInfo.HostId != nil {
173+
hostInfoMap["host_id"] = hostInfo.HostId
174+
}
175+
176+
ids = append(ids)
177+
tmpList = append(tmpList, hostInfoMap)
178+
}
179+
180+
_ = d.Set("host_info_set", tmpList)
181+
}
182+
183+
d.SetId(helper.DataResourceIdsHash(ids))
184+
output, ok := d.GetOk("result_output_file")
185+
if ok && output.(string) != "" {
186+
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
187+
return e
188+
}
189+
}
190+
191+
return nil
192+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Use this data source to query detailed information of CDC dedicated cluster hosts
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_cdc_dedicated_cluster_hosts" "hosts" {
7+
dedicated_cluster_id = "cluster-262n63e8"
8+
}
9+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cdc
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
6+
"testing"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudNeedFixCdcDedicatedClusterHostsDataSource_basic -v
10+
func TestAccTencentCloudNeedFixCdcDedicatedClusterHostsDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
tcacctest.AccPreCheck(t)
15+
},
16+
Providers: tcacctest.AccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccCdcDedicatedClusterHostsDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_cdc_dedicated_cluster_hosts.hosts", "id"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_cdc_dedicated_cluster_hosts.hosts", "dedicated_cluster_id"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccCdcDedicatedClusterHostsDataSource = `
30+
data "tencentcloud_cdc_dedicated_cluster_hosts" "hosts" {
31+
dedicated_cluster_id = "cluster-262n63e8"
32+
}
33+
`

0 commit comments

Comments
 (0)