|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of bi user_project |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_bi_user_project" "user_project" { |
| 8 | + project_id = 123 |
| 9 | + all_page = true |
| 10 | +} |
| 11 | +``` |
| 12 | +*/ |
| 13 | +package tencentcloud |
| 14 | + |
| 15 | +import ( |
| 16 | + "context" |
| 17 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 18 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 19 | + bi "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi/v20220105" |
| 20 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 21 | +) |
| 22 | + |
| 23 | +func dataSourceTencentCloudBiUserProject() *schema.Resource { |
| 24 | + return &schema.Resource{ |
| 25 | + Read: dataSourceTencentCloudBiUserProjectRead, |
| 26 | + Schema: map[string]*schema.Schema{ |
| 27 | + "project_id": { |
| 28 | + Optional: true, |
| 29 | + Type: schema.TypeInt, |
| 30 | + Description: "Project id.", |
| 31 | + }, |
| 32 | + |
| 33 | + "all_page": { |
| 34 | + Optional: true, |
| 35 | + Type: schema.TypeBool, |
| 36 | + Description: "Whether to display all, if true, ignore paging.", |
| 37 | + }, |
| 38 | + |
| 39 | + "list": { |
| 40 | + Type: schema.TypeList, |
| 41 | + Computed: true, |
| 42 | + Description: "Array(Note: This field may return null, indicating that no valid value can be obtained).", |
| 43 | + Elem: &schema.Resource{ |
| 44 | + Schema: map[string]*schema.Schema{ |
| 45 | + "user_id": { |
| 46 | + Type: schema.TypeString, |
| 47 | + Computed: true, |
| 48 | + Description: "User id.", |
| 49 | + }, |
| 50 | + "user_name": { |
| 51 | + Type: schema.TypeString, |
| 52 | + Computed: true, |
| 53 | + Description: "Username.", |
| 54 | + }, |
| 55 | + "corp_id": { |
| 56 | + Type: schema.TypeString, |
| 57 | + Computed: true, |
| 58 | + Description: "Enterprise id(Note: This field may return null, indicating that no valid value can be obtained).", |
| 59 | + }, |
| 60 | + "email": { |
| 61 | + Type: schema.TypeString, |
| 62 | + Computed: true, |
| 63 | + Description: "E-mail(Note: This field may return null, indicating that no valid value can be obtained).", |
| 64 | + }, |
| 65 | + "last_login": { |
| 66 | + Type: schema.TypeString, |
| 67 | + Computed: true, |
| 68 | + Description: "Last login time, public cloud unrelated fields(Note: This field may return null, indicating that no valid value can be obtained).", |
| 69 | + }, |
| 70 | + "status": { |
| 71 | + Type: schema.TypeInt, |
| 72 | + Computed: true, |
| 73 | + Description: "Disabled state(Note: This field may return null, indicating that no valid value can be obtained).", |
| 74 | + }, |
| 75 | + "first_modify": { |
| 76 | + Type: schema.TypeInt, |
| 77 | + Computed: true, |
| 78 | + Description: "First login to change password, public cloud unrelated fields(Note: This field may return null, indicating that no valid value can be obtained).", |
| 79 | + }, |
| 80 | + "phone_number": { |
| 81 | + Type: schema.TypeString, |
| 82 | + Computed: true, |
| 83 | + Description: "Phone number(Note: This field may return null, indicating that no valid value can be obtained).", |
| 84 | + }, |
| 85 | + "area_code": { |
| 86 | + Type: schema.TypeString, |
| 87 | + Computed: true, |
| 88 | + Description: "Mobile area code(Note: This field may return null, indicating that no valid value can be obtained).", |
| 89 | + }, |
| 90 | + "created_user": { |
| 91 | + Type: schema.TypeString, |
| 92 | + Computed: true, |
| 93 | + Description: "Created by(Note: This field may return null, indicating that no valid value can be obtained).", |
| 94 | + }, |
| 95 | + "created_at": { |
| 96 | + Type: schema.TypeString, |
| 97 | + Computed: true, |
| 98 | + Description: "Created at(Note: This field may return null, indicating that no valid value can be obtained).", |
| 99 | + }, |
| 100 | + "updated_user": { |
| 101 | + Type: schema.TypeString, |
| 102 | + Computed: true, |
| 103 | + Description: "Updated by(Note: This field may return null, indicating that no valid value can be obtained).", |
| 104 | + }, |
| 105 | + "updated_at": { |
| 106 | + Type: schema.TypeString, |
| 107 | + Computed: true, |
| 108 | + Description: "Updated at(Note: This field may return null, indicating that no valid value can be obtained).", |
| 109 | + }, |
| 110 | + "global_user_name": { |
| 111 | + Type: schema.TypeString, |
| 112 | + Computed: true, |
| 113 | + Description: "Global role name(Note: This field may return null, indicating that no valid value can be obtained).", |
| 114 | + }, |
| 115 | + "mobile": { |
| 116 | + Type: schema.TypeString, |
| 117 | + Computed: true, |
| 118 | + Description: "Mobile number, public cloud unrelated fields(Note: This field may return null, indicating that no valid value can be obtained).", |
| 119 | + }, |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + |
| 124 | + "result_output_file": { |
| 125 | + Type: schema.TypeString, |
| 126 | + Optional: true, |
| 127 | + Description: "Used to save results.", |
| 128 | + }, |
| 129 | + }, |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +func dataSourceTencentCloudBiUserProjectRead(d *schema.ResourceData, meta interface{}) error { |
| 134 | + defer logElapsed("data_source.tencentcloud_bi_user_project.read")() |
| 135 | + defer inconsistentCheck(d, meta)() |
| 136 | + |
| 137 | + logId := getLogId(contextNil) |
| 138 | + |
| 139 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 140 | + |
| 141 | + paramMap := make(map[string]interface{}) |
| 142 | + if v, _ := d.GetOk("project_id"); v != nil { |
| 143 | + paramMap["ProjectId"] = helper.IntInt64(v.(int)) |
| 144 | + } |
| 145 | + |
| 146 | + if v, _ := d.GetOk("all_page"); v != nil { |
| 147 | + paramMap["AllPage"] = helper.Bool(v.(bool)) |
| 148 | + } |
| 149 | + |
| 150 | + service := BiService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 151 | + |
| 152 | + var data []*bi.UserIdAndUserName |
| 153 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 154 | + result, e := service.DescribeBiUserProjectByFilter(ctx, paramMap) |
| 155 | + if e != nil { |
| 156 | + return retryError(e) |
| 157 | + } |
| 158 | + data = result |
| 159 | + return nil |
| 160 | + }) |
| 161 | + if err != nil { |
| 162 | + return err |
| 163 | + } |
| 164 | + |
| 165 | + ids := make([]string, 0, len(data)) |
| 166 | + dataList := []interface{}{} |
| 167 | + if data != nil { |
| 168 | + for _, list := range data { |
| 169 | + listMap := map[string]interface{}{} |
| 170 | + |
| 171 | + if list.UserId != nil { |
| 172 | + listMap["user_id"] = list.UserId |
| 173 | + } |
| 174 | + |
| 175 | + if list.UserName != nil { |
| 176 | + listMap["user_name"] = list.UserName |
| 177 | + } |
| 178 | + |
| 179 | + if list.CorpId != nil { |
| 180 | + listMap["corp_id"] = list.CorpId |
| 181 | + } |
| 182 | + |
| 183 | + if list.Email != nil { |
| 184 | + listMap["email"] = list.Email |
| 185 | + } |
| 186 | + |
| 187 | + if list.LastLogin != nil { |
| 188 | + listMap["last_login"] = list.LastLogin |
| 189 | + } |
| 190 | + |
| 191 | + if list.Status != nil { |
| 192 | + listMap["status"] = list.Status |
| 193 | + } |
| 194 | + |
| 195 | + if list.FirstModify != nil { |
| 196 | + listMap["first_modify"] = list.FirstModify |
| 197 | + } |
| 198 | + |
| 199 | + if list.PhoneNumber != nil { |
| 200 | + listMap["phone_number"] = list.PhoneNumber |
| 201 | + } |
| 202 | + |
| 203 | + if list.AreaCode != nil { |
| 204 | + listMap["area_code"] = list.AreaCode |
| 205 | + } |
| 206 | + |
| 207 | + if list.CreatedUser != nil { |
| 208 | + listMap["created_user"] = list.CreatedUser |
| 209 | + } |
| 210 | + |
| 211 | + if list.CreatedAt != nil { |
| 212 | + listMap["created_at"] = list.CreatedAt |
| 213 | + } |
| 214 | + |
| 215 | + if list.UpdatedUser != nil { |
| 216 | + listMap["updated_user"] = list.UpdatedUser |
| 217 | + } |
| 218 | + |
| 219 | + if list.UpdatedAt != nil { |
| 220 | + listMap["updated_at"] = list.UpdatedAt |
| 221 | + } |
| 222 | + |
| 223 | + if list.GlobalUserName != nil { |
| 224 | + listMap["global_user_name"] = list.GlobalUserName |
| 225 | + } |
| 226 | + |
| 227 | + if list.Mobile != nil { |
| 228 | + listMap["mobile"] = list.Mobile |
| 229 | + } |
| 230 | + |
| 231 | + dataList = append(dataList, listMap) |
| 232 | + } |
| 233 | + _ = d.Set("list", dataList) |
| 234 | + } |
| 235 | + |
| 236 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 237 | + output, ok := d.GetOk("result_output_file") |
| 238 | + if ok && output.(string) != "" { |
| 239 | + if e := writeToFile(output.(string), dataList); e != nil { |
| 240 | + return e |
| 241 | + } |
| 242 | + } |
| 243 | + return nil |
| 244 | +} |
0 commit comments