Skip to content

Commit 5b2f858

Browse files
authored
feat(wedata): [127477929] add new resource (#3572)
* add * add * add
1 parent b68f8a8 commit 5b2f858

8 files changed

+596
-0
lines changed

.changelog/3572.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-resource
2+
tencentcloud_wedata_add_calc_engines_to_project_operation
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_wedata_data_backfill_plan_operation
7+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,8 @@ func Provider() *schema.Provider {
23522352
"tencentcloud_wedata_code_file": wedata.ResourceTencentCloudWedataCodeFile(),
23532353
"tencentcloud_wedata_run_sql_script_operation": wedata.ResourceTencentCloudWedataRunSqlScriptOperation(),
23542354
"tencentcloud_wedata_stop_sql_script_run_operation": wedata.ResourceTencentCloudWedataStopSqlScriptRunOperation(),
2355+
"tencentcloud_wedata_add_calc_engines_to_project_operation": wedata.ResourceTencentCloudWedataAddCalcEnginesToProjectOperation(),
2356+
"tencentcloud_wedata_data_backfill_plan_operation": wedata.ResourceTencentCloudWedataDataBackfillPlanOperation(),
23552357
"tencentcloud_cfw_address_template": cfw.ResourceTencentCloudCfwAddressTemplate(),
23562358
"tencentcloud_cfw_block_ignore": cfw.ResourceTencentCloudCfwBlockIgnore(),
23572359
"tencentcloud_cfw_edge_policy": cfw.ResourceTencentCloudCfwEdgePolicy(),
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package wedata
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
wedatav20250806 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata/v20250806"
10+
11+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
12+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
13+
)
14+
15+
func ResourceTencentCloudWedataAddCalcEnginesToProjectOperation() *schema.Resource {
16+
return &schema.Resource{
17+
Create: resourceTencentCloudWedataAddCalcEnginesToProjectOperationCreate,
18+
Read: resourceTencentCloudWedataAddCalcEnginesToProjectOperationRead,
19+
Delete: resourceTencentCloudWedataAddCalcEnginesToProjectOperationDelete,
20+
Schema: map[string]*schema.Schema{
21+
"project_id": {
22+
Type: schema.TypeString,
23+
Required: true,
24+
ForceNew: true,
25+
Description: "Project ID to be modified.",
26+
},
27+
28+
"dlc_info": {
29+
Type: schema.TypeList,
30+
Required: true,
31+
ForceNew: true,
32+
Description: "DLC cluster information.",
33+
Elem: &schema.Resource{
34+
Schema: map[string]*schema.Schema{
35+
"compute_resources": {
36+
Type: schema.TypeSet,
37+
Required: true,
38+
Description: "DLC resource names (need to add role Uin to DLC, otherwise resources may not be available).",
39+
Elem: &schema.Schema{
40+
Type: schema.TypeString,
41+
},
42+
},
43+
"region": {
44+
Type: schema.TypeString,
45+
Required: true,
46+
Description: "DLC region.",
47+
},
48+
"default_database": {
49+
Type: schema.TypeString,
50+
Required: true,
51+
Description: "Specify the default database for the DLC cluster.",
52+
},
53+
"standard_mode_env_tag": {
54+
Type: schema.TypeString,
55+
Optional: true,
56+
Description: "Cluster configuration tag (only effective for standard mode projects and required for standard mode). Enum values:\n- Prod (Production environment)\n- Dev (Development environment).",
57+
},
58+
"access_account": {
59+
Type: schema.TypeString,
60+
Optional: true,
61+
Description: "Access account (only effective for standard mode projects and required for standard mode), used to submit DLC tasks.\nIt is recommended to use a specified sub-account and set corresponding database table permissions for the sub-account; task runner mode may cause task failures when the responsible person leaves; main account mode is not easy for permission control when multiple projects have different permissions.\n\nEnum values:\n- TASK_RUNNER (Task Runner)\n- OWNER (Main Account Mode)\n- SUB (Sub-Account Mode).",
62+
},
63+
"sub_account_uin": {
64+
Type: schema.TypeString,
65+
Optional: true,
66+
Description: "Sub-account ID (only effective for standard mode projects), when AccessAccount is in sub-account mode, the sub-account ID information needs to be specified, other modes do not need to be specified.",
67+
},
68+
},
69+
},
70+
},
71+
},
72+
}
73+
}
74+
75+
func resourceTencentCloudWedataAddCalcEnginesToProjectOperationCreate(d *schema.ResourceData, meta interface{}) error {
76+
defer tccommon.LogElapsed("resource.tencentcloud_wedata_add_calc_engines_to_project_operation.create")()
77+
defer tccommon.InconsistentCheck(d, meta)()
78+
79+
var (
80+
logId = tccommon.GetLogId(tccommon.ContextNil)
81+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
82+
request = wedatav20250806.NewAddCalcEnginesToProjectRequest()
83+
projectId string
84+
)
85+
86+
if v, ok := d.GetOk("project_id"); ok {
87+
request.ProjectId = helper.String(v.(string))
88+
projectId = v.(string)
89+
}
90+
91+
if v, ok := d.GetOk("dlc_info"); ok {
92+
for _, item := range v.([]interface{}) {
93+
dLCInfoMap := item.(map[string]interface{})
94+
dLCClusterInfo := wedatav20250806.DLCClusterInfo{}
95+
if v, ok := dLCInfoMap["compute_resources"]; ok {
96+
computeResourcesSet := v.(*schema.Set).List()
97+
for i := range computeResourcesSet {
98+
computeResources := computeResourcesSet[i].(string)
99+
dLCClusterInfo.ComputeResources = append(dLCClusterInfo.ComputeResources, helper.String(computeResources))
100+
}
101+
}
102+
103+
if v, ok := dLCInfoMap["region"].(string); ok && v != "" {
104+
dLCClusterInfo.Region = helper.String(v)
105+
}
106+
107+
if v, ok := dLCInfoMap["default_database"].(string); ok && v != "" {
108+
dLCClusterInfo.DefaultDatabase = helper.String(v)
109+
}
110+
111+
if v, ok := dLCInfoMap["standard_mode_env_tag"].(string); ok && v != "" {
112+
dLCClusterInfo.StandardModeEnvTag = helper.String(v)
113+
}
114+
115+
if v, ok := dLCInfoMap["access_account"].(string); ok && v != "" {
116+
dLCClusterInfo.AccessAccount = helper.String(v)
117+
}
118+
119+
if v, ok := dLCInfoMap["sub_account_uin"].(string); ok && v != "" {
120+
dLCClusterInfo.SubAccountUin = helper.String(v)
121+
}
122+
123+
request.DLCInfo = append(request.DLCInfo, &dLCClusterInfo)
124+
}
125+
}
126+
127+
reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
128+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseWedataV20250806Client().AddCalcEnginesToProjectWithContext(ctx, request)
129+
if e != nil {
130+
return tccommon.RetryError(e)
131+
} else {
132+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
133+
}
134+
135+
return nil
136+
})
137+
138+
if reqErr != nil {
139+
log.Printf("[CRITAL]%s create wedata add calc engines to project operation failed, reason:%+v", logId, reqErr)
140+
return reqErr
141+
}
142+
143+
d.SetId(projectId)
144+
return resourceTencentCloudWedataAddCalcEnginesToProjectOperationRead(d, meta)
145+
}
146+
147+
func resourceTencentCloudWedataAddCalcEnginesToProjectOperationRead(d *schema.ResourceData, meta interface{}) error {
148+
defer tccommon.LogElapsed("resource.tencentcloud_wedata_add_calc_engines_to_project_operation.read")()
149+
defer tccommon.InconsistentCheck(d, meta)()
150+
151+
return nil
152+
}
153+
154+
func resourceTencentCloudWedataAddCalcEnginesToProjectOperationDelete(d *schema.ResourceData, meta interface{}) error {
155+
defer tccommon.LogElapsed("resource.tencentcloud_wedata_add_calc_engines_to_project_operation.delete")()
156+
defer tccommon.InconsistentCheck(d, meta)()
157+
158+
return nil
159+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Provides a resource to create a WeData add calc engines to project operation
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_wedata_add_calc_engines_to_project_operation" "example" {
7+
project_id = "20241107221758402"
8+
dlc_info {
9+
compute_resources = [
10+
"dlc_linau6d4bu8bd5u52ffu52a8"
11+
]
12+
region = "ap-guangzhou"
13+
default_database = "default_db"
14+
}
15+
}
16+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package wedata_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 TestAccTencentCloudWedataAddCalcEnginesToProjectOperationResource_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+
{
20+
Config: testAccWedataAddCalcEnginesToProjectOperation,
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("tencentcloud_wedata_add_calc_engines_to_project_operation.example", "id"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccWedataAddCalcEnginesToProjectOperation = `
30+
resource "tencentcloud_wedata_add_calc_engines_to_project_operation" "example" {
31+
project_id = "20241107221758402"
32+
dlc_info {
33+
compute_resources = [
34+
"dlc_linau6d4bu8bd5u52ffu52a8"
35+
]
36+
region = "ap-guangzhou"
37+
default_database = "default_db"
38+
}
39+
}
40+
`

0 commit comments

Comments
 (0)