Skip to content

Commit 5d6b16c

Browse files
committed
add
1 parent 60a66b7 commit 5d6b16c

File tree

12 files changed

+15142
-0
lines changed

12 files changed

+15142
-0
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,8 @@ func Provider() *schema.Provider {
22452245
"tencentcloud_dlc_user_data_engine_config": dlc.ResourceTencentCloudDlcUserDataEngineConfig(),
22462246
"tencentcloud_dlc_user_vpc_connection": dlc.ResourceTencentCloudDlcUserVpcConnection(),
22472247
"tencentcloud_dlc_standard_engine_resource_group": dlc.ResourceTencentCloudDlcStandardEngineResourceGroup(),
2248+
"tencentcloud_dlc_data_mask_strategy": dlc.ResourceTencentCloudDlcDataMaskStrategy(),
2249+
"tencentcloud_dlc_attach_data_mask_policy": dlc.ResourceTencentCloudDlcAttachDataMaskPolicy(),
22482250
"tencentcloud_waf_custom_rule": waf.ResourceTencentCloudWafCustomRule(),
22492251
"tencentcloud_waf_custom_white_rule": waf.ResourceTencentCloudWafCustomWhiteRule(),
22502252
"tencentcloud_waf_clb_domain": waf.ResourceTencentCloudWafClbDomain(),

tencentcloud/provider.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,8 @@ tencentcloud_dlc_update_row_filter_operation
21672167
tencentcloud_dlc_bind_work_groups_to_user_attachment
21682168
tencentcloud_dlc_user_vpc_connection
21692169
tencentcloud_dlc_standard_engine_resource_group
2170+
tencentcloud_dlc_data_mask_strategy
2171+
tencentcloud_dlc_attach_data_mask_policy
21702172

21712173
Web Application Firewall(WAF)
21722174
Data Source
Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
package dlc
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"strings"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
dlcv20210125 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
12+
13+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
14+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
15+
)
16+
17+
func ResourceTencentCloudDlcAttachDataMaskPolicy() *schema.Resource {
18+
return &schema.Resource{
19+
Create: resourceTencentCloudDlcAttachDataMaskPolicyCreate,
20+
Read: resourceTencentCloudDlcAttachDataMaskPolicyRead,
21+
Delete: resourceTencentCloudDlcAttachDataMaskPolicyDelete,
22+
Schema: map[string]*schema.Schema{
23+
"data_mask_strategy_policy_set": {
24+
Type: schema.TypeList,
25+
Optional: true,
26+
ForceNew: true,
27+
MaxItems: 1,
28+
Description: "A collection of data masking policy permission objects to be bound.",
29+
Elem: &schema.Resource{
30+
Schema: map[string]*schema.Schema{
31+
"policy_info": {
32+
Type: schema.TypeList,
33+
Optional: true,
34+
ForceNew: true,
35+
MaxItems: 1,
36+
Description: "Data masking permission object.",
37+
Elem: &schema.Resource{
38+
Schema: map[string]*schema.Schema{
39+
"database": {
40+
Type: schema.TypeString,
41+
Required: true,
42+
ForceNew: true,
43+
Description: "The name of the database to be authorized. Use * to represent all databases under the current Catalog. For administrator-level authorization, only * is allowed. For data connection-level authorization, leave it empty. For other types, specify the database name.",
44+
},
45+
"catalog": {
46+
Type: schema.TypeString,
47+
Required: true,
48+
ForceNew: true,
49+
Description: "The name of the data source to be authorized. For administrator-level authorization, only * is allowed (representing all resources at this level). For data source-level and database-level authorization, only COSDataCatalog or * is allowed. For table-level authorization, custom data sources can be specified. Defaults to DataLakeCatalog if not specified. Note: For custom data sources, DLC can only manage a subset of permissions provided by the user during data source integration.",
50+
},
51+
"table": {
52+
Type: schema.TypeString,
53+
Required: true,
54+
ForceNew: true,
55+
Description: "The name of the table to be authorized. Use * to represent all tables under the current Database. For administrator-level authorization, only * is allowed. For data connection-level and database-level authorization, leave it empty. For other types, specify the table name.",
56+
},
57+
"operation": {
58+
Type: schema.TypeString,
59+
Required: true,
60+
ForceNew: true,
61+
Description: "The permission operation to be granted, varying by authorization level. Administrator-level: ALL (default). Data connection-level: CREATE. Database-level: ALL, CREATE, ALTER, DROP. Table-level: ALL, SELECT, INSERT, ALTER, DELETE, DROP, UPDATE. Note: For table-level permissions, only SELECT is supported if the data source is not COSDataCatalog.",
62+
},
63+
"policy_type": {
64+
Type: schema.TypeString,
65+
Optional: true,
66+
ForceNew: true,
67+
Description: "The type of authorization. Currently supports eight types: ADMIN (administrator-level), DATASOURCE (data connection-level), DATABASE (database-level), TABLE (table-level), VIEW (view-level), FUNCTION (function-level), COLUMN (column-level), ENGINE (data engine-level). Defaults to administrator-level.",
68+
},
69+
"column": {
70+
Type: schema.TypeString,
71+
Optional: true,
72+
ForceNew: true,
73+
Description: "The name of the column to be authorized. Use * to represent all columns. For administrator-level authorization, only * is allowed.",
74+
},
75+
"mode": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
ForceNew: true,
79+
Description: "The authorization mode. Do not fill in this parameter. COMMON: Normal mode. SENIOR: Advanced mode.",
80+
},
81+
},
82+
},
83+
},
84+
"data_mask_strategy_id": {
85+
Type: schema.TypeString,
86+
Optional: true,
87+
ForceNew: true,
88+
Description: "The ID of the data masking strategy.",
89+
},
90+
"column_type": {
91+
Type: schema.TypeString,
92+
Optional: true,
93+
ForceNew: true,
94+
Description: "The type of the bound field.",
95+
},
96+
},
97+
},
98+
},
99+
},
100+
}
101+
}
102+
103+
func resourceTencentCloudDlcAttachDataMaskPolicyCreate(d *schema.ResourceData, meta interface{}) error {
104+
defer tccommon.LogElapsed("resource.tencentcloud_dlc_attach_data_mask_policy.create")()
105+
defer tccommon.InconsistentCheck(d, meta)()
106+
107+
var (
108+
logId = tccommon.GetLogId(tccommon.ContextNil)
109+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
110+
request = dlcv20210125.NewAttachDataMaskPolicyRequest()
111+
catalog string
112+
dataBase string
113+
table string
114+
column string
115+
dataMaskStrategyId string
116+
)
117+
118+
if v, ok := d.GetOk("data_mask_strategy_policy_set"); ok {
119+
for _, item := range v.([]interface{}) {
120+
dataMaskStrategyPolicySetMap := item.(map[string]interface{})
121+
dataMaskStrategyPolicy := dlcv20210125.DataMaskStrategyPolicy{}
122+
if policyInfoMap, ok := helper.ConvertInterfacesHeadToMap(dataMaskStrategyPolicySetMap["policy_info"]); ok {
123+
policy := dlcv20210125.Policy{}
124+
if v, ok := policyInfoMap["database"].(string); ok && v != "" {
125+
policy.Database = helper.String(v)
126+
dataBase = v
127+
}
128+
129+
if v, ok := policyInfoMap["catalog"].(string); ok && v != "" {
130+
policy.Catalog = helper.String(v)
131+
catalog = v
132+
}
133+
134+
if v, ok := policyInfoMap["table"].(string); ok && v != "" {
135+
policy.Table = helper.String(v)
136+
table = v
137+
}
138+
139+
if v, ok := policyInfoMap["operation"].(string); ok && v != "" {
140+
policy.Operation = helper.String(v)
141+
}
142+
143+
if v, ok := policyInfoMap["policy_type"].(string); ok && v != "" {
144+
policy.PolicyType = helper.String(v)
145+
}
146+
147+
if v, ok := policyInfoMap["column"].(string); ok && v != "" {
148+
policy.Column = helper.String(v)
149+
column = v
150+
}
151+
152+
if v, ok := policyInfoMap["mode"].(string); ok && v != "" {
153+
policy.Mode = helper.String(v)
154+
}
155+
156+
dataMaskStrategyPolicy.PolicyInfo = &policy
157+
}
158+
159+
if v, ok := dataMaskStrategyPolicySetMap["data_mask_strategy_id"].(string); ok && v != "" {
160+
dataMaskStrategyPolicy.DataMaskStrategyId = helper.String(v)
161+
}
162+
163+
if v, ok := dataMaskStrategyPolicySetMap["column_type"].(string); ok && v != "" {
164+
dataMaskStrategyPolicy.ColumnType = helper.String(v)
165+
}
166+
167+
request.DataMaskStrategyPolicySet = append(request.DataMaskStrategyPolicySet, &dataMaskStrategyPolicy)
168+
}
169+
}
170+
171+
reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
172+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDlcClient().AttachDataMaskPolicyWithContext(ctx, request)
173+
if e != nil {
174+
return tccommon.RetryError(e)
175+
} else {
176+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
177+
}
178+
179+
return nil
180+
})
181+
182+
if reqErr != nil {
183+
log.Printf("[CRITAL]%s create dlc attach data mask policy failed, reason:%+v", logId, reqErr)
184+
return reqErr
185+
}
186+
187+
policyInfoStr := strings.Join([]string{catalog, dataBase, table, column}, tccommon.COMMA_SP)
188+
d.SetId(strings.Join([]string{policyInfoStr, dataMaskStrategyId}, tccommon.FILED_SP))
189+
return resourceTencentCloudDlcAttachDataMaskPolicyRead(d, meta)
190+
}
191+
192+
func resourceTencentCloudDlcAttachDataMaskPolicyRead(d *schema.ResourceData, meta interface{}) error {
193+
defer tccommon.LogElapsed("resource.tencentcloud_dlc_attach_data_mask_policy.read")()
194+
defer tccommon.InconsistentCheck(d, meta)()
195+
196+
var (
197+
logId = tccommon.GetLogId(tccommon.ContextNil)
198+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
199+
service = DlcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
200+
)
201+
202+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
203+
if len(idSplit) != 2 {
204+
return fmt.Errorf("id is broken,%s", d.Id())
205+
}
206+
207+
policyInfoStr := idSplit[0]
208+
secIdSplit := strings.Split(policyInfoStr, tccommon.COMMA_SP)
209+
if len(secIdSplit) != 4 {
210+
return fmt.Errorf("id is broken,%s", d.Id())
211+
}
212+
213+
catalog := secIdSplit[0]
214+
dataBase := secIdSplit[1]
215+
table := secIdSplit[2]
216+
column := secIdSplit[3]
217+
218+
respData, err := service.DescribeDlcAttachDataMaskPolicyById(ctx, catalog, dataBase, table)
219+
if err != nil {
220+
return err
221+
}
222+
223+
if respData == nil {
224+
log.Printf("[WARN]%s resource `tencentcloud_dlc_attach_data_mask_policy` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
225+
d.SetId("")
226+
return nil
227+
}
228+
229+
if respData.Columns != nil {
230+
for _, item := range respData.Columns {
231+
if item.Name != nil && *item.Name == column {
232+
tmpList := make([]map[string]interface{}, 0, 1)
233+
dMap := make(map[string]interface{}, 0)
234+
policyInfoList := make([]map[string]interface{}, 0, 1)
235+
policyInfoMap := make(map[string]interface{}, 0)
236+
policyInfoMap["catalog"] = catalog
237+
policyInfoMap["database"] = dataBase
238+
policyInfoMap["table"] = table
239+
policyInfoMap["column"] = column
240+
policyInfoList = append(policyInfoList, policyInfoMap)
241+
dMap["policy_info"] = policyInfoList
242+
243+
if item.DataMaskStrategyInfo != nil && item.DataMaskStrategyInfo.StrategyId != nil {
244+
dMap["data_mask_strategy_id"] = item.DataMaskStrategyInfo.StrategyId
245+
}
246+
247+
if item.Type != nil {
248+
dMap["column_type"] = item.Type
249+
}
250+
251+
tmpList = append(tmpList, dMap)
252+
_ = d.Set("data_mask_strategy_policy_set", tmpList)
253+
}
254+
}
255+
}
256+
257+
return nil
258+
}
259+
260+
func resourceTencentCloudDlcAttachDataMaskPolicyDelete(d *schema.ResourceData, meta interface{}) error {
261+
defer tccommon.LogElapsed("resource.tencentcloud_dlc_attach_data_mask_policy.delete")()
262+
defer tccommon.InconsistentCheck(d, meta)()
263+
264+
var (
265+
logId = tccommon.GetLogId(tccommon.ContextNil)
266+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
267+
request = dlcv20210125.NewAttachDataMaskPolicyRequest()
268+
)
269+
270+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
271+
if len(idSplit) != 2 {
272+
return fmt.Errorf("id is broken,%s", d.Id())
273+
}
274+
275+
policyInfoStr := idSplit[0]
276+
secIdSplit := strings.Split(policyInfoStr, tccommon.COMMA_SP)
277+
if len(secIdSplit) != 4 {
278+
return fmt.Errorf("id is broken,%s", d.Id())
279+
}
280+
281+
catalog := secIdSplit[0]
282+
dataBase := secIdSplit[1]
283+
table := secIdSplit[2]
284+
column := secIdSplit[3]
285+
286+
if v, ok := d.GetOk("data_mask_strategy_policy_set"); ok {
287+
for _, item := range v.([]interface{}) {
288+
dataMaskStrategyPolicySetMap := item.(map[string]interface{})
289+
dataMaskStrategyPolicy := dlcv20210125.DataMaskStrategyPolicy{}
290+
if policyInfoMap, ok := helper.ConvertInterfacesHeadToMap(dataMaskStrategyPolicySetMap["policy_info"]); ok {
291+
policy := dlcv20210125.Policy{}
292+
if v, ok := policyInfoMap["database"].(string); ok && v != "" {
293+
policy.Database = &dataBase
294+
}
295+
296+
if v, ok := policyInfoMap["catalog"].(string); ok && v != "" {
297+
policy.Catalog = &catalog
298+
}
299+
300+
if v, ok := policyInfoMap["table"].(string); ok && v != "" {
301+
policy.Table = &table
302+
}
303+
304+
if v, ok := policyInfoMap["operation"].(string); ok && v != "" {
305+
policy.Operation = helper.String(v)
306+
}
307+
308+
if v, ok := policyInfoMap["policy_type"].(string); ok && v != "" {
309+
policy.PolicyType = helper.String(v)
310+
}
311+
312+
if v, ok := policyInfoMap["column"].(string); ok && v != "" {
313+
policy.Column = &column
314+
}
315+
316+
if v, ok := policyInfoMap["mode"].(string); ok && v != "" {
317+
policy.Mode = helper.String(v)
318+
}
319+
320+
dataMaskStrategyPolicy.PolicyInfo = &policy
321+
}
322+
323+
if v, ok := dataMaskStrategyPolicySetMap["data_mask_strategy_id"].(string); ok && v != "" {
324+
dataMaskStrategyPolicy.DataMaskStrategyId = helper.String(v)
325+
}
326+
327+
if v, ok := dataMaskStrategyPolicySetMap["column_type"].(string); ok && v != "" {
328+
dataMaskStrategyPolicy.ColumnType = helper.String(v)
329+
}
330+
331+
request.DataMaskStrategyPolicySet = append(request.DataMaskStrategyPolicySet, &dataMaskStrategyPolicy)
332+
}
333+
}
334+
335+
reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
336+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDlcClient().AttachDataMaskPolicyWithContext(ctx, request)
337+
if e != nil {
338+
return tccommon.RetryError(e)
339+
} else {
340+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
341+
}
342+
343+
return nil
344+
})
345+
346+
if reqErr != nil {
347+
log.Printf("[CRITAL]%s delete dlc attach data mask policy failed, reason:%+v", logId, reqErr)
348+
return reqErr
349+
}
350+
351+
return nil
352+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Provides a resource to create a DLC dlc attach data mask policy
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_dlc_attach_data_mask_policy" "example" {
7+
data_mask_strategy_policy_set {
8+
policy_info {
9+
database = ""
10+
catalog = ""
11+
table = ""
12+
operation = ""
13+
policy_type = ""
14+
column = ""
15+
mode = ""
16+
}
17+
18+
data_mask_strategy_id = ""
19+
column_type = ""
20+
}
21+
}
22+
```

0 commit comments

Comments
 (0)