Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support data source tencentcloud_mps_schedules #2185

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2185.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
tencentcloud_mps_schedules
```
8 changes: 8 additions & 0 deletions tencentcloud/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,3 +1138,11 @@ resource "tencentcloud_eni_attachment" "foo" {
`

//End of Clb

// MPS
const (
defaultMpsScheduleId = 24685
defaultMpsScheduleName = "keep_mps_schedule_001"
)

//End of MPS
4,604 changes: 4,604 additions & 0 deletions tencentcloud/data_source_tc_mps_schedules.go

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions tencentcloud/data_source_tc_mps_schedules_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package tencentcloud

import (
"fmt"
"testing"

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

func TestAccTencentCloudMpsSchedulesDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccMpsSchedulesDataSource_none,
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_mps_schedules.schedules"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.activities.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.create_time"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.update_time"),
),
},
{
Config: fmt.Sprintf(testAccMpsSchedulesDataSource_specific_one, defaultMpsScheduleId),
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_mps_schedules.schedules"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_ids.#"),
resource.TestCheckTypeSetElemAttr("data.tencentcloud_mps_schedules.schedules", "schedule_ids.*", fmt.Sprint(defaultMpsScheduleId)),
resource.TestCheckResourceAttr("data.tencentcloud_mps_schedules.schedules", "trigger_type", "CosFileUpload"),
resource.TestCheckResourceAttr("data.tencentcloud_mps_schedules.schedules", "status", "Disabled"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.#"),
resource.TestCheckResourceAttr("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.schedule_id", fmt.Sprint(defaultMpsScheduleId)),
resource.TestCheckResourceAttr("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.schedule_name", defaultMpsScheduleName),
resource.TestCheckResourceAttr("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.status", "Disabled"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.trigger.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.activities.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.output_storage.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.output_dir"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.task_notify_config.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.create_time"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mps_schedules.schedules", "schedule_info_set.0.update_time"),
),
},
},
})
}

const testAccMpsSchedulesDataSource_none = `

data "tencentcloud_mps_schedules" "schedules" {
}

`

const testAccMpsSchedulesDataSource_specific_one = `

data "tencentcloud_mps_schedules" "schedules" {
schedule_ids = [%d]
trigger_type = "CosFileUpload"
status = "Disabled"
}

`
4 changes: 4 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,9 @@ Tencent Service Framework(TSF)
tencentcloud_tsf_unit_namespace

Media Processing Service(MPS)
Data Source
tencentcloud_mps_schedules

Resource
tencentcloud_mps_workflow
tencentcloud_mps_enable_workflow_config
Expand Down Expand Up @@ -2244,6 +2247,7 @@ func Provider() *schema.Provider {
"tencentcloud_mariadb_sale_info": dataSourceTencentCloudMariadbSaleInfo(),
"tencentcloud_mariadb_slow_logs": dataSourceTencentCloudMariadbSlowLogs(),
"tencentcloud_mariadb_upgrade_price": dataSourceTencentCloudMariadbUpgradePrice(),
"tencentcloud_mps_schedules": dataSourceTencentCloudMpsSchedules(),
"tencentcloud_tdcpg_clusters": dataSourceTencentCloudTdcpgClusters(),
"tencentcloud_tdcpg_instances": dataSourceTencentCloudTdcpgInstances(),
"tencentcloud_cat_probe_data": dataSourceTencentCloudCatProbeData(),
Expand Down
55 changes: 55 additions & 0 deletions tencentcloud/service_tencentcloud_mps.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,58 @@ func (me *MpsService) DeleteMpsScheduleById(ctx context.Context, scheduleId stri

return
}

func (me *MpsService) DescribeMpsSchedulesByFilter(ctx context.Context, param map[string]interface{}) (schedules []*mps.SchedulesInfo, errRet error) {
var (
logId = getLogId(ctx)
request = mps.NewDescribeSchedulesRequest()
)

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 == "ScheduleIds" {
request.ScheduleIds = helper.InterfacesIntInt64Point(v.([]interface{}))
}
if k == "TriggerType" {
request.TriggerType = v.(*string)
}
if k == "Status" {
request.Status = v.(*string)
}
}

ratelimit.Check(request.GetAction())

var (
offset uint64 = 0
limit uint64 = 20
)

for {
request.Offset = &offset
request.Limit = &limit
response, err := me.client.UseMpsClient().DescribeSchedules(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 == nil || len(response.Response.ScheduleInfoSet) < 1 {
break
}
schedules = append(schedules, response.Response.ScheduleInfoSet...)
if len(response.Response.ScheduleInfoSet) < int(limit) {
break
}

offset += limit
}

return
}
Loading
Loading