|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of eb plateform_event_template |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_eb_plateform_event_template" "plateform_event_template" { |
| 8 | + event_type = "eb_platform_test:TEST:ALL" |
| 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 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 20 | +) |
| 21 | + |
| 22 | +func dataSourceTencentCloudEbPlateformEventTemplate() *schema.Resource { |
| 23 | + return &schema.Resource{ |
| 24 | + Read: dataSourceTencentCloudEbPlateformEventTemplateRead, |
| 25 | + Schema: map[string]*schema.Schema{ |
| 26 | + "event_type": { |
| 27 | + Required: true, |
| 28 | + Type: schema.TypeString, |
| 29 | + Description: "Platform product event type.", |
| 30 | + }, |
| 31 | + |
| 32 | + "event_template": { |
| 33 | + Computed: true, |
| 34 | + Type: schema.TypeString, |
| 35 | + Description: "Platform product event template.", |
| 36 | + }, |
| 37 | + |
| 38 | + "result_output_file": { |
| 39 | + Type: schema.TypeString, |
| 40 | + Optional: true, |
| 41 | + Description: "Used to save results.", |
| 42 | + }, |
| 43 | + }, |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func dataSourceTencentCloudEbPlateformEventTemplateRead(d *schema.ResourceData, meta interface{}) error { |
| 48 | + defer logElapsed("data_source.tencentcloud_eb_plateform_event_template.read")() |
| 49 | + defer inconsistentCheck(d, meta)() |
| 50 | + |
| 51 | + logId := getLogId(contextNil) |
| 52 | + |
| 53 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 54 | + |
| 55 | + var eventType string |
| 56 | + paramMap := make(map[string]interface{}) |
| 57 | + if v, ok := d.GetOk("event_type"); ok { |
| 58 | + eventType = v.(string) |
| 59 | + paramMap["EventType"] = helper.String(v.(string)) |
| 60 | + } |
| 61 | + |
| 62 | + service := EbService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 63 | + |
| 64 | + var eventTemplate *string |
| 65 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 66 | + result, e := service.DescribeEbPlateformEventTemplateByFilter(ctx, paramMap) |
| 67 | + if e != nil { |
| 68 | + return retryError(e) |
| 69 | + } |
| 70 | + eventTemplate = result |
| 71 | + return nil |
| 72 | + }) |
| 73 | + if err != nil { |
| 74 | + return err |
| 75 | + } |
| 76 | + |
| 77 | + if eventTemplate != nil { |
| 78 | + _ = d.Set("event_template", eventTemplate) |
| 79 | + } |
| 80 | + |
| 81 | + d.SetId(helper.DataResourceIdsHash([]string{eventType, *eventTemplate})) |
| 82 | + output, ok := d.GetOk("result_output_file") |
| 83 | + if ok && output.(string) != "" { |
| 84 | + if e := writeToFile(output.(string), eventTemplate); e != nil { |
| 85 | + return e |
| 86 | + } |
| 87 | + } |
| 88 | + return nil |
| 89 | +} |
0 commit comments