Skip to content

Commit

Permalink
feat: support eb platform (#2180)
Browse files Browse the repository at this point in the history
* feat: support eb datasource

* feat: add changelog

* fix: modify test
  • Loading branch information
gitmkn authored Oct 9, 2023
1 parent 9e37bf3 commit 042e9b7
Show file tree
Hide file tree
Showing 18 changed files with 1,564 additions and 396 deletions.
11 changes: 11 additions & 0 deletions .changelog/2180.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:new-data-source
tencentcloud_eb_platform_event_names
```

```release-note:new-data-source
tencentcloud_eb_platform_event_patterns
```

```release-note:new-data-source
tencentcloud_eb_platform_products
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.539
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.715
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.725
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.699
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.514
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628 h1:cnhe9uh
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628/go.mod h1:JxTXEld643DHk5HeQe4xIvuuoxsCmbTjgmE64Mtrdxw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.715 h1:k9wDdxbFD29m2T6B1j5qnpWjVUUVP02vmTZB/m4AVaI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.715/go.mod h1:JoFrUxweQaDBzl5jvphkz8uIxvm+pugI25kY8aUdIAo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760 h1:IKP2LFgJwbnP4IyQQw0k2gdVrd8H8e8X8TL/cIuCHEk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760/go.mod h1:pSQXTeuC6BahiUIfssVqvL1/BoXccLkyD7nJ+tKgygw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.725 h1:r2klzw/HohGsw/piykh3QW5Ft8+7kl0y5KlgNQ8TdAc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.725/go.mod h1:SW2tOlPfjXsCTKU2fYwG5Ydt8w2ZmrK8p3WBgm7sTTE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.699 h1:7lFObucmWErYOh+5/AzpgerUAFoO72XqhXrAzFltTIo=
Expand Down
120 changes: 120 additions & 0 deletions tencentcloud/data_source_tc_eb_platform_event_names.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Use this data source to query detailed information of eb platform_event_names
Example Usage
```hcl
data "tencentcloud_eb_platform_event_names" "platform_event_names" {
product_type = ""
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
eb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb/v20210416"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudEbPlatformEventNames() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudEbPlateformRead,
Schema: map[string]*schema.Schema{
"product_type": {
Required: true,
Type: schema.TypeString,
Description: "Platform product event type.",
},

"event_names": {
Computed: true,
Type: schema.TypeList,
Description: "Platform product list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"event_name": {
Type: schema.TypeString,
Computed: true,
Description: "Event name.Note: This field may return null, indicating that no valid value can be obtained.",
},
"event_type": {
Type: schema.TypeString,
Computed: true,
Description: "Event type.Note: This field may return null, indicating that no valid value can be obtained.",
},
},
},
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudEbPlateformRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_eb_platform_event_names.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)

var productType string
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("product_type"); ok {
productType = v.(string)
paramMap["ProductType"] = helper.String(v.(string))
}

service := EbService{client: meta.(*TencentCloudClient).apiV3Conn}

var eventNames []*eb.PlatformEventDetail
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeEbPlateformByFilter(ctx, paramMap)
if e != nil {
return retryError(e)
}
eventNames = result
return nil
})
if err != nil {
return err
}

ids := make([]string, 0, len(eventNames))
tmpList := make([]map[string]interface{}, 0, len(eventNames))
if eventNames != nil {
for _, platformEventDetail := range eventNames {
platformEventDetailMap := map[string]interface{}{}

if platformEventDetail.EventName != nil {
platformEventDetailMap["event_name"] = platformEventDetail.EventName
}

if platformEventDetail.EventType != nil {
platformEventDetailMap["event_type"] = platformEventDetail.EventType
ids = append(ids, *platformEventDetail.EventType)
}

tmpList = append(tmpList, platformEventDetailMap)
}

_ = d.Set("event_names", tmpList)
}

d.SetId(helper.DataResourceIdsHash(append(ids, productType)))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), tmpList); e != nil {
return e
}
}
return nil
}
35 changes: 35 additions & 0 deletions tencentcloud/data_source_tc_eb_platform_event_names_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -test.run TestAccTencentCloudEbPlatformEventNamesDataSource_basic -v
func TestAccTencentCloudEbPlatformEventNamesDataSource_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: testAccEbPlatformEventNamesDataSource,
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_eb_platform_event_names.platform_event_names"),
),
},
},
})
}

const testAccEbPlatformEventNamesDataSource = `
data "tencentcloud_eb_platform_event_names" "platform_event_names" {
product_type = "eb_platform_test"
}
`
122 changes: 122 additions & 0 deletions tencentcloud/data_source_tc_eb_platform_event_patterns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
Use this data source to query detailed information of eb platform_event_patterns
Example Usage
```hcl
data "tencentcloud_eb_platform_event_patterns" "platform_event_patterns" {
product_type = ""
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
eb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb/v20210416"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudEbPlatformEventPatterns() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudEbPlatformEventPatternsRead,
Schema: map[string]*schema.Schema{
"product_type": {
Required: true,
Type: schema.TypeString,
Description: "Platform product type.",
},

"event_patterns": {
Computed: true,
Type: schema.TypeList,
Description: "Platform product event matching rules.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"event_name": {
Type: schema.TypeString,
Computed: true,
Description: "Platform event name.Note: This field may return null, indicating that no valid value can be obtained.",
},
"event_pattern": {
Type: schema.TypeString,
Computed: true,
Description: "Platform event matching rules.Note: This field may return null, indicating that no valid value can be obtained.",
},
},
},
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudEbPlatformEventPatternsRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_eb_platform_event_patterns.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

ctx := context.WithValue(context.TODO(), logIdKey, logId)

var productType string
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("product_type"); ok {
productType = v.(string)
paramMap["ProductType"] = helper.String(v.(string))
}

service := EbService{client: meta.(*TencentCloudClient).apiV3Conn}

var eventPatterns []*eb.PlatformEventSummary

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeEbPlatformEventPatternsByFilter(ctx, paramMap)
if e != nil {
return retryError(e)
}
eventPatterns = result
return nil
})
if err != nil {
return err
}

ids := make([]string, 0, len(eventPatterns))
tmpList := make([]map[string]interface{}, 0, len(eventPatterns))

if eventPatterns != nil {
for _, platformEventSummary := range eventPatterns {
platformEventSummaryMap := map[string]interface{}{}

if platformEventSummary.EventName != nil {
platformEventSummaryMap["event_name"] = platformEventSummary.EventName
}

if platformEventSummary.EventPattern != nil {
platformEventSummaryMap["event_pattern"] = platformEventSummary.EventPattern
ids = append(ids, *platformEventSummary.EventPattern)
}
tmpList = append(tmpList, platformEventSummaryMap)
}

_ = d.Set("event_patterns", tmpList)
}

d.SetId(helper.DataResourceIdsHash(append(ids, productType)))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), tmpList); e != nil {
return e
}
}
return nil
}
35 changes: 35 additions & 0 deletions tencentcloud/data_source_tc_eb_platform_event_patterns_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -test.run TestAccTencentCloudEbPlatformEventPatternsDataSource_basic -v
func TestAccTencentCloudEbPlatformEventPatternsDataSource_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: testAccEbPlatformEventPatternsDataSource,
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_eb_platform_event_patterns.platform_event_patterns"),
),
},
},
})
}

const testAccEbPlatformEventPatternsDataSource = `
data "tencentcloud_eb_platform_event_patterns" "platform_event_patterns" {
product_type = "eb_platform_test"
}
`
Loading

0 comments on commit 042e9b7

Please sign in to comment.