|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of dlc check_data_engine_config_pairs_validity |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_dlc_check_data_engine_config_pairs_validity" "check_data_engine_config_pairs_validity" { |
| 8 | + child_image_version_id = "d3ftghd4-9a7e-4f64-a3f4-f38507c69742" |
| 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 dataSourceTencentCloudDlcCheckDataEngineConfigPairsValidity() *schema.Resource { |
| 24 | + return &schema.Resource{ |
| 25 | + Read: dataSourceTencentCloudDlcCheckDataEngineConfigPairsValidityRead, |
| 26 | + Schema: map[string]*schema.Schema{ |
| 27 | + "child_image_version_id": { |
| 28 | + Optional: true, |
| 29 | + Type: schema.TypeString, |
| 30 | + Description: "Engine Image version id.", |
| 31 | + }, |
| 32 | + |
| 33 | + "data_engine_config_pairs": { |
| 34 | + Optional: true, |
| 35 | + Type: schema.TypeList, |
| 36 | + Description: "User-defined parameters.", |
| 37 | + Elem: &schema.Resource{ |
| 38 | + Schema: map[string]*schema.Schema{ |
| 39 | + "config_item": { |
| 40 | + Type: schema.TypeString, |
| 41 | + Required: true, |
| 42 | + Description: "Configuration item.", |
| 43 | + }, |
| 44 | + "config_value": { |
| 45 | + Type: schema.TypeString, |
| 46 | + Required: true, |
| 47 | + Description: "Configuration value.", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + |
| 53 | + "image_version_id": { |
| 54 | + Optional: true, |
| 55 | + Type: schema.TypeString, |
| 56 | + Description: "Engine major version id. If a minor version id exists, you only need to pass in the minor version id. If it does not exist, the latest minor version id under the current major version will be obtained.", |
| 57 | + }, |
| 58 | + |
| 59 | + "is_available": { |
| 60 | + Computed: true, |
| 61 | + Type: schema.TypeBool, |
| 62 | + Description: "Parameter validity: true: valid, false: at least one invalid parameter exists.", |
| 63 | + }, |
| 64 | + |
| 65 | + "unavailable_config": { |
| 66 | + Computed: true, |
| 67 | + Type: schema.TypeSet, |
| 68 | + Elem: &schema.Schema{ |
| 69 | + Type: schema.TypeString, |
| 70 | + }, |
| 71 | + Description: "Invalid parameter set.", |
| 72 | + }, |
| 73 | + |
| 74 | + "result_output_file": { |
| 75 | + Type: schema.TypeString, |
| 76 | + Optional: true, |
| 77 | + Description: "Used to save results.", |
| 78 | + }, |
| 79 | + }, |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +func dataSourceTencentCloudDlcCheckDataEngineConfigPairsValidityRead(d *schema.ResourceData, meta interface{}) error { |
| 84 | + defer logElapsed("data_source.tencentcloud_dlc_check_data_engine_config_pairs_validity.read")() |
| 85 | + defer inconsistentCheck(d, meta)() |
| 86 | + |
| 87 | + logId := getLogId(contextNil) |
| 88 | + |
| 89 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 90 | + var childImageVersionId string |
| 91 | + paramMap := make(map[string]interface{}) |
| 92 | + if v, ok := d.GetOk("child_image_version_id"); ok { |
| 93 | + childImageVersionId = v.(string) |
| 94 | + paramMap["ChildImageVersionId"] = helper.String(v.(string)) |
| 95 | + } |
| 96 | + |
| 97 | + if v, ok := d.GetOk("data_engine_config_pairs"); ok { |
| 98 | + dataEngineConfigPairsSet := v.([]interface{}) |
| 99 | + tmpSet := make([]*dlc.DataEngineConfigPair, 0, len(dataEngineConfigPairsSet)) |
| 100 | + |
| 101 | + for _, item := range dataEngineConfigPairsSet { |
| 102 | + dataEngineConfigPair := dlc.DataEngineConfigPair{} |
| 103 | + dataEngineConfigPairMap := item.(map[string]interface{}) |
| 104 | + |
| 105 | + if v, ok := dataEngineConfigPairMap["config_item"]; ok { |
| 106 | + dataEngineConfigPair.ConfigItem = helper.String(v.(string)) |
| 107 | + } |
| 108 | + if v, ok := dataEngineConfigPairMap["config_value"]; ok { |
| 109 | + dataEngineConfigPair.ConfigValue = helper.String(v.(string)) |
| 110 | + } |
| 111 | + tmpSet = append(tmpSet, &dataEngineConfigPair) |
| 112 | + } |
| 113 | + paramMap["data_engine_config_pairs"] = tmpSet |
| 114 | + } |
| 115 | + |
| 116 | + if v, ok := d.GetOk("image_version_id"); ok { |
| 117 | + paramMap["ImageVersionId"] = helper.String(v.(string)) |
| 118 | + } |
| 119 | + |
| 120 | + service := DlcService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 121 | + var data *dlc.CheckDataEngineConfigPairsValidityResponseParams |
| 122 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 123 | + result, e := service.DescribeDlcCheckDataEngineConfigPairsValidityByFilter(ctx, paramMap) |
| 124 | + if e != nil { |
| 125 | + return retryError(e) |
| 126 | + } |
| 127 | + data = result |
| 128 | + return nil |
| 129 | + }) |
| 130 | + if err != nil { |
| 131 | + return err |
| 132 | + } |
| 133 | + result := make(map[string]interface{}) |
| 134 | + if data.IsAvailable != nil { |
| 135 | + _ = d.Set("is_available", data.IsAvailable) |
| 136 | + result["is_available"] = data.IsAvailable |
| 137 | + } |
| 138 | + |
| 139 | + if data.UnavailableConfig != nil { |
| 140 | + _ = d.Set("unavailable_config", data.UnavailableConfig) |
| 141 | + result["unavailable_config"] = data.UnavailableConfig |
| 142 | + } |
| 143 | + |
| 144 | + d.SetId(childImageVersionId) |
| 145 | + output, ok := d.GetOk("result_output_file") |
| 146 | + if ok && output.(string) != "" { |
| 147 | + if e := writeToFile(output.(string), result); e != nil { |
| 148 | + return e |
| 149 | + } |
| 150 | + } |
| 151 | + return nil |
| 152 | +} |
0 commit comments