From eb6602fca7bd53c0819e10b2b459fb93c09bb389 Mon Sep 17 00:00:00 2001 From: arunma Date: Mon, 9 Oct 2023 18:01:44 +0800 Subject: [PATCH] feat: support eb plateform_event_template --- ...a_source_tc_eb_plateform_event_template.go | 89 +++++++++++++++++++ ...rce_tc_eb_plateform_event_template_test.go | 36 ++++++++ tencentcloud/provider.go | 2 + tencentcloud/service_tencentcloud_eb.go | 35 ++++++++ .../eb_plateform_event_template.html.markdown | 35 ++++++++ website/tencentcloud.erb | 3 + 6 files changed, 200 insertions(+) create mode 100644 tencentcloud/data_source_tc_eb_plateform_event_template.go create mode 100644 tencentcloud/data_source_tc_eb_plateform_event_template_test.go create mode 100644 website/docs/d/eb_plateform_event_template.html.markdown diff --git a/tencentcloud/data_source_tc_eb_plateform_event_template.go b/tencentcloud/data_source_tc_eb_plateform_event_template.go new file mode 100644 index 0000000000..38d25dad7f --- /dev/null +++ b/tencentcloud/data_source_tc_eb_plateform_event_template.go @@ -0,0 +1,89 @@ +/* +Use this data source to query detailed information of eb plateform_event_template + +Example Usage + +```hcl +data "tencentcloud_eb_plateform_event_template" "plateform_event_template" { + event_type = "eb_platform_test:TEST:ALL" +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudEbPlateformEventTemplate() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudEbPlateformEventTemplateRead, + Schema: map[string]*schema.Schema{ + "event_type": { + Required: true, + Type: schema.TypeString, + Description: "Platform product event type.", + }, + + "event_template": { + Computed: true, + Type: schema.TypeString, + Description: "Platform product event template.", + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudEbPlateformEventTemplateRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_eb_plateform_event_template.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + var eventType string + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("event_type"); ok { + eventType = v.(string) + paramMap["EventType"] = helper.String(v.(string)) + } + + service := EbService{client: meta.(*TencentCloudClient).apiV3Conn} + + var eventTemplate *string + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeEbPlateformEventTemplateByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + eventTemplate = result + return nil + }) + if err != nil { + return err + } + + if eventTemplate != nil { + _ = d.Set("event_template", eventTemplate) + } + + d.SetId(helper.DataResourceIdsHash([]string{eventType, *eventTemplate})) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), eventTemplate); e != nil { + return e + } + } + return nil +} diff --git a/tencentcloud/data_source_tc_eb_plateform_event_template_test.go b/tencentcloud/data_source_tc_eb_plateform_event_template_test.go new file mode 100644 index 0000000000..16af0edaa7 --- /dev/null +++ b/tencentcloud/data_source_tc_eb_plateform_event_template_test.go @@ -0,0 +1,36 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -test.run TestAccTencentCloudEbPlateformEventTemplateDataSource_basic -v +func TestAccTencentCloudEbPlateformEventTemplateDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccStepSetRegion(t, "ap-chongqing") + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccEbPlateformEventTemplateDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_eb_plateform_event_template.plateform_event_template"), + resource.TestCheckResourceAttrSet("data.tencentcloud_eb_plateform_event_template.plateform_event_template", "event_template"), + ), + }, + }, + }) +} + +const testAccEbPlateformEventTemplateDataSource = ` + +data "tencentcloud_eb_plateform_event_template" "plateform_event_template" { + event_type = "eb_platform_test:TEST:ALL" +} + +` diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 5d8dee3518..81c50de2a9 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1659,6 +1659,7 @@ EventBridge(EB) tencentcloud_eb_platform_event_names tencentcloud_eb_platform_event_patterns tencentcloud_eb_platform_products + tencentcloud_eb_plateform_event_template Resource tencentcloud_eb_event_transform @@ -2381,6 +2382,7 @@ func Provider() *schema.Provider { "tencentcloud_eb_platform_event_names": dataSourceTencentCloudEbPlatformEventNames(), "tencentcloud_eb_platform_event_patterns": dataSourceTencentCloudEbPlatformEventPatterns(), "tencentcloud_eb_platform_products": dataSourceTencentCloudEbPlatformProducts(), + "tencentcloud_eb_plateform_event_template": dataSourceTencentCloudEbPlateformEventTemplate(), "tencentcloud_wedata_rule_templates": dataSourceTencentCloudWedataRuleTemplates(), "tencentcloud_private_dns_records": dataSourceTencentCloudPrivateDnsRecords(), "tencentcloud_waf_ciphers": dataSourceTencentCloudWafCiphers(), diff --git a/tencentcloud/service_tencentcloud_eb.go b/tencentcloud/service_tencentcloud_eb.go index 6e7c25adb7..d8f3649f71 100644 --- a/tencentcloud/service_tencentcloud_eb.go +++ b/tencentcloud/service_tencentcloud_eb.go @@ -628,3 +628,38 @@ func (me *EbService) DescribeEbPlatformProductsByFilter(ctx context.Context, par return } + +func (me *EbService) DescribeEbPlateformEventTemplateByFilter(ctx context.Context, param map[string]interface{}) (plateformEventTemplate *string, errRet error) { + var ( + logId = getLogId(ctx) + request = eb.NewGetPlatformEventTemplateRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + for k, v := range param { + if k == "EventType" { + request.EventType = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseEbClient().GetPlatformEventTemplate(request) + if err != nil { + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if response.Response.EventTemplate == nil { + return + } + + plateformEventTemplate = response.Response.EventTemplate + + return +} diff --git a/website/docs/d/eb_plateform_event_template.html.markdown b/website/docs/d/eb_plateform_event_template.html.markdown new file mode 100644 index 0000000000..e33603b95c --- /dev/null +++ b/website/docs/d/eb_plateform_event_template.html.markdown @@ -0,0 +1,35 @@ +--- +subcategory: "EventBridge(EB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_eb_plateform_event_template" +sidebar_current: "docs-tencentcloud-datasource-eb_plateform_event_template" +description: |- + Use this data source to query detailed information of eb plateform_event_template +--- + +# tencentcloud_eb_plateform_event_template + +Use this data source to query detailed information of eb plateform_event_template + +## Example Usage + +```hcl +data "tencentcloud_eb_plateform_event_template" "plateform_event_template" { + event_type = "eb_platform_test:TEST:ALL" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `event_type` - (Required, String) Platform product event type. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `event_template` - Platform product event template. + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 7f404f8db7..75786c7068 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -1856,6 +1856,9 @@
  • tencentcloud_eb_event_rules
  • +
  • + tencentcloud_eb_plateform_event_template +
  • tencentcloud_eb_platform_event_names