-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support eb datasource * feat: add changelog * fix: modify test
- Loading branch information
Showing
18 changed files
with
1,564 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
tencentcloud/data_source_tc_eb_platform_event_names_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
122
tencentcloud/data_source_tc_eb_platform_event_patterns.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
tencentcloud/data_source_tc_eb_platform_event_patterns_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
` |
Oops, something went wrong.