-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathdata_source_tc_cam_sub_accounts.go
177 lines (152 loc) · 5.02 KB
/
data_source_tc_cam_sub_accounts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Code generated by iacg; DO NOT EDIT.
package cam
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
camv20190116 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudCamSubAccounts() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudCamSubAccountsRead,
Schema: map[string]*schema.Schema{
"filter_sub_account_uin": {
Type: schema.TypeSet,
Required: true,
Description: "List of sub-user UINs. Up to 50 UINs are supported.",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"sub_accounts": {
Type: schema.TypeList,
Computed: true,
Description: "Sub-user list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uin": {
Type: schema.TypeInt,
Required: true,
Description: "Sub-user ID.",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Sub-user name.",
},
"uid": {
Type: schema.TypeInt,
Required: true,
Description: "Sub-user UID. UID is the unique identifier of a user who is a message recipient, while UIN is a unique identifier of a user.",
},
"remark": {
Type: schema.TypeString,
Required: true,
Description: "Sub-user remarks.",
},
"create_time": {
Type: schema.TypeString,
Required: true,
Description: "Creation time\nNote: this field may return null, indicating that no valid values can be obtained.",
},
"user_type": {
Type: schema.TypeInt,
Required: true,
Description: "User type (1: root account; 2: sub-user; 3: WeCom sub-user; 4: collaborator; 5: message recipient).",
},
"last_login_ip": {
Type: schema.TypeString,
Required: true,
Description: "Last login IP.",
},
"last_login_time": {
Type: schema.TypeString,
Required: true,
Description: "Last login time.",
},
},
},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}
func dataSourceTencentCloudCamSubAccountsRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_cam_sub_accounts.read")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(nil)
ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
service := CamService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("filter_sub_account_uin"); ok {
filterSubAccountUinList := []*uint64{}
filterSubAccountUinSet := v.(*schema.Set).List()
for i := range filterSubAccountUinSet {
filterSubAccountUin := filterSubAccountUinSet[i].(int)
filterSubAccountUinList = append(filterSubAccountUinList, helper.IntUint64(filterSubAccountUin))
}
paramMap["FilterSubAccountUin"] = filterSubAccountUinList
}
var respData []*camv20190116.SubAccountUser
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCamSubAccountsByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
respData = result
return nil
})
if err != nil {
return err
}
var ids []string
subAccountsList := make([]map[string]interface{}, 0, len(respData))
if respData != nil {
for _, subAccounts := range respData {
subAccountsMap := map[string]interface{}{}
var uin uint64
if subAccounts.Uin != nil {
subAccountsMap["uin"] = subAccounts.Uin
uin = *subAccounts.Uin
}
if subAccounts.Name != nil {
subAccountsMap["name"] = subAccounts.Name
}
if subAccounts.Uid != nil {
subAccountsMap["uid"] = subAccounts.Uid
}
if subAccounts.Remark != nil {
subAccountsMap["remark"] = subAccounts.Remark
}
if subAccounts.CreateTime != nil {
subAccountsMap["create_time"] = subAccounts.CreateTime
}
if subAccounts.UserType != nil {
subAccountsMap["user_type"] = subAccounts.UserType
}
if subAccounts.LastLoginIp != nil {
subAccountsMap["last_login_ip"] = subAccounts.LastLoginIp
}
if subAccounts.LastLoginTime != nil {
subAccountsMap["last_login_time"] = subAccounts.LastLoginTime
}
ids = append(ids, helper.UInt64ToStr(uin))
subAccountsList = append(subAccountsList, subAccountsMap)
}
_ = d.Set("sub_accounts", subAccountsList)
}
d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), subAccountsList); e != nil {
return e
}
}
return nil
}