Skip to content

Commit 112c5d6

Browse files
WeiMengXSWeiMengXS
andauthored
feat: update row filter (#2270)
* feat: update row filter * feat: update row filter * feat: update row filter * feat: doc * feat: doc --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent a45ff99 commit 112c5d6

File tree

6 files changed

+386
-0
lines changed

6 files changed

+386
-0
lines changed

.changelog/2270.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_dlc_update_row_filter_operation
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ Data Lake Compute(DLC)
19211921
tencentcloud_dlc_switch_data_engine_image_operation
19221922
tencentcloud_dlc_upgrade_data_engine_image_operation
19231923
tencentcloud_dlc_user_data_engine_config
1924+
tencentcloud_dlc_update_row_filter_operation
19241925
tencentcloud_dlc_bind_work_groups_to_user_attachment
19251926
19261927
WeData
@@ -3673,6 +3674,7 @@ func Provider() *schema.Provider {
36733674
"tencentcloud_dlc_switch_data_engine_image_operation": resourceTencentCloudDlcSwitchDataEngineImageOperation(),
36743675
"tencentcloud_dlc_upgrade_data_engine_image_operation": resourceTencentCloudDlcUpgradeDataEngineImageOperation(),
36753676
"tencentcloud_dlc_bind_work_groups_to_user_attachment": resourceTencentCloudDlcBindWorkGroupsToUserAttachment(),
3677+
"tencentcloud_dlc_update_row_filter_operation": resourceTencentCloudDlcUpdateRowFilterOperation(),
36763678
"tencentcloud_dlc_user_data_engine_config": resourceTencentCloudDlcUserDataEngineConfig(),
36773679
"tencentcloud_wedata_rule_template": resourceTencentCloudWedataRuleTemplate(),
36783680
"tencentcloud_waf_custom_rule": resourceTencentCloudWafCustomRule(),
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
/*
2+
Provides a resource to create a dlc update_row_filter_operation
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_dlc_update_row_filter_operation" "update_row_filter_operation" {
8+
policy_id = 103704
9+
policy {
10+
database = "test_iac_keep"
11+
catalog = "DataLakeCatalog"
12+
table = "test_table"
13+
operation = "value!=\"0\""
14+
policy_type = "ROWFILTER"
15+
function = ""
16+
view = ""
17+
column = ""
18+
source = "USER"
19+
mode = "SENIOR"
20+
re_auth = false
21+
}
22+
}
23+
```
24+
25+
*/
26+
package tencentcloud
27+
28+
import (
29+
"log"
30+
31+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
32+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
33+
dlc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
34+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
35+
)
36+
37+
func resourceTencentCloudDlcUpdateRowFilterOperation() *schema.Resource {
38+
return &schema.Resource{
39+
Create: resourceTencentCloudDlcUpdateRowFilterOperationCreate,
40+
Read: resourceTencentCloudDlcUpdateRowFilterOperationRead,
41+
Delete: resourceTencentCloudDlcUpdateRowFilterOperationDelete,
42+
Importer: &schema.ResourceImporter{
43+
State: schema.ImportStatePassthrough,
44+
},
45+
Schema: map[string]*schema.Schema{
46+
"policy_id": {
47+
Required: true,
48+
ForceNew: true,
49+
Type: schema.TypeInt,
50+
Description: "The id of the row filtering policy.",
51+
},
52+
53+
"policy": {
54+
Required: true,
55+
ForceNew: true,
56+
Type: schema.TypeList,
57+
MaxItems: 1,
58+
Description: "New filtering strategy.",
59+
Elem: &schema.Resource{
60+
Schema: map[string]*schema.Schema{
61+
"database": {
62+
Type: schema.TypeString,
63+
Required: true,
64+
Description: "Database name that requires authorization, fill in * to represent all databases under the current catalog. When the authorization type is administrator level, only * is allowed to be filled in. when the authorization type is data connection level, only blanks are allowed to be filled in. For other types, the database can be specified arbitrarily.",
65+
},
66+
"catalog": {
67+
Type: schema.TypeString,
68+
Required: true,
69+
Description: "For the data source name that requires authorization, only * (representing all resources at this level) is supported under the administrator level; in the case of data source level and database level authentication, only COSDataCatalog or * is supported; in data table level authentication, it is possible Fill in the user-defined data source. If left blank, it defaults to DataLakeCatalog. note: If a user-defined data source is authenticated, the permissions that dlc can manage are a subset of the accounts provided by the user when accessing the data source.",
70+
},
71+
"table": {
72+
Type: schema.TypeString,
73+
Required: true,
74+
Description: "For the table name that requires authorization, fill in * to represent all tables under the current database. when the authorization type is administrator level, only * is allowed to be filled in. when the authorization type is data connection level or database level, only blanks are allowed to be filled in. For other types, data tables can be specified arbitrarily.",
75+
},
76+
"operation": {
77+
Type: schema.TypeString,
78+
Required: true,
79+
Description: "Authorized permission operations provide different operations for different levels of authentication. administrator permissions: ALL, default is ALL if left blank; data connection level authentication: CREATE; database level authentication: ALL, CREATE, ALTER, DROP; data table permissions: ALL, SELECT, INSERT, ALTER, DELETE, DROP, UPDATE. note: under data table permissions, only SELECT operations are supported when the specified data source is not COSDataCatalog.",
80+
},
81+
"policy_type": {
82+
Type: schema.TypeString,
83+
Optional: true,
84+
Description: "Authorization type, currently supports eight authorization types: ADMIN: Administrator level authentication DATASOURCE: data connection level authentication DATABASE: database level authentication TABLE: Table level authentication VIEW: view level authentication FUNCTION: Function level authentication COLUMN: Column level authentication ENGINE: Data engine authentication. if left blank, the default is administrator level authentication.",
85+
},
86+
"function": {
87+
Type: schema.TypeString,
88+
Optional: true,
89+
Description: "For the function name that requires authorization, fill in * to represent all functions under the current catalog. when the authorization type is administrator level, only * is allowed to be filled in. When the authorization type is data connection level, only blanks are allowed to be filled in. in other types, functions can be specified arbitrarily.",
90+
},
91+
"view": {
92+
Type: schema.TypeString,
93+
Optional: true,
94+
Description: "For views that require authorization, fill in * to represent all views under the current database. When the authorization type is administrator level, only * is allowed to be filled in. when the authorization type is data connection level or database level, only blanks are allowed to be filled in. for other types, the view can be specified arbitrarily.",
95+
},
96+
"column": {
97+
Type: schema.TypeString,
98+
Optional: true,
99+
Description: "For columns that require authorization, fill in * to represent all current columns. When the authorization type is administrator level, only * is allowed.",
100+
},
101+
"data_engine": {
102+
Type: schema.TypeString,
103+
Optional: true,
104+
Description: "Data engines that require authorization, fill in * to represent all current engines. when the authorization type is administrator level, only * is allowed.",
105+
},
106+
"re_auth": {
107+
Type: schema.TypeBool,
108+
Optional: true,
109+
Description: "Whether the user can perform secondary authorization. when it is true, the authorized user can re-authorize the permissions obtained this time to other sub-users. default is false.",
110+
},
111+
"source": {
112+
Type: schema.TypeString,
113+
Optional: true,
114+
Description: "Permission source, please leave it blank. USER: permissions come from the user itself; WORKGROUP: permissions come from the bound workgroup.",
115+
},
116+
"mode": {
117+
Type: schema.TypeString,
118+
Optional: true,
119+
Description: "Authorization mode, please leave this parameter blank. COMMON: normal mode; SENIOR: advanced mode.",
120+
},
121+
"operator": {
122+
Type: schema.TypeString,
123+
Optional: true,
124+
Description: "Operator, do not fill in the input parameters.",
125+
},
126+
"create_time": {
127+
Type: schema.TypeString,
128+
Optional: true,
129+
Description: "The time when the permission was created. Leave the input parameter blank.",
130+
},
131+
"source_id": {
132+
Type: schema.TypeInt,
133+
Optional: true,
134+
Description: "The id of the workgroup to which the permission belongs. this value only exists when the source of the permission is a workgroup. that is, this field has a value only when the value of the Source field is WORKGROUP.",
135+
},
136+
"source_name": {
137+
Type: schema.TypeString,
138+
Optional: true,
139+
Description: "The name of the workgroup to which the permission belongs. this value only exists when the source of the permission is a workgroup. that is, this field has a value only when the value of the source field is WORKGROUP.",
140+
},
141+
"id": {
142+
Type: schema.TypeInt,
143+
Optional: true,
144+
Description: "Policy id.",
145+
},
146+
},
147+
},
148+
},
149+
},
150+
}
151+
}
152+
153+
func resourceTencentCloudDlcUpdateRowFilterOperationCreate(d *schema.ResourceData, meta interface{}) error {
154+
defer logElapsed("resource.tencentcloud_dlc_update_row_filter_operation.create")()
155+
defer inconsistentCheck(d, meta)()
156+
157+
logId := getLogId(contextNil)
158+
159+
var (
160+
request = dlc.NewUpdateRowFilterRequest()
161+
policyId string
162+
)
163+
if v, _ := d.GetOk("policy_id"); v != nil {
164+
policyId = helper.IntToStr(v.(int))
165+
request.PolicyId = helper.IntInt64(v.(int))
166+
}
167+
168+
if dMap, ok := helper.InterfacesHeadMap(d, "policy"); ok {
169+
policy := dlc.Policy{}
170+
if v, ok := dMap["database"]; ok {
171+
policy.Database = helper.String(v.(string))
172+
}
173+
if v, ok := dMap["catalog"]; ok {
174+
policy.Catalog = helper.String(v.(string))
175+
}
176+
if v, ok := dMap["table"]; ok {
177+
policy.Table = helper.String(v.(string))
178+
}
179+
if v, ok := dMap["operation"]; ok {
180+
policy.Operation = helper.String(v.(string))
181+
}
182+
if v, ok := dMap["policy_type"]; ok {
183+
policy.PolicyType = helper.String(v.(string))
184+
}
185+
if v, ok := dMap["function"]; ok {
186+
policy.Function = helper.String(v.(string))
187+
}
188+
if v, ok := dMap["view"]; ok {
189+
policy.View = helper.String(v.(string))
190+
}
191+
if v, ok := dMap["column"]; ok {
192+
policy.Column = helper.String(v.(string))
193+
}
194+
if v, ok := dMap["data_engine"]; ok {
195+
policy.DataEngine = helper.String(v.(string))
196+
}
197+
if v, ok := dMap["re_auth"]; ok {
198+
policy.ReAuth = helper.Bool(v.(bool))
199+
}
200+
if v, ok := dMap["source"]; ok {
201+
policy.Source = helper.String(v.(string))
202+
}
203+
if v, ok := dMap["mode"]; ok {
204+
policy.Mode = helper.String(v.(string))
205+
}
206+
if v, ok := dMap["operator"]; ok {
207+
policy.Operator = helper.String(v.(string))
208+
}
209+
if v, ok := dMap["create_time"]; ok {
210+
policy.CreateTime = helper.String(v.(string))
211+
}
212+
if v, ok := dMap["source_id"]; ok {
213+
policy.SourceId = helper.IntInt64(v.(int))
214+
}
215+
if v, ok := dMap["source_name"]; ok {
216+
policy.SourceName = helper.String(v.(string))
217+
}
218+
if v, ok := dMap["id"]; ok {
219+
policy.Id = helper.IntInt64(v.(int))
220+
}
221+
request.Policy = &policy
222+
}
223+
224+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
225+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseDlcClient().UpdateRowFilter(request)
226+
if e != nil {
227+
return retryError(e)
228+
} else {
229+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
230+
}
231+
return nil
232+
})
233+
if err != nil {
234+
log.Printf("[CRITAL]%s operate dlc updateRowFilter failed, reason:%+v", logId, err)
235+
return err
236+
}
237+
238+
d.SetId(policyId)
239+
240+
return resourceTencentCloudDlcUpdateRowFilterOperationRead(d, meta)
241+
}
242+
243+
func resourceTencentCloudDlcUpdateRowFilterOperationRead(d *schema.ResourceData, meta interface{}) error {
244+
defer logElapsed("resource.tencentcloud_dlc_update_row_filter_operation.read")()
245+
defer inconsistentCheck(d, meta)()
246+
247+
return nil
248+
}
249+
250+
func resourceTencentCloudDlcUpdateRowFilterOperationDelete(d *schema.ResourceData, meta interface{}) error {
251+
defer logElapsed("resource.tencentcloud_dlc_update_row_filter_operation.delete")()
252+
defer inconsistentCheck(d, meta)()
253+
254+
return nil
255+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDlcUpdateRowFilterOperationResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccDlcUpdateRowFilterOperation,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "id"),
20+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy_id", "103704"),
21+
resource.TestCheckResourceAttrSet("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.#"),
22+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.database", "test_iac_keep"),
23+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.catalog", "DataLakeCatalog"),
24+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.table", "test_table"),
25+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.operation", "value!=\"0\""),
26+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.policy_type", "ROWFILTER"),
27+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.re_auth", "false"),
28+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.source", "USER"),
29+
resource.TestCheckResourceAttr("tencentcloud_dlc_update_row_filter_operation.update_row_filter_operation", "policy.0.mode", "SENIOR")),
30+
},
31+
},
32+
})
33+
}
34+
35+
const testAccDlcUpdateRowFilterOperation = `
36+
37+
resource "tencentcloud_dlc_update_row_filter_operation" "update_row_filter_operation" {
38+
policy_id = 103704
39+
policy {
40+
database = "test_iac_keep"
41+
catalog = "DataLakeCatalog"
42+
table = "test_table"
43+
operation = "value!=\"0\""
44+
policy_type = "ROWFILTER"
45+
function = ""
46+
view = ""
47+
column = ""
48+
source = "USER"
49+
mode = "SENIOR"
50+
re_auth = false
51+
}
52+
}
53+
54+
`

0 commit comments

Comments
 (0)