|
| 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 DataSourceTencentCloudWedataDownstreamTasks() *schema.Resource { |
| 15 | + return &schema.Resource{ |
| 16 | + Read: dataSourceTencentCloudWedataDownstreamTasksRead, |
| 17 | + Schema: map[string]*schema.Schema{ |
| 18 | + "project_id": { |
| 19 | + Type: schema.TypeString, |
| 20 | + Required: true, |
| 21 | + Description: "Project ID.", |
| 22 | + }, |
| 23 | + |
| 24 | + "task_id": { |
| 25 | + Type: schema.TypeString, |
| 26 | + Required: true, |
| 27 | + Description: "Task ID.", |
| 28 | + }, |
| 29 | + |
| 30 | + "data": { |
| 31 | + Type: schema.TypeList, |
| 32 | + Computed: true, |
| 33 | + Description: "Describes the downstream dependency details.", |
| 34 | + Elem: &schema.Resource{ |
| 35 | + Schema: map[string]*schema.Schema{ |
| 36 | + "task_id": { |
| 37 | + Type: schema.TypeString, |
| 38 | + Required: true, |
| 39 | + Description: "Task ID.", |
| 40 | + }, |
| 41 | + "task_name": { |
| 42 | + Type: schema.TypeString, |
| 43 | + Required: true, |
| 44 | + Description: "Task name.", |
| 45 | + }, |
| 46 | + "workflow_id": { |
| 47 | + Type: schema.TypeString, |
| 48 | + Required: true, |
| 49 | + Description: "Workflow id.", |
| 50 | + }, |
| 51 | + "workflow_name": { |
| 52 | + Type: schema.TypeString, |
| 53 | + Required: true, |
| 54 | + Description: "Workflow name.", |
| 55 | + }, |
| 56 | + "project_id": { |
| 57 | + Type: schema.TypeString, |
| 58 | + Required: true, |
| 59 | + Description: "Project ID.", |
| 60 | + }, |
| 61 | + "status": { |
| 62 | + Type: schema.TypeString, |
| 63 | + Required: true, |
| 64 | + Description: "Task Status:\n\n* N: New\n\n* Y: Scheduling\n\n* F: Offline\n\n* O: Paused\n\n* T: Offlining (in the process of being taken offline)\n\nI* NVALID: Invalid.", |
| 65 | + }, |
| 66 | + "task_type_id": { |
| 67 | + Type: schema.TypeInt, |
| 68 | + Required: true, |
| 69 | + Description: "Task type id.", |
| 70 | + }, |
| 71 | + "task_type_desc": { |
| 72 | + Type: schema.TypeString, |
| 73 | + Required: true, |
| 74 | + Description: "Task type description.\n-20: universal data synchronization.\n - 25: ETLTaskType\n - 26: ETLTaskType\n - 30: python\n - 31: pyspark\n - 34: hivesql\n - 35: shell\n - 36: sparksql\n - 21: jdbcsql\n - 32: dlc\n - 33: ImpalaTaskType\n - 40: CDWTaskType\n - 41: kettle\n - 42: TCHouse-X\n - 43: TCHouse-X SQL\n - 46: dlcsparkTaskType\n - 47: TiOneMachineLearningTaskType\n - 48: Trino\n - 50: DLCPyspark\n - 23: TencentDistributedSQL\n - 39: spark\n - 92: MRTaskType\n - 38: ShellScript\n - 70: HiveSQLScrip\n-130: branch.\n-131: merge.\n-132: Notebook \n-133: SSH node.\n - 134: StarRocks\n - 137: For-each\n-10000: custom business common.", |
| 75 | + }, |
| 76 | + "schedule_desc": { |
| 77 | + Type: schema.TypeString, |
| 78 | + Required: true, |
| 79 | + Description: "Specifies scheduling plan display description information.", |
| 80 | + }, |
| 81 | + "start_time": { |
| 82 | + Type: schema.TypeString, |
| 83 | + Required: true, |
| 84 | + Description: "Task start time.", |
| 85 | + }, |
| 86 | + "end_time": { |
| 87 | + Type: schema.TypeString, |
| 88 | + Required: true, |
| 89 | + Description: "Task end time.", |
| 90 | + }, |
| 91 | + "delay_time": { |
| 92 | + Type: schema.TypeInt, |
| 93 | + Required: true, |
| 94 | + Description: "Delay time.", |
| 95 | + }, |
| 96 | + "cycle_type": { |
| 97 | + Type: schema.TypeString, |
| 98 | + Required: true, |
| 99 | + Description: "Cycle Type, Default: D\nSupported types:\n* O: One-time\n\n* Y: Yearly\n\n* M: Monthly\n\n* W: Weekly\n\n* D: Daily\n\n* H: Hourly\n\n* I: Minute\n\n* C: Crontab expression type.", |
| 100 | + }, |
| 101 | + "owner_uin": { |
| 102 | + Type: schema.TypeString, |
| 103 | + Required: true, |
| 104 | + Description: "Owner ID.", |
| 105 | + }, |
| 106 | + "task_action": { |
| 107 | + Type: schema.TypeString, |
| 108 | + Required: true, |
| 109 | + Description: "Elastic cycle configuration.", |
| 110 | + }, |
| 111 | + "init_strategy": { |
| 112 | + Type: schema.TypeString, |
| 113 | + Required: true, |
| 114 | + Description: "Initialization strategy for scheduling.", |
| 115 | + }, |
| 116 | + "crontab_expression": { |
| 117 | + Type: schema.TypeString, |
| 118 | + Required: true, |
| 119 | + Description: "crontab expression.", |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + }, |
| 124 | + |
| 125 | + "result_output_file": { |
| 126 | + Type: schema.TypeString, |
| 127 | + Optional: true, |
| 128 | + Description: "Used to save results.", |
| 129 | + }, |
| 130 | + }, |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +func dataSourceTencentCloudWedataDownstreamTasksRead(d *schema.ResourceData, meta interface{}) error { |
| 135 | + defer tccommon.LogElapsed("data_source.tencentcloud_wedata_downstream_tasks.read")() |
| 136 | + defer tccommon.InconsistentCheck(d, meta)() |
| 137 | + |
| 138 | + logId := tccommon.GetLogId(nil) |
| 139 | + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) |
| 140 | + |
| 141 | + service := WedataService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} |
| 142 | + |
| 143 | + paramMap := make(map[string]interface{}) |
| 144 | + if v, ok := d.GetOk("project_id"); ok { |
| 145 | + paramMap["ProjectId"] = helper.String(v.(string)) |
| 146 | + } |
| 147 | + |
| 148 | + if v, ok := d.GetOk("task_id"); ok { |
| 149 | + paramMap["TaskId"] = helper.String(v.(string)) |
| 150 | + } |
| 151 | + |
| 152 | + var respData []*wedatav20250806.TaskDependDto |
| 153 | + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { |
| 154 | + result, e := service.DescribeWedataDownstreamTasksByFilter(ctx, paramMap) |
| 155 | + if e != nil { |
| 156 | + return tccommon.RetryError(e) |
| 157 | + } |
| 158 | + respData = result |
| 159 | + return nil |
| 160 | + }) |
| 161 | + if err != nil { |
| 162 | + return err |
| 163 | + } |
| 164 | + |
| 165 | + ids := make([]string, 0, len(respData)) |
| 166 | + itemsList := make([]map[string]interface{}, 0, len(respData)) |
| 167 | + |
| 168 | + for _, items := range respData { |
| 169 | + itemsMap := map[string]interface{}{} |
| 170 | + |
| 171 | + if items.TaskId != nil { |
| 172 | + itemsMap["task_id"] = items.TaskId |
| 173 | + ids = append(ids, *items.TaskId) |
| 174 | + } |
| 175 | + |
| 176 | + if items.TaskName != nil { |
| 177 | + itemsMap["task_name"] = items.TaskName |
| 178 | + } |
| 179 | + |
| 180 | + if items.WorkflowId != nil { |
| 181 | + itemsMap["workflow_id"] = items.WorkflowId |
| 182 | + } |
| 183 | + |
| 184 | + if items.WorkflowName != nil { |
| 185 | + itemsMap["workflow_name"] = items.WorkflowName |
| 186 | + } |
| 187 | + |
| 188 | + if items.ProjectId != nil { |
| 189 | + itemsMap["project_id"] = items.ProjectId |
| 190 | + } |
| 191 | + |
| 192 | + if items.Status != nil { |
| 193 | + itemsMap["status"] = items.Status |
| 194 | + } |
| 195 | + |
| 196 | + if items.TaskTypeId != nil { |
| 197 | + itemsMap["task_type_id"] = items.TaskTypeId |
| 198 | + } |
| 199 | + |
| 200 | + if items.TaskTypeDesc != nil { |
| 201 | + itemsMap["task_type_desc"] = items.TaskTypeDesc |
| 202 | + } |
| 203 | + |
| 204 | + if items.ScheduleDesc != nil { |
| 205 | + itemsMap["schedule_desc"] = items.ScheduleDesc |
| 206 | + } |
| 207 | + |
| 208 | + if items.StartTime != nil { |
| 209 | + itemsMap["start_time"] = items.StartTime |
| 210 | + } |
| 211 | + |
| 212 | + if items.EndTime != nil { |
| 213 | + itemsMap["end_time"] = items.EndTime |
| 214 | + } |
| 215 | + |
| 216 | + if items.DelayTime != nil { |
| 217 | + itemsMap["delay_time"] = items.DelayTime |
| 218 | + } |
| 219 | + |
| 220 | + if items.CycleType != nil { |
| 221 | + itemsMap["cycle_type"] = items.CycleType |
| 222 | + } |
| 223 | + |
| 224 | + if items.OwnerUin != nil { |
| 225 | + itemsMap["owner_uin"] = items.OwnerUin |
| 226 | + } |
| 227 | + |
| 228 | + if items.TaskAction != nil { |
| 229 | + itemsMap["task_action"] = items.TaskAction |
| 230 | + } |
| 231 | + |
| 232 | + if items.InitStrategy != nil { |
| 233 | + itemsMap["init_strategy"] = items.InitStrategy |
| 234 | + } |
| 235 | + |
| 236 | + if items.CrontabExpression != nil { |
| 237 | + itemsMap["crontab_expression"] = items.CrontabExpression |
| 238 | + } |
| 239 | + |
| 240 | + itemsList = append(itemsList, itemsMap) |
| 241 | + } |
| 242 | + |
| 243 | + _ = d.Set("data", itemsList) |
| 244 | + |
| 245 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 246 | + |
| 247 | + output, ok := d.GetOk("result_output_file") |
| 248 | + if ok && output.(string) != "" { |
| 249 | + if e := tccommon.WriteToFile(output.(string), itemsList); e != nil { |
| 250 | + return e |
| 251 | + } |
| 252 | + } |
| 253 | + |
| 254 | + return nil |
| 255 | +} |
0 commit comments