|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of organization members |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_organization_members" "members" {} |
| 8 | +``` |
| 9 | +*/ |
| 10 | +package tencentcloud |
| 11 | + |
| 12 | +import ( |
| 13 | + "context" |
| 14 | + |
| 15 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 16 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 17 | + organization "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331" |
| 18 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 19 | +) |
| 20 | + |
| 21 | +func dataSourceTencentCloudOrganizationMembers() *schema.Resource { |
| 22 | + return &schema.Resource{ |
| 23 | + Read: dataSourceTencentCloudOrganizationMembersRead, |
| 24 | + Schema: map[string]*schema.Schema{ |
| 25 | + "lang": { |
| 26 | + Optional: true, |
| 27 | + Type: schema.TypeString, |
| 28 | + Description: "Valid values: `en` (Tencent Cloud International); `zh` (Tencent Cloud).", |
| 29 | + }, |
| 30 | + |
| 31 | + "search_key": { |
| 32 | + Optional: true, |
| 33 | + Type: schema.TypeString, |
| 34 | + Description: "Search by member name or ID.", |
| 35 | + }, |
| 36 | + |
| 37 | + "auth_name": { |
| 38 | + Optional: true, |
| 39 | + Type: schema.TypeString, |
| 40 | + Description: "Entity name.", |
| 41 | + }, |
| 42 | + |
| 43 | + "product": { |
| 44 | + Optional: true, |
| 45 | + Type: schema.TypeString, |
| 46 | + Description: "Abbreviation of the trusted service, which is required during querying the trusted service admin.", |
| 47 | + }, |
| 48 | + |
| 49 | + "items": { |
| 50 | + Computed: true, |
| 51 | + Type: schema.TypeList, |
| 52 | + Description: "Member list.", |
| 53 | + Elem: &schema.Resource{ |
| 54 | + Schema: map[string]*schema.Schema{ |
| 55 | + "member_uin": { |
| 56 | + Type: schema.TypeInt, |
| 57 | + Computed: true, |
| 58 | + Description: "Member UINNote: This field may return null, indicating that no valid values can be obtained.", |
| 59 | + }, |
| 60 | + "name": { |
| 61 | + Type: schema.TypeString, |
| 62 | + Computed: true, |
| 63 | + Description: "Member nameNote: This field may return null, indicating that no valid values can be obtained.", |
| 64 | + }, |
| 65 | + "member_type": { |
| 66 | + Type: schema.TypeString, |
| 67 | + Computed: true, |
| 68 | + Description: "Member type. Valid values: `Invite` (invited); `Create` (created).Note: This field may return null, indicating that no valid values can be obtained.", |
| 69 | + }, |
| 70 | + "org_policy_type": { |
| 71 | + Type: schema.TypeString, |
| 72 | + Computed: true, |
| 73 | + Description: "Relationship policy typeNote: This field may return null, indicating that no valid values can be obtained.", |
| 74 | + }, |
| 75 | + "org_policy_name": { |
| 76 | + Type: schema.TypeString, |
| 77 | + Computed: true, |
| 78 | + Description: "Relationship policy nameNote: This field may return null, indicating that no valid values can be obtained.", |
| 79 | + }, |
| 80 | + "org_permission": { |
| 81 | + Type: schema.TypeList, |
| 82 | + Computed: true, |
| 83 | + Description: "Relationship policy permissionNote: This field may return null, indicating that no valid values can be obtained.", |
| 84 | + Elem: &schema.Resource{ |
| 85 | + Schema: map[string]*schema.Schema{ |
| 86 | + "id": { |
| 87 | + Type: schema.TypeInt, |
| 88 | + Computed: true, |
| 89 | + Description: "Permission ID.", |
| 90 | + }, |
| 91 | + "name": { |
| 92 | + Type: schema.TypeString, |
| 93 | + Computed: true, |
| 94 | + Description: "Permission name.", |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + "node_id": { |
| 100 | + Type: schema.TypeInt, |
| 101 | + Computed: true, |
| 102 | + Description: "Node IDNote: This field may return null, indicating that no valid values can be obtained.", |
| 103 | + }, |
| 104 | + "node_name": { |
| 105 | + Type: schema.TypeString, |
| 106 | + Computed: true, |
| 107 | + Description: "Node nameNote: This field may return null, indicating that no valid values can be obtained.", |
| 108 | + }, |
| 109 | + "remark": { |
| 110 | + Type: schema.TypeString, |
| 111 | + Computed: true, |
| 112 | + Description: "RemarksNote: This field may return null, indicating that no valid values can be obtained.", |
| 113 | + }, |
| 114 | + "create_time": { |
| 115 | + Type: schema.TypeString, |
| 116 | + Computed: true, |
| 117 | + Description: "Creation timeNote: This field may return null, indicating that no valid values can be obtained.", |
| 118 | + }, |
| 119 | + "update_time": { |
| 120 | + Type: schema.TypeString, |
| 121 | + Computed: true, |
| 122 | + Description: "Update timeNote: This field may return null, indicating that no valid values can be obtained.", |
| 123 | + }, |
| 124 | + "is_allow_quit": { |
| 125 | + Type: schema.TypeString, |
| 126 | + Computed: true, |
| 127 | + Description: "Whether the member is allowed to leave. Valid values: `Allow`, `Denied`.Note: This field may return null, indicating that no valid values can be obtained.", |
| 128 | + }, |
| 129 | + "pay_uin": { |
| 130 | + Type: schema.TypeString, |
| 131 | + Computed: true, |
| 132 | + Description: "Payer UINNote: This field may return null, indicating that no valid values can be obtained.", |
| 133 | + }, |
| 134 | + "pay_name": { |
| 135 | + Type: schema.TypeString, |
| 136 | + Computed: true, |
| 137 | + Description: "Payer nameNote: This field may return null, indicating that no valid values can be obtained.", |
| 138 | + }, |
| 139 | + "org_identity": { |
| 140 | + Type: schema.TypeList, |
| 141 | + Computed: true, |
| 142 | + Description: "Management identityNote: This field may return null, indicating that no valid values can be obtained.", |
| 143 | + Elem: &schema.Resource{ |
| 144 | + Schema: map[string]*schema.Schema{ |
| 145 | + "identity_id": { |
| 146 | + Type: schema.TypeInt, |
| 147 | + Computed: true, |
| 148 | + Description: "Identity ID.Note: This field may return null, indicating that no valid values can be obtained.", |
| 149 | + }, |
| 150 | + "identity_alias_name": { |
| 151 | + Type: schema.TypeString, |
| 152 | + Computed: true, |
| 153 | + Description: "Identity name.Note: This field may return null, indicating that no valid values can be obtained.", |
| 154 | + }, |
| 155 | + }, |
| 156 | + }, |
| 157 | + }, |
| 158 | + "bind_status": { |
| 159 | + Type: schema.TypeString, |
| 160 | + Computed: true, |
| 161 | + Description: "Security information binding status. Valid values: `Unbound`, `Valid`, `Success`, `Failed`.Note: This field may return null, indicating that no valid values can be obtained.", |
| 162 | + }, |
| 163 | + "permission_status": { |
| 164 | + Type: schema.TypeString, |
| 165 | + Computed: true, |
| 166 | + Description: "Member permission status. Valid values: `Confirmed`, `UnConfirmed`.Note: This field may return null, indicating that no valid values can be obtained.", |
| 167 | + }, |
| 168 | + }, |
| 169 | + }, |
| 170 | + }, |
| 171 | + |
| 172 | + "result_output_file": { |
| 173 | + Type: schema.TypeString, |
| 174 | + Optional: true, |
| 175 | + Description: "Used to save results.", |
| 176 | + }, |
| 177 | + }, |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +func dataSourceTencentCloudOrganizationMembersRead(d *schema.ResourceData, meta interface{}) error { |
| 182 | + defer logElapsed("data_source.tencentcloud_organization_members.read")() |
| 183 | + defer inconsistentCheck(d, meta)() |
| 184 | + |
| 185 | + logId := getLogId(contextNil) |
| 186 | + |
| 187 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 188 | + |
| 189 | + paramMap := make(map[string]interface{}) |
| 190 | + if v, ok := d.GetOk("lang"); ok { |
| 191 | + paramMap["Lang"] = helper.String(v.(string)) |
| 192 | + } |
| 193 | + |
| 194 | + if v, ok := d.GetOk("search_key"); ok { |
| 195 | + paramMap["SearchKey"] = helper.String(v.(string)) |
| 196 | + } |
| 197 | + |
| 198 | + if v, ok := d.GetOk("auth_name"); ok { |
| 199 | + paramMap["AuthName"] = helper.String(v.(string)) |
| 200 | + } |
| 201 | + |
| 202 | + if v, ok := d.GetOk("product"); ok { |
| 203 | + paramMap["Product"] = helper.String(v.(string)) |
| 204 | + } |
| 205 | + |
| 206 | + service := OrganizationService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 207 | + |
| 208 | + var items []*organization.OrgMember |
| 209 | + |
| 210 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 211 | + result, e := service.DescribeOrganizationMembersByFilter(ctx, paramMap) |
| 212 | + if e != nil { |
| 213 | + return retryError(e) |
| 214 | + } |
| 215 | + items = result |
| 216 | + return nil |
| 217 | + }) |
| 218 | + if err != nil { |
| 219 | + return err |
| 220 | + } |
| 221 | + |
| 222 | + ids := make([]string, 0, len(items)) |
| 223 | + tmpList := make([]map[string]interface{}, 0, len(items)) |
| 224 | + |
| 225 | + if items != nil { |
| 226 | + for _, orgMember := range items { |
| 227 | + orgMemberMap := map[string]interface{}{} |
| 228 | + |
| 229 | + if orgMember.MemberUin != nil { |
| 230 | + orgMemberMap["member_uin"] = orgMember.MemberUin |
| 231 | + } |
| 232 | + |
| 233 | + if orgMember.Name != nil { |
| 234 | + orgMemberMap["name"] = orgMember.Name |
| 235 | + } |
| 236 | + |
| 237 | + if orgMember.MemberType != nil { |
| 238 | + orgMemberMap["member_type"] = orgMember.MemberType |
| 239 | + } |
| 240 | + |
| 241 | + if orgMember.OrgPolicyType != nil { |
| 242 | + orgMemberMap["org_policy_type"] = orgMember.OrgPolicyType |
| 243 | + } |
| 244 | + |
| 245 | + if orgMember.OrgPolicyName != nil { |
| 246 | + orgMemberMap["org_policy_name"] = orgMember.OrgPolicyName |
| 247 | + } |
| 248 | + |
| 249 | + if orgMember.OrgPermission != nil { |
| 250 | + orgPermissionList := []interface{}{} |
| 251 | + for _, orgPermission := range orgMember.OrgPermission { |
| 252 | + orgPermissionMap := map[string]interface{}{} |
| 253 | + |
| 254 | + if orgPermission.Id != nil { |
| 255 | + orgPermissionMap["id"] = orgPermission.Id |
| 256 | + } |
| 257 | + |
| 258 | + if orgPermission.Name != nil { |
| 259 | + orgPermissionMap["name"] = orgPermission.Name |
| 260 | + } |
| 261 | + |
| 262 | + orgPermissionList = append(orgPermissionList, orgPermissionMap) |
| 263 | + } |
| 264 | + |
| 265 | + orgMemberMap["org_permission"] = orgPermissionList |
| 266 | + } |
| 267 | + |
| 268 | + if orgMember.NodeId != nil { |
| 269 | + orgMemberMap["node_id"] = orgMember.NodeId |
| 270 | + } |
| 271 | + |
| 272 | + if orgMember.NodeName != nil { |
| 273 | + orgMemberMap["node_name"] = orgMember.NodeName |
| 274 | + } |
| 275 | + |
| 276 | + if orgMember.Remark != nil { |
| 277 | + orgMemberMap["remark"] = orgMember.Remark |
| 278 | + } |
| 279 | + |
| 280 | + if orgMember.CreateTime != nil { |
| 281 | + orgMemberMap["create_time"] = orgMember.CreateTime |
| 282 | + } |
| 283 | + |
| 284 | + if orgMember.UpdateTime != nil { |
| 285 | + orgMemberMap["update_time"] = orgMember.UpdateTime |
| 286 | + } |
| 287 | + |
| 288 | + if orgMember.IsAllowQuit != nil { |
| 289 | + orgMemberMap["is_allow_quit"] = orgMember.IsAllowQuit |
| 290 | + } |
| 291 | + |
| 292 | + if orgMember.PayUin != nil { |
| 293 | + orgMemberMap["pay_uin"] = orgMember.PayUin |
| 294 | + } |
| 295 | + |
| 296 | + if orgMember.PayName != nil { |
| 297 | + orgMemberMap["pay_name"] = orgMember.PayName |
| 298 | + } |
| 299 | + |
| 300 | + if orgMember.OrgIdentity != nil { |
| 301 | + orgIdentityList := []interface{}{} |
| 302 | + for _, orgIdentity := range orgMember.OrgIdentity { |
| 303 | + orgIdentityMap := map[string]interface{}{} |
| 304 | + |
| 305 | + if orgIdentity.IdentityId != nil { |
| 306 | + orgIdentityMap["identity_id"] = orgIdentity.IdentityId |
| 307 | + } |
| 308 | + |
| 309 | + if orgIdentity.IdentityAliasName != nil { |
| 310 | + orgIdentityMap["identity_alias_name"] = orgIdentity.IdentityAliasName |
| 311 | + } |
| 312 | + |
| 313 | + orgIdentityList = append(orgIdentityList, orgIdentityMap) |
| 314 | + } |
| 315 | + |
| 316 | + orgMemberMap["org_identity"] = orgIdentityList |
| 317 | + } |
| 318 | + |
| 319 | + if orgMember.BindStatus != nil { |
| 320 | + orgMemberMap["bind_status"] = orgMember.BindStatus |
| 321 | + } |
| 322 | + |
| 323 | + if orgMember.PermissionStatus != nil { |
| 324 | + orgMemberMap["permission_status"] = orgMember.PermissionStatus |
| 325 | + } |
| 326 | + |
| 327 | + ids = append(ids, *orgMember.Name) |
| 328 | + tmpList = append(tmpList, orgMemberMap) |
| 329 | + } |
| 330 | + |
| 331 | + _ = d.Set("items", tmpList) |
| 332 | + } |
| 333 | + |
| 334 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 335 | + output, ok := d.GetOk("result_output_file") |
| 336 | + if ok && output.(string) != "" { |
| 337 | + if e := writeToFile(output.(string), tmpList); e != nil { |
| 338 | + return e |
| 339 | + } |
| 340 | + } |
| 341 | + return nil |
| 342 | +} |
0 commit comments