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

[do not merge][need refactor]Feat/support mps operation #2165

Closed
wants to merge 6 commits into from
Closed
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
15 changes: 15 additions & 0 deletions .changelog/2165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:new-resource
tencentcloud_mps_parse_live_stream_process_notify_operation
```

```release-note:new-resource
tencentcloud_mps_parse_notify_operation
```

```release-note:new-resource
tencentcloud_mps_edit_media_operation
```

```release-note:new-resource
tencentcloud_mps_describe_media_metadata_operation
```
8 changes: 8 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,10 @@ Media Processing Service(MPS)
tencentcloud_mps_adaptive_dynamic_streaming_template
tencentcloud_mps_person_sample
tencentcloud_mps_withdraws_watermark_operation
tencentcloud_mps_parse_live_stream_process_notify_operation
tencentcloud_mps_parse_notify_operation
tencentcloud_mps_edit_media_operation
tencentcloud_mps_describe_media_metadata_operation

Cloud HDFS(CHDFS)
Data Source
Expand Down Expand Up @@ -3065,6 +3069,10 @@ func Provider() *schema.Provider {
"tencentcloud_mps_adaptive_dynamic_streaming_template": resourceTencentCloudMpsAdaptiveDynamicStreamingTemplate(),
"tencentcloud_mps_person_sample": resourceTencentCloudMpsPersonSample(),
"tencentcloud_mps_withdraws_watermark_operation": resourceTencentCloudMpsWithdrawsWatermarkOperation(),
"tencentcloud_mps_parse_live_stream_process_notify_operation": resourceTencentCloudMpsParseLiveStreamProcessNotifyOperation(),
"tencentcloud_mps_parse_notify_operation": resourceTencentCloudMpsParseNotifyOperation(),
"tencentcloud_mps_edit_media_operation": resourceTencentCloudMpsEditMediaOperation(),
"tencentcloud_mps_describe_media_metadata_operation": resourceTencentCloudMpsDescribeMediaMetadataOperation(),
"tencentcloud_cbs_disk_backup": resourceTencentCloudCbsDiskBackup(),
"tencentcloud_cbs_snapshot_share_permission": resourceTencentCloudCbsSnapshotSharePermission(),
"tencentcloud_cbs_disk_backup_rollback_operation": resourceTencentCloudCbsDiskBackupRollbackOperation(),
Expand Down
230 changes: 230 additions & 0 deletions tencentcloud/resource_tc_mps_describe_media_metadata_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个资源不适合作为datasource类型是吧

Provides a resource to create a mps describe_media_metadata_operation

Example Usage

Operation through COS

```hcl
data "tencentcloud_cos_bucket_object" "object" {
bucket = "keep-bucket-${local.app_id}"
key = "/mps-test/test.mov"
}

resource "tencentcloud_mps_describe_media_metadata_operation" "operation" {
input_info {
type = "COS"
cos_input_info {
bucket = data.tencentcloud_cos_bucket_object.object.bucket
region = "%s"
object = data.tencentcloud_cos_bucket_object.object.key
}
}
}
```

*/
package tencentcloud

import (
"encoding/json"
"log"

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

func resourceTencentCloudMpsDescribeMediaMetadataOperation() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudMpsDescribeMediaMetadataOperationCreate,
Read: resourceTencentCloudMpsDescribeMediaMetadataOperationRead,
Delete: resourceTencentCloudMpsDescribeMediaMetadataOperationDelete,
Schema: map[string]*schema.Schema{
"input_info": {
Required: true,
ForceNew: true,
Type: schema.TypeList,
MaxItems: 1,
Description: "Input information of file for metadata getting.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
Description: "The input type. Valid values: `COS`: A COS bucket address. `URL`: A URL. `AWS-S3`: An AWS S3 bucket address. Currently, this type is only supported for transcoding tasks.",
},
"cos_input_info": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "The information of the COS object to process. This parameter is valid and required when `Type` is `COS`.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Required: true,
Description: "The COS bucket of the object to process, such as `TopRankVideo-125xxx88`.",
},
"region": {
Type: schema.TypeString,
Required: true,
Description: "The region of the COS bucket, such as `ap-chongqing`.",
},
"object": {
Type: schema.TypeString,
Required: true,
Description: "The path of the object to process, such as `/movie/201907/WildAnimal.mov`.",
},
},
},
},
"url_input_info": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "The URL of the object to process. This parameter is valid and required when `Type` is `URL`.Note: This field may return null, indicating that no valid value can be obtained.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Required: true,
Description: "URL of a video.",
},
},
},
},
"s3_input_info": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "The information of the AWS S3 object processed. This parameter is required if `Type` is `AWS-S3`.Note: This field may return null, indicating that no valid value can be obtained.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"s3_bucket": {
Type: schema.TypeString,
Required: true,
Description: "The AWS S3 bucket.",
},
"s3_region": {
Type: schema.TypeString,
Required: true,
Description: "The region of the AWS S3 bucket.",
},
"s3_object": {
Type: schema.TypeString,
Required: true,
Description: "The path of the AWS S3 object.",
},
"s3_secret_id": {
Type: schema.TypeString,
Optional: true,
Description: "The key ID required to access the AWS S3 object.",
},
"s3_secret_key": {
Type: schema.TypeString,
Optional: true,
Description: "The key required to access the AWS S3 object.",
},
},
},
},
},
},
},
},
}
}

func resourceTencentCloudMpsDescribeMediaMetadataOperationCreate(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_mps_describe_media_metadata_operation.create")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

var (
request = mps.NewDescribeMediaMetaDataRequest()
inputInfo mps.MediaInputInfo
)
if dMap, ok := helper.InterfacesHeadMap(d, "input_info"); ok {
mediaInputInfo := mps.MediaInputInfo{}
if v, ok := dMap["type"]; ok {
mediaInputInfo.Type = helper.String(v.(string))
}
if cosInputInfoMap, ok := helper.InterfaceToMap(dMap, "cos_input_info"); ok {
cosInputInfo := mps.CosInputInfo{}
if v, ok := cosInputInfoMap["bucket"]; ok {
cosInputInfo.Bucket = helper.String(v.(string))
}
if v, ok := cosInputInfoMap["region"]; ok {
cosInputInfo.Region = helper.String(v.(string))
}
if v, ok := cosInputInfoMap["object"]; ok {
cosInputInfo.Object = helper.String(v.(string))
}
mediaInputInfo.CosInputInfo = &cosInputInfo
}
if urlInputInfoMap, ok := helper.InterfaceToMap(dMap, "url_input_info"); ok {
urlInputInfo := mps.UrlInputInfo{}
if v, ok := urlInputInfoMap["url"]; ok {
urlInputInfo.Url = helper.String(v.(string))
}
mediaInputInfo.UrlInputInfo = &urlInputInfo
}
if s3InputInfoMap, ok := helper.InterfaceToMap(dMap, "s3_input_info"); ok {
s3InputInfo := mps.S3InputInfo{}
if v, ok := s3InputInfoMap["s3_bucket"]; ok {
s3InputInfo.S3Bucket = helper.String(v.(string))
}
if v, ok := s3InputInfoMap["s3_region"]; ok {
s3InputInfo.S3Region = helper.String(v.(string))
}
if v, ok := s3InputInfoMap["s3_object"]; ok {
s3InputInfo.S3Object = helper.String(v.(string))
}
if v, ok := s3InputInfoMap["s3_secret_id"]; ok {
s3InputInfo.S3SecretId = helper.String(v.(string))
}
if v, ok := s3InputInfoMap["s3_secret_key"]; ok {
s3InputInfo.S3SecretKey = helper.String(v.(string))
}
mediaInputInfo.S3InputInfo = &s3InputInfo
}
request.InputInfo = &mediaInputInfo
inputInfo = mediaInputInfo
}

err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
result, e := meta.(*TencentCloudClient).apiV3Conn.UseMpsClient().DescribeMediaMetaData(request)
if e != nil {
return retryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
return nil
})
if err != nil {
log.Printf("[CRITAL]%s operate mps describeMediaMetadataOperation failed, reason:%+v", logId, err)
return err
}

b, _ := json.Marshal(inputInfo)
d.SetId(helper.IntToStr(helper.HashString(string(b))))

return resourceTencentCloudMpsDescribeMediaMetadataOperationRead(d, meta)
}

func resourceTencentCloudMpsDescribeMediaMetadataOperationRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_mps_describe_media_metadata_operation.read")()
defer inconsistentCheck(d, meta)()

return nil
}

func resourceTencentCloudMpsDescribeMediaMetadataOperationDelete(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_mps_describe_media_metadata_operation.delete")()
defer inconsistentCheck(d, meta)()

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package tencentcloud

import (
"fmt"
"testing"

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

func TestAccTencentCloudMpsDescribeMediaMetadataOperationResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccMpsDescribeMediaMetadataOperation, defaultRegion),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_mps_describe_media_metadata_operation.operation", "id"),
resource.TestCheckResourceAttrSet("tencentcloud_mps_describe_media_metadata_operation.operation", "input_info.#"),
resource.TestCheckResourceAttr("tencentcloud_mps_describe_media_metadata_operation.operation", "input_info.0.type", "COS"),
resource.TestCheckResourceAttrSet("tencentcloud_mps_describe_media_metadata_operation.operation", "input_info.0.cos_input_info.#"),
resource.TestCheckResourceAttrSet("tencentcloud_mps_describe_media_metadata_operation.operation", "input_info.0.cos_input_info.0.bucket"),
resource.TestCheckResourceAttr("tencentcloud_mps_describe_media_metadata_operation.operation", "input_info.0.cos_input_info.0.region", defaultRegion),
resource.TestCheckResourceAttr("tencentcloud_mps_describe_media_metadata_operation.operation", "input_info.0.cos_input_info.0.object", "/mps-test/test.mov"),
),
},
},
})
}

const testAccMpsDescribeMediaMetadataOperation = userInfoData + `
data "tencentcloud_cos_bucket_object" "object" {
bucket = "keep-bucket-${local.app_id}"
key = "/mps-test/test.mov"
}

resource "tencentcloud_mps_describe_media_metadata_operation" "operation" {
input_info {
type = "COS"
cos_input_info {
bucket = data.tencentcloud_cos_bucket_object.object.bucket
region = "%s"
object = data.tencentcloud_cos_bucket_object.object.key
}
}
}

`
Loading