Skip to content

Commit e52371d

Browse files
authored
feat(dlc): [126452417] add data source (#3478)
* add * add
1 parent 822e8a0 commit e52371d

21 files changed

+2377
-788
lines changed

.changelog/3478.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-data-source
2+
tencentcloud_dlc_task_result
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_dlc_engine_node_specifications
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_dlc_native_spark_sessions
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_dlc_standard_engine_resource_group_config_information
15+
```

tencentcloud/provider.go

Lines changed: 792 additions & 788 deletions
Large diffs are not rendered by default.

tencentcloud/provider.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,10 @@ tencentcloud_dlc_check_data_engine_image_can_be_upgrade
21362136
tencentcloud_dlc_check_data_engine_config_pairs_validity
21372137
tencentcloud_dlc_describe_updatable_data_engines
21382138
tencentcloud_dlc_describe_data_engine_events
2139+
tencentcloud_dlc_task_result
2140+
tencentcloud_dlc_engine_node_specifications
2141+
tencentcloud_dlc_native_spark_sessions
2142+
tencentcloud_dlc_standard_engine_resource_group_config_information
21392143

21402144
Resource
21412145
tencentcloud_dlc_work_group
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
package dlc
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
dlcv20210125 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
9+
10+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
12+
)
13+
14+
func DataSourceTencentCloudDlcEngineNodeSpecifications() *schema.Resource {
15+
return &schema.Resource{
16+
Read: dataSourceTencentCloudDlcEngineNodeSpecificationsRead,
17+
Schema: map[string]*schema.Schema{
18+
"data_engine_name": {
19+
Type: schema.TypeString,
20+
Optional: true,
21+
Description: "Engine Name.",
22+
},
23+
24+
"driver_spec": {
25+
Type: schema.TypeList,
26+
Computed: true,
27+
Description: "Driver available specifications.",
28+
Elem: &schema.Resource{
29+
Schema: map[string]*schema.Schema{
30+
"name": {
31+
Type: schema.TypeString,
32+
Required: true,
33+
Description: "Specification name.",
34+
},
35+
"cu": {
36+
Type: schema.TypeInt,
37+
Required: true,
38+
Description: "Current specification of CU number.",
39+
},
40+
"cpu": {
41+
Type: schema.TypeInt,
42+
Required: true,
43+
Description: "Current CPU specifications.",
44+
},
45+
"memory": {
46+
Type: schema.TypeInt,
47+
Required: true,
48+
Description: "The current memory size, in GB.",
49+
},
50+
},
51+
},
52+
},
53+
54+
"executor_spec": {
55+
Type: schema.TypeList,
56+
Computed: true,
57+
Description: "Available executor specifications.",
58+
Elem: &schema.Resource{
59+
Schema: map[string]*schema.Schema{
60+
"name": {
61+
Type: schema.TypeString,
62+
Required: true,
63+
Description: "Specification name.",
64+
},
65+
"cu": {
66+
Type: schema.TypeInt,
67+
Required: true,
68+
Description: "Current specification of CU number.",
69+
},
70+
"cpu": {
71+
Type: schema.TypeInt,
72+
Required: true,
73+
Description: "Current CPU specifications.",
74+
},
75+
"memory": {
76+
Type: schema.TypeInt,
77+
Required: true,
78+
Description: "The current memory size, in GB.",
79+
},
80+
},
81+
},
82+
},
83+
84+
"result_output_file": {
85+
Type: schema.TypeString,
86+
Optional: true,
87+
Description: "Used to save results.",
88+
},
89+
},
90+
}
91+
}
92+
93+
func dataSourceTencentCloudDlcEngineNodeSpecificationsRead(d *schema.ResourceData, meta interface{}) error {
94+
defer tccommon.LogElapsed("data_source.tencentcloud_dlc_engine_node_specifications.read")()
95+
defer tccommon.InconsistentCheck(d, meta)()
96+
97+
var (
98+
logId = tccommon.GetLogId(nil)
99+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
100+
service = DlcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
101+
)
102+
103+
paramMap := make(map[string]interface{})
104+
if v, ok := d.GetOk("data_engine_name"); ok {
105+
paramMap["DataEngineName"] = helper.String(v.(string))
106+
}
107+
108+
var respData *dlcv20210125.DescribeEngineNodeSpecResponseParams
109+
reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
110+
result, e := service.DescribeDlcEngineNodeSpecificationsByFilter(ctx, paramMap)
111+
if e != nil {
112+
return tccommon.RetryError(e)
113+
}
114+
115+
respData = result
116+
return nil
117+
})
118+
119+
if reqErr != nil {
120+
return reqErr
121+
}
122+
123+
driverSpecList := make([]map[string]interface{}, 0, len(respData.DriverSpec))
124+
if respData.DriverSpec != nil {
125+
for _, driverSpec := range respData.DriverSpec {
126+
driverSpecMap := map[string]interface{}{}
127+
if driverSpec.Name != nil {
128+
driverSpecMap["name"] = driverSpec.Name
129+
}
130+
131+
if driverSpec.Cu != nil {
132+
driverSpecMap["cu"] = driverSpec.Cu
133+
}
134+
135+
if driverSpec.Cpu != nil {
136+
driverSpecMap["cpu"] = driverSpec.Cpu
137+
}
138+
139+
if driverSpec.Memory != nil {
140+
driverSpecMap["memory"] = driverSpec.Memory
141+
}
142+
143+
driverSpecList = append(driverSpecList, driverSpecMap)
144+
}
145+
146+
_ = d.Set("driver_spec", driverSpecList)
147+
}
148+
149+
executorSpecList := make([]map[string]interface{}, 0, len(respData.ExecutorSpec))
150+
if respData.ExecutorSpec != nil {
151+
for _, executorSpec := range respData.ExecutorSpec {
152+
executorSpecMap := map[string]interface{}{}
153+
if executorSpec.Name != nil {
154+
executorSpecMap["name"] = executorSpec.Name
155+
}
156+
157+
if executorSpec.Cu != nil {
158+
executorSpecMap["cu"] = executorSpec.Cu
159+
}
160+
161+
if executorSpec.Cpu != nil {
162+
executorSpecMap["cpu"] = executorSpec.Cpu
163+
}
164+
165+
if executorSpec.Memory != nil {
166+
executorSpecMap["memory"] = executorSpec.Memory
167+
}
168+
169+
executorSpecList = append(executorSpecList, executorSpecMap)
170+
}
171+
172+
_ = d.Set("executor_spec", executorSpecList)
173+
}
174+
175+
d.SetId(helper.BuildToken())
176+
output, ok := d.GetOk("result_output_file")
177+
if ok && output.(string) != "" {
178+
if e := tccommon.WriteToFile(output.(string), d); e != nil {
179+
return e
180+
}
181+
}
182+
183+
return nil
184+
}
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 DLC engine node specifications
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_dlc_engine_node_specifications" "example" {
7+
data_engine_name = "tf-example"
8+
}
9+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dlc_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
func TestAccTencentCloudDlcEngineNodeSpecificationsDataSource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() {
15+
tcacctest.AccPreCheck(t)
16+
},
17+
Providers: tcacctest.AccProviders,
18+
Steps: []resource.TestStep{{
19+
Config: testAccDlcEngineNodeSpecificationsDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_dlc_engine_node_specifications.example"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_dlc_engine_node_specifications.example", "data_engine_name"),
23+
),
24+
}},
25+
})
26+
}
27+
28+
const testAccDlcEngineNodeSpecificationsDataSource = `
29+
data "tencentcloud_dlc_engine_node_specifications" "example" {
30+
data_engine_name = "tf-example"
31+
}
32+
`

0 commit comments

Comments
 (0)