|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of dnspod domain_log_list |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_dnspod_domain_log_list" "domain_log_list" { |
| 8 | + domain = "iac-tf.cloud" |
| 9 | + domain_id = 123 |
| 10 | +} |
| 11 | +``` |
| 12 | +*/ |
| 13 | +package tencentcloud |
| 14 | + |
| 15 | +import ( |
| 16 | + "context" |
| 17 | + |
| 18 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 19 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 20 | + |
| 21 | + // dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323" |
| 22 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 23 | +) |
| 24 | + |
| 25 | +func dataSourceTencentCloudDnspodDomainLogList() *schema.Resource { |
| 26 | + return &schema.Resource{ |
| 27 | + Read: dataSourceTencentCloudDnspodDomainLogListRead, |
| 28 | + Schema: map[string]*schema.Schema{ |
| 29 | + "domain": { |
| 30 | + Required: true, |
| 31 | + Type: schema.TypeString, |
| 32 | + Description: "Domain.", |
| 33 | + }, |
| 34 | + |
| 35 | + "domain_id": { |
| 36 | + Optional: true, |
| 37 | + Type: schema.TypeInt, |
| 38 | + Description: "Domain ID. The parameter DomainId has a higher priority than the parameter Domain. If the parameter DomainId is passed, the parameter Domain will be ignored. You can find all Domains and DomainIds through the DescribeDomainList interface.", |
| 39 | + }, |
| 40 | + |
| 41 | + "log_list": { |
| 42 | + Computed: true, |
| 43 | + Type: schema.TypeSet, |
| 44 | + Elem: &schema.Schema{ |
| 45 | + Type: schema.TypeString, |
| 46 | + }, |
| 47 | + Description: "Domain Operation Log List. Note: This field may return null, indicating that no valid value can be obtained.", |
| 48 | + }, |
| 49 | + |
| 50 | + "result_output_file": { |
| 51 | + Type: schema.TypeString, |
| 52 | + Optional: true, |
| 53 | + Description: "Used to save results.", |
| 54 | + }, |
| 55 | + }, |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func dataSourceTencentCloudDnspodDomainLogListRead(d *schema.ResourceData, meta interface{}) error { |
| 60 | + defer logElapsed("data_source.tencentcloud_dnspod_domain_log_list.read")() |
| 61 | + defer inconsistentCheck(d, meta)() |
| 62 | + |
| 63 | + logId := getLogId(contextNil) |
| 64 | + |
| 65 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 66 | + var domain string |
| 67 | + |
| 68 | + paramMap := make(map[string]interface{}) |
| 69 | + if v, ok := d.GetOk("domain"); ok { |
| 70 | + domain = v.(string) |
| 71 | + paramMap["Domain"] = helper.String(v.(string)) |
| 72 | + } |
| 73 | + |
| 74 | + if v, ok := d.GetOkExists("domain_id"); ok { |
| 75 | + paramMap["DomainId"] = helper.IntUint64(v.(int)) |
| 76 | + } |
| 77 | + |
| 78 | + service := DnspodService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 79 | + |
| 80 | + var logList []*string |
| 81 | + |
| 82 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 83 | + result, e := service.DescribeDnspodDomainLogListByFilter(ctx, paramMap) |
| 84 | + if e != nil { |
| 85 | + return retryError(e) |
| 86 | + } |
| 87 | + logList = result |
| 88 | + return nil |
| 89 | + }) |
| 90 | + if err != nil { |
| 91 | + return err |
| 92 | + } |
| 93 | + |
| 94 | + // ids := make([]string, 0, len(logList)) |
| 95 | + if logList != nil { |
| 96 | + _ = d.Set("log_list", logList) |
| 97 | + } |
| 98 | + |
| 99 | + d.SetId(helper.DataResourceIdHash(domain)) |
| 100 | + output, ok := d.GetOk("result_output_file") |
| 101 | + if ok && output.(string) != "" { |
| 102 | + if e := writeToFile(output.(string), logList); e != nil { |
| 103 | + return e |
| 104 | + } |
| 105 | + } |
| 106 | + return nil |
| 107 | +} |
0 commit comments