Skip to content

Commit

Permalink
feat: support eb plateform_event_template
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmkn committed Oct 9, 2023
1 parent 042e9b7 commit eb6602f
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tencentcloud/data_source_tc_eb_plateform_event_template.go
Original file line number Diff line number Diff line change
@@ -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
}
36 changes: 36 additions & 0 deletions tencentcloud/data_source_tc_eb_plateform_event_template_test.go
Original file line number Diff line number Diff line change
@@ -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"
}
`
2 changes: 2 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
35 changes: 35 additions & 0 deletions tencentcloud/service_tencentcloud_eb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
35 changes: 35 additions & 0 deletions website/docs/d/eb_plateform_event_template.html.markdown
Original file line number Diff line number Diff line change
@@ -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.


3 changes: 3 additions & 0 deletions website/tencentcloud.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,9 @@
<li>
<a href="/docs/providers/tencentcloud/d/eb_event_rules.html">tencentcloud_eb_event_rules</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/d/eb_plateform_event_template.html">tencentcloud_eb_plateform_event_template</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/d/eb_platform_event_names.html">tencentcloud_eb_platform_event_names</a>
</li>
Expand Down

0 comments on commit eb6602f

Please sign in to comment.