|
| 1 | +package wedata |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + wedatav20250806 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata/v20250806" |
| 9 | + |
| 10 | + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" |
| 11 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 12 | +) |
| 13 | + |
| 14 | +func DataSourceTencentCloudWedataDataSources() *schema.Resource { |
| 15 | + return &schema.Resource{ |
| 16 | + Read: dataSourceTencentCloudWedataDataSourcesRead, |
| 17 | + Schema: map[string]*schema.Schema{ |
| 18 | + "project_id": { |
| 19 | + Type: schema.TypeString, |
| 20 | + Required: true, |
| 21 | + Description: "Project ID.", |
| 22 | + }, |
| 23 | + |
| 24 | + "name": { |
| 25 | + Type: schema.TypeString, |
| 26 | + Optional: true, |
| 27 | + Description: "Data source name.", |
| 28 | + }, |
| 29 | + |
| 30 | + "display_name": { |
| 31 | + Type: schema.TypeString, |
| 32 | + Optional: true, |
| 33 | + Description: "Data source display name.", |
| 34 | + }, |
| 35 | + |
| 36 | + "type": { |
| 37 | + Type: schema.TypeSet, |
| 38 | + Optional: true, |
| 39 | + Description: "Data source type: enumeration values.\n\n- MYSQL\n- TENCENT_MYSQL\n- POSTGRE\n- ORACLE\n- SQLSERVER\n- FTP\n- HIVE\n- HUDI\n- HDFS\n- ICEBERG\n- KAFKA\n- HBASE\n- SPARK\n- VIRTUAL\n- TBASE\n- DB2\n- DM\n- GAUSSDB\n- GBASE\n- IMPALA\n- ES\n- TENCENT_ES\n- GREENPLUM\n- PHOENIX\n- SAP_HANA\n- SFTP\n- OCEANBASE\n- CLICKHOUSE\n- KUDU\n- VERTICA\n- REDIS\n- COS\n- DLC\n- DORIS\n- CKAFKA\n- S3\n- TDSQL\n- TDSQL_MYSQL\n- MONGODB\n- TENCENT_MONGODB\n- REST_API\n- SuperSQL\n- PRESTO\n- TiDB\n- StarRocks\n- Trino\n- Kyuubi\n- TCHOUSE_X\n- TCHOUSE_P\n- TCHOUSE_C\n- TCHOUSE_D\n- INFLUXDB\n- BIG_QUERY\n- SSH\n- BLOB.", |
| 40 | + Elem: &schema.Schema{ |
| 41 | + Type: schema.TypeString, |
| 42 | + }, |
| 43 | + }, |
| 44 | + |
| 45 | + "creator": { |
| 46 | + Type: schema.TypeString, |
| 47 | + Optional: true, |
| 48 | + Description: "Creator.", |
| 49 | + }, |
| 50 | + |
| 51 | + "items": { |
| 52 | + Type: schema.TypeList, |
| 53 | + Computed: true, |
| 54 | + Description: "Data source list.", |
| 55 | + Elem: &schema.Resource{ |
| 56 | + Schema: map[string]*schema.Schema{ |
| 57 | + "project_id": { |
| 58 | + Type: schema.TypeString, |
| 59 | + Computed: true, |
| 60 | + Description: "Belonging project ID.", |
| 61 | + }, |
| 62 | + "id": { |
| 63 | + Type: schema.TypeInt, |
| 64 | + Computed: true, |
| 65 | + Description: "Data source ID.", |
| 66 | + }, |
| 67 | + "type": { |
| 68 | + Type: schema.TypeString, |
| 69 | + Computed: true, |
| 70 | + Description: "Data source type: enumeration values.", |
| 71 | + }, |
| 72 | + "name": { |
| 73 | + Type: schema.TypeString, |
| 74 | + Computed: true, |
| 75 | + Description: "Data source name.", |
| 76 | + }, |
| 77 | + "display_name": { |
| 78 | + Type: schema.TypeString, |
| 79 | + Computed: true, |
| 80 | + Description: "Data source display name, for visual viewing.", |
| 81 | + }, |
| 82 | + "description": { |
| 83 | + Type: schema.TypeString, |
| 84 | + Computed: true, |
| 85 | + Description: "Data source description information.", |
| 86 | + }, |
| 87 | + "project_name": { |
| 88 | + Type: schema.TypeString, |
| 89 | + Computed: true, |
| 90 | + Description: "Belonging project name.", |
| 91 | + }, |
| 92 | + "create_user": { |
| 93 | + Type: schema.TypeString, |
| 94 | + Computed: true, |
| 95 | + Description: "Data source creator.", |
| 96 | + }, |
| 97 | + "create_time": { |
| 98 | + Type: schema.TypeString, |
| 99 | + Computed: true, |
| 100 | + Description: "Time.", |
| 101 | + }, |
| 102 | + "modify_user": { |
| 103 | + Type: schema.TypeString, |
| 104 | + Computed: true, |
| 105 | + Description: "Modifier.", |
| 106 | + }, |
| 107 | + "modify_time": { |
| 108 | + Type: schema.TypeString, |
| 109 | + Computed: true, |
| 110 | + Description: "Modification time.", |
| 111 | + }, |
| 112 | + "prod_con_properties": { |
| 113 | + Type: schema.TypeString, |
| 114 | + Computed: true, |
| 115 | + Description: "Data source configuration information, stored in JSON KV format, varies by data source type.", |
| 116 | + }, |
| 117 | + "dev_con_properties": { |
| 118 | + Type: schema.TypeString, |
| 119 | + Computed: true, |
| 120 | + Description: "Same as params, contains data for development data source.", |
| 121 | + }, |
| 122 | + "category": { |
| 123 | + Type: schema.TypeString, |
| 124 | + Computed: true, |
| 125 | + Description: "Data source category:\n\n- DB - custom source\n- CLUSTER - system source.", |
| 126 | + }, |
| 127 | + }, |
| 128 | + }, |
| 129 | + }, |
| 130 | + |
| 131 | + "result_output_file": { |
| 132 | + Type: schema.TypeString, |
| 133 | + Optional: true, |
| 134 | + Description: "Used to save results.", |
| 135 | + }, |
| 136 | + }, |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +func dataSourceTencentCloudWedataDataSourcesRead(d *schema.ResourceData, meta interface{}) error { |
| 141 | + defer tccommon.LogElapsed("data_source.tencentcloud_wedata_data_sources.read")() |
| 142 | + defer tccommon.InconsistentCheck(d, meta)() |
| 143 | + |
| 144 | + var ( |
| 145 | + logId = tccommon.GetLogId(nil) |
| 146 | + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) |
| 147 | + service = WedataService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} |
| 148 | + projectId string |
| 149 | + ) |
| 150 | + |
| 151 | + paramMap := make(map[string]interface{}) |
| 152 | + if v, ok := d.GetOk("project_id"); ok { |
| 153 | + paramMap["ProjectId"] = helper.String(v.(string)) |
| 154 | + projectId = v.(string) |
| 155 | + } |
| 156 | + |
| 157 | + if v, ok := d.GetOk("name"); ok { |
| 158 | + paramMap["Name"] = helper.String(v.(string)) |
| 159 | + } |
| 160 | + |
| 161 | + if v, ok := d.GetOk("display_name"); ok { |
| 162 | + paramMap["DisplayName"] = helper.String(v.(string)) |
| 163 | + } |
| 164 | + |
| 165 | + if v, ok := d.GetOk("type"); ok { |
| 166 | + typeList := []*string{} |
| 167 | + typeSet := v.(*schema.Set).List() |
| 168 | + for i := range typeSet { |
| 169 | + tmpType := typeSet[i].(string) |
| 170 | + typeList = append(typeList, helper.String(tmpType)) |
| 171 | + } |
| 172 | + |
| 173 | + paramMap["Type"] = typeList |
| 174 | + } |
| 175 | + |
| 176 | + if v, ok := d.GetOk("creator"); ok { |
| 177 | + paramMap["Creator"] = helper.String(v.(string)) |
| 178 | + } |
| 179 | + |
| 180 | + var respData []*wedatav20250806.DataSource |
| 181 | + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { |
| 182 | + result, e := service.DescribeWedataDataSourcesByFilter(ctx, paramMap) |
| 183 | + if e != nil { |
| 184 | + return tccommon.RetryError(e) |
| 185 | + } |
| 186 | + |
| 187 | + respData = result |
| 188 | + return nil |
| 189 | + }) |
| 190 | + |
| 191 | + if reqErr != nil { |
| 192 | + return reqErr |
| 193 | + } |
| 194 | + |
| 195 | + itemsList := make([]map[string]interface{}, 0, len(respData)) |
| 196 | + for _, items := range respData { |
| 197 | + itemsMap := map[string]interface{}{} |
| 198 | + if items.ProjectId != nil { |
| 199 | + itemsMap["project_id"] = items.ProjectId |
| 200 | + } |
| 201 | + |
| 202 | + if items.Id != nil { |
| 203 | + itemsMap["id"] = items.Id |
| 204 | + } |
| 205 | + |
| 206 | + if items.Type != nil { |
| 207 | + itemsMap["type"] = items.Type |
| 208 | + } |
| 209 | + |
| 210 | + if items.Name != nil { |
| 211 | + itemsMap["name"] = items.Name |
| 212 | + } |
| 213 | + |
| 214 | + if items.DisplayName != nil { |
| 215 | + itemsMap["display_name"] = items.DisplayName |
| 216 | + } |
| 217 | + |
| 218 | + if items.Description != nil { |
| 219 | + itemsMap["description"] = items.Description |
| 220 | + } |
| 221 | + |
| 222 | + if items.ProjectName != nil { |
| 223 | + itemsMap["project_name"] = items.ProjectName |
| 224 | + } |
| 225 | + |
| 226 | + if items.CreateUser != nil { |
| 227 | + itemsMap["create_user"] = items.CreateUser |
| 228 | + } |
| 229 | + |
| 230 | + if items.CreateTime != nil { |
| 231 | + itemsMap["create_time"] = items.CreateTime |
| 232 | + } |
| 233 | + |
| 234 | + if items.ModifyUser != nil { |
| 235 | + itemsMap["modify_user"] = items.ModifyUser |
| 236 | + } |
| 237 | + |
| 238 | + if items.ModifyTime != nil { |
| 239 | + itemsMap["modify_time"] = items.ModifyTime |
| 240 | + } |
| 241 | + |
| 242 | + if items.ProdConProperties != nil { |
| 243 | + itemsMap["prod_con_properties"] = items.ProdConProperties |
| 244 | + } |
| 245 | + |
| 246 | + if items.DevConProperties != nil { |
| 247 | + itemsMap["dev_con_properties"] = items.DevConProperties |
| 248 | + } |
| 249 | + |
| 250 | + if items.Category != nil { |
| 251 | + itemsMap["category"] = items.Category |
| 252 | + } |
| 253 | + |
| 254 | + itemsList = append(itemsList, itemsMap) |
| 255 | + } |
| 256 | + |
| 257 | + _ = d.Set("items", itemsList) |
| 258 | + |
| 259 | + d.SetId(projectId) |
| 260 | + output, ok := d.GetOk("result_output_file") |
| 261 | + if ok && output.(string) != "" { |
| 262 | + if e := tccommon.WriteToFile(output.(string), itemsList); e != nil { |
| 263 | + return e |
| 264 | + } |
| 265 | + } |
| 266 | + |
| 267 | + return nil |
| 268 | +} |
0 commit comments