|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of dlc describe_updatable_data_engines |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_dlc_describe_updatable_data_engines" "describe_updatable_data_engines" { |
| 8 | + data_engine_config_command = "UpdateSparkSQLLakefsPath" |
| 9 | + } |
| 10 | +``` |
| 11 | +*/ |
| 12 | +package tencentcloud |
| 13 | + |
| 14 | +import ( |
| 15 | + "context" |
| 16 | + |
| 17 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 18 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 19 | + dlc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125" |
| 20 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 21 | +) |
| 22 | + |
| 23 | +func dataSourceTencentCloudDlcDescribeUpdatableDataEngines() *schema.Resource { |
| 24 | + return &schema.Resource{ |
| 25 | + Read: dataSourceTencentCloudDlcDescribeUpdatableDataEnginesRead, |
| 26 | + Schema: map[string]*schema.Schema{ |
| 27 | + "data_engine_config_command": { |
| 28 | + Required: true, |
| 29 | + Type: schema.TypeString, |
| 30 | + Description: "Engine configuration operation command, UpdateSparkSQLLakefsPath updates the managed table path, UpdateSparkSQLResultPath updates the result bucket path.", |
| 31 | + }, |
| 32 | + |
| 33 | + "data_engine_basic_infos": { |
| 34 | + Computed: true, |
| 35 | + Type: schema.TypeList, |
| 36 | + Description: "Engine basic information.", |
| 37 | + Elem: &schema.Resource{ |
| 38 | + Schema: map[string]*schema.Schema{ |
| 39 | + "data_engine_name": { |
| 40 | + Type: schema.TypeString, |
| 41 | + Computed: true, |
| 42 | + Description: "Engine name.", |
| 43 | + }, |
| 44 | + "state": { |
| 45 | + Type: schema.TypeInt, |
| 46 | + Computed: true, |
| 47 | + Description: "Engine state, only support: 0:Init/-1:Failed/-2:Deleted/1:Pause/2:Running/3:ToBeDelete/4:Deleting.", |
| 48 | + }, |
| 49 | + "create_time": { |
| 50 | + Type: schema.TypeInt, |
| 51 | + Computed: true, |
| 52 | + Description: "Create time.", |
| 53 | + }, |
| 54 | + "update_time": { |
| 55 | + Type: schema.TypeInt, |
| 56 | + Computed: true, |
| 57 | + Description: "Update time.", |
| 58 | + }, |
| 59 | + "message": { |
| 60 | + Type: schema.TypeString, |
| 61 | + Computed: true, |
| 62 | + Description: "Returned messages.", |
| 63 | + }, |
| 64 | + "data_engine_id": { |
| 65 | + Type: schema.TypeString, |
| 66 | + Computed: true, |
| 67 | + Description: "Engine unique id.", |
| 68 | + }, |
| 69 | + "data_engine_type": { |
| 70 | + Type: schema.TypeString, |
| 71 | + Computed: true, |
| 72 | + Description: "Engine type, valid values: PrestoSQL/SparkSQL/SparkBatch.", |
| 73 | + }, |
| 74 | + "app_id": { |
| 75 | + Type: schema.TypeInt, |
| 76 | + Computed: true, |
| 77 | + Description: "User unique ID.", |
| 78 | + }, |
| 79 | + "user_uin": { |
| 80 | + Type: schema.TypeString, |
| 81 | + Computed: true, |
| 82 | + Description: "User unique uin.", |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + |
| 88 | + "result_output_file": { |
| 89 | + Type: schema.TypeString, |
| 90 | + Optional: true, |
| 91 | + Description: "Used to save results.", |
| 92 | + }, |
| 93 | + }, |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +func dataSourceTencentCloudDlcDescribeUpdatableDataEnginesRead(d *schema.ResourceData, meta interface{}) error { |
| 98 | + defer logElapsed("data_source.tencentcloud_dlc_describe_updatable_data_engines.read")() |
| 99 | + defer inconsistentCheck(d, meta)() |
| 100 | + |
| 101 | + logId := getLogId(contextNil) |
| 102 | + |
| 103 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 104 | + |
| 105 | + paramMap := make(map[string]interface{}) |
| 106 | + if v, ok := d.GetOk("data_engine_config_command"); ok { |
| 107 | + paramMap["DataEngineConfigCommand"] = helper.String(v.(string)) |
| 108 | + } |
| 109 | + |
| 110 | + service := DlcService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 111 | + |
| 112 | + var dataEngineBasicInfos []*dlc.DataEngineBasicInfo |
| 113 | + |
| 114 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 115 | + result, e := service.DescribeDlcDescribeUpdatableDataEnginesByFilter(ctx, paramMap) |
| 116 | + if e != nil { |
| 117 | + return retryError(e) |
| 118 | + } |
| 119 | + dataEngineBasicInfos = result |
| 120 | + return nil |
| 121 | + }) |
| 122 | + if err != nil { |
| 123 | + return err |
| 124 | + } |
| 125 | + |
| 126 | + ids := make([]string, 0, len(dataEngineBasicInfos)) |
| 127 | + tmpList := make([]map[string]interface{}, 0, len(dataEngineBasicInfos)) |
| 128 | + |
| 129 | + if dataEngineBasicInfos != nil { |
| 130 | + for _, dataEngineBasicInfo := range dataEngineBasicInfos { |
| 131 | + dataEngineBasicInfoMap := map[string]interface{}{} |
| 132 | + |
| 133 | + if dataEngineBasicInfo.DataEngineName != nil { |
| 134 | + dataEngineBasicInfoMap["data_engine_name"] = dataEngineBasicInfo.DataEngineName |
| 135 | + } |
| 136 | + |
| 137 | + if dataEngineBasicInfo.State != nil { |
| 138 | + dataEngineBasicInfoMap["state"] = dataEngineBasicInfo.State |
| 139 | + } |
| 140 | + |
| 141 | + if dataEngineBasicInfo.CreateTime != nil { |
| 142 | + dataEngineBasicInfoMap["create_time"] = dataEngineBasicInfo.CreateTime |
| 143 | + } |
| 144 | + |
| 145 | + if dataEngineBasicInfo.UpdateTime != nil { |
| 146 | + dataEngineBasicInfoMap["update_time"] = dataEngineBasicInfo.UpdateTime |
| 147 | + } |
| 148 | + |
| 149 | + if dataEngineBasicInfo.Message != nil { |
| 150 | + dataEngineBasicInfoMap["message"] = dataEngineBasicInfo.Message |
| 151 | + } |
| 152 | + |
| 153 | + if dataEngineBasicInfo.DataEngineId != nil { |
| 154 | + dataEngineBasicInfoMap["data_engine_id"] = dataEngineBasicInfo.DataEngineId |
| 155 | + } |
| 156 | + |
| 157 | + if dataEngineBasicInfo.DataEngineType != nil { |
| 158 | + dataEngineBasicInfoMap["data_engine_type"] = dataEngineBasicInfo.DataEngineType |
| 159 | + } |
| 160 | + |
| 161 | + if dataEngineBasicInfo.AppId != nil { |
| 162 | + dataEngineBasicInfoMap["app_id"] = dataEngineBasicInfo.AppId |
| 163 | + } |
| 164 | + |
| 165 | + if dataEngineBasicInfo.UserUin != nil { |
| 166 | + dataEngineBasicInfoMap["user_uin"] = dataEngineBasicInfo.UserUin |
| 167 | + } |
| 168 | + |
| 169 | + ids = append(ids, *dataEngineBasicInfo.DataEngineId) |
| 170 | + tmpList = append(tmpList, dataEngineBasicInfoMap) |
| 171 | + } |
| 172 | + |
| 173 | + _ = d.Set("data_engine_basic_infos", tmpList) |
| 174 | + } |
| 175 | + |
| 176 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 177 | + output, ok := d.GetOk("result_output_file") |
| 178 | + if ok && output.(string) != "" { |
| 179 | + if e := writeToFile(output.(string), tmpList); e != nil { |
| 180 | + return e |
| 181 | + } |
| 182 | + } |
| 183 | + return nil |
| 184 | +} |
0 commit comments