-
Notifications
You must be signed in to change notification settings - Fork 136
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 | ||
``` |
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
230 changes: 230 additions & 0 deletions
230
tencentcloud/resource_tc_mps_describe_media_metadata_operation.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,230 @@ | ||
/* | ||
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 | ||
} |
51 changes: 51 additions & 0 deletions
51
tencentcloud/resource_tc_mps_describe_media_metadata_operation_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,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 | ||
} | ||
} | ||
} | ||
|
||
` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个资源不适合作为datasource类型是吧