Skip to content

Commit 5acb838

Browse files
WeiMengXSWeiMengXS
and
WeiMengXS
authored
Feat/dlc (#2244)
* feat: datasource * feat: datasource * feat: datasource * feat: changelog --------- Co-authored-by: WeiMengXS <[email protected]>
1 parent 188a4e4 commit 5acb838

13 files changed

+1694
-0
lines changed

.changelog/2244.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-data-source
2+
tencentcloud_dlc_describe_user_type
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_dlc_describe_user_info
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_dlc_describe_user_roles
11+
```

tencentcloud/data_source_tc_dlc_describe_user_info.go

Lines changed: 898 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDlcDescribeUserInfoDataSource_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: testAccDlcDescribeUserInfoDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_dlc_describe_user_info.describe_user_info"),
20+
resource.TestCheckResourceAttr("data.tencentcloud_dlc_describe_user_info.describe_user_info", "user_id", "100032772113"),
21+
resource.TestCheckResourceAttr("data.tencentcloud_dlc_describe_user_info.describe_user_info", "type", "Group"),
22+
resource.TestCheckResourceAttr("data.tencentcloud_dlc_describe_user_info.describe_user_info", "sort_by", "create-time"),
23+
resource.TestCheckResourceAttr("data.tencentcloud_dlc_describe_user_info.describe_user_info", "sorting", "desc"),
24+
),
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccDlcDescribeUserInfoDataSource = `
31+
32+
data "tencentcloud_dlc_describe_user_info" "describe_user_info" {
33+
user_id = "100032772113"
34+
type = "Group"
35+
sort_by = "create-time"
36+
sorting = "desc"
37+
}
38+
`
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/*
2+
Use this data source to query detailed information of dlc describe_user_roles
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_dlc_describe_user_roles" "describe_user_roles" {
8+
fuzzy = "1"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
dlc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudDlcDescribeUserRoles() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudDlcDescribeUserRolesRead,
26+
Schema: map[string]*schema.Schema{
27+
"fuzzy": {
28+
Optional: true,
29+
Type: schema.TypeString,
30+
Description: "List according to ARN blur.",
31+
},
32+
33+
"sort_by": {
34+
Optional: true,
35+
Type: schema.TypeString,
36+
Description: "The return results are sorted according to this field.",
37+
},
38+
39+
"sorting": {
40+
Optional: true,
41+
Type: schema.TypeString,
42+
Description: "Positive or inverted, such as DESC.",
43+
},
44+
45+
"user_roles": {
46+
Computed: true,
47+
Type: schema.TypeList,
48+
Description: "User role information.",
49+
Elem: &schema.Resource{
50+
Schema: map[string]*schema.Schema{
51+
"role_id": {
52+
Type: schema.TypeInt,
53+
Computed: true,
54+
Description: "Character ID.",
55+
},
56+
"app_id": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
Description: "User app ID.",
60+
},
61+
"uin": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
Description: "User ID.",
65+
},
66+
"arn": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "Role Permissions.",
70+
},
71+
"modify_time": {
72+
Type: schema.TypeInt,
73+
Computed: true,
74+
Description: "Recently modify the time stamp.",
75+
},
76+
"desc": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
Description: "Character description information.",
80+
},
81+
"role_name": {
82+
Type: schema.TypeString,
83+
Computed: true,
84+
Description: "Role NameNote: This field may return NULL, indicating that the valid value cannot be obtained.",
85+
},
86+
"creator": {
87+
Type: schema.TypeString,
88+
Computed: true,
89+
Description: "Creator UinNote: This field may return NULL, indicating that the valid value cannot be obtained.",
90+
},
91+
"cos_permission_list": {
92+
Type: schema.TypeList,
93+
Computed: true,
94+
Description: "COS authorization path listNote: This field may return NULL, indicating that the valid value cannot be obtained.",
95+
Elem: &schema.Resource{
96+
Schema: map[string]*schema.Schema{
97+
"cos_path": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Description: "COS pathNote: This field may return NULL, indicating that the valid value cannot be obtained.",
101+
},
102+
"permissions": {
103+
Type: schema.TypeSet,
104+
Elem: &schema.Schema{
105+
Type: schema.TypeString,
106+
},
107+
Computed: true,
108+
Description: "Permissions [Read, WRITE]Note: This field may return NULL, indicating that the valid value cannot be obtained.",
109+
},
110+
},
111+
},
112+
},
113+
"permission_json": {
114+
Type: schema.TypeString,
115+
Computed: true,
116+
Description: "CAM strategy jsonNote: This field may return NULL, indicating that the valid value cannot be obtained.",
117+
},
118+
},
119+
},
120+
},
121+
122+
"result_output_file": {
123+
Type: schema.TypeString,
124+
Optional: true,
125+
Description: "Used to save results.",
126+
},
127+
},
128+
}
129+
}
130+
131+
func dataSourceTencentCloudDlcDescribeUserRolesRead(d *schema.ResourceData, meta interface{}) error {
132+
defer logElapsed("data_source.tencentcloud_dlc_describe_user_roles.read")()
133+
defer inconsistentCheck(d, meta)()
134+
135+
logId := getLogId(contextNil)
136+
137+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
138+
139+
paramMap := make(map[string]interface{})
140+
if v, ok := d.GetOk("fuzzy"); ok {
141+
paramMap["Fuzzy"] = helper.String(v.(string))
142+
}
143+
144+
if v, ok := d.GetOk("sort_by"); ok {
145+
paramMap["SortBy"] = helper.String(v.(string))
146+
}
147+
148+
if v, ok := d.GetOk("sorting"); ok {
149+
paramMap["Sorting"] = helper.String(v.(string))
150+
}
151+
152+
service := DlcService{client: meta.(*TencentCloudClient).apiV3Conn}
153+
154+
var userRoles []*dlc.UserRole
155+
156+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
157+
result, e := service.DescribeDlcDescribeUserRolesByFilter(ctx, paramMap)
158+
if e != nil {
159+
return retryError(e)
160+
}
161+
userRoles = result
162+
return nil
163+
})
164+
if err != nil {
165+
return err
166+
}
167+
168+
ids := make([]string, 0, len(userRoles))
169+
tmpList := make([]map[string]interface{}, 0, len(userRoles))
170+
171+
if userRoles != nil {
172+
for _, userRole := range userRoles {
173+
userRoleMap := map[string]interface{}{}
174+
175+
if userRole.RoleId != nil {
176+
userRoleMap["role_id"] = userRole.RoleId
177+
}
178+
179+
if userRole.AppId != nil {
180+
userRoleMap["app_id"] = userRole.AppId
181+
}
182+
183+
if userRole.Uin != nil {
184+
userRoleMap["uin"] = userRole.Uin
185+
}
186+
187+
if userRole.Arn != nil {
188+
userRoleMap["arn"] = userRole.Arn
189+
}
190+
191+
if userRole.ModifyTime != nil {
192+
userRoleMap["modify_time"] = userRole.ModifyTime
193+
}
194+
195+
if userRole.Desc != nil {
196+
userRoleMap["desc"] = userRole.Desc
197+
}
198+
199+
if userRole.RoleName != nil {
200+
userRoleMap["role_name"] = userRole.RoleName
201+
}
202+
203+
if userRole.Creator != nil {
204+
userRoleMap["creator"] = userRole.Creator
205+
}
206+
207+
if userRole.CosPermissionList != nil {
208+
var cosPermissionListList []interface{}
209+
for _, cosPermissionList := range userRole.CosPermissionList {
210+
cosPermissionListMap := map[string]interface{}{}
211+
212+
if cosPermissionList.CosPath != nil {
213+
cosPermissionListMap["cos_path"] = cosPermissionList.CosPath
214+
}
215+
216+
if cosPermissionList.Permissions != nil {
217+
cosPermissionListMap["permissions"] = cosPermissionList.Permissions
218+
}
219+
220+
cosPermissionListList = append(cosPermissionListList, cosPermissionListMap)
221+
}
222+
223+
userRoleMap["cos_permission_list"] = cosPermissionListList
224+
}
225+
226+
if userRole.PermissionJson != nil {
227+
userRoleMap["permission_json"] = userRole.PermissionJson
228+
}
229+
230+
ids = append(ids, helper.Int64ToStr(*userRole.RoleId))
231+
tmpList = append(tmpList, userRoleMap)
232+
}
233+
234+
_ = d.Set("user_roles", tmpList)
235+
}
236+
237+
d.SetId(helper.DataResourceIdsHash(ids))
238+
output, ok := d.GetOk("result_output_file")
239+
if ok && output.(string) != "" {
240+
if e := writeToFile(output.(string), tmpList); e != nil {
241+
return e
242+
}
243+
}
244+
return nil
245+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDlcDescribeUserRolesDataSource_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: testAccDlcDescribeUserRolesDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_dlc_describe_user_roles.describe_user_roles"),
20+
resource.TestCheckResourceAttr("data.tencentcloud_dlc_describe_user_roles.describe_user_roles", "fuzzy", "1")),
21+
},
22+
},
23+
})
24+
}
25+
26+
const testAccDlcDescribeUserRolesDataSource = `
27+
28+
data "tencentcloud_dlc_describe_user_roles" "describe_user_roles" {
29+
fuzzy = "1"
30+
}
31+
32+
`

0 commit comments

Comments
 (0)