From e1dc0ed82c1c91c7123acb52faf7f03a00231fa8 Mon Sep 17 00:00:00 2001 From: mikatong Date: Tue, 27 Feb 2024 20:29:50 +0800 Subject: [PATCH] fix vod procedure template must set sub_app_id --- .../vod/resource_tc_vod_procedure_template.go | 65 +++++++++++++++---- .../vod/resource_tc_vod_procedure_template.md | 7 ++ ...resource_tc_vod_procedure_template_test.go | 53 +++++++++++---- .../services/vod/service_tencentcloud_vod.go | 6 +- .../r/vod_procedure_template.html.markdown | 13 +++- 5 files changed, 113 insertions(+), 31 deletions(-) diff --git a/tencentcloud/services/vod/resource_tc_vod_procedure_template.go b/tencentcloud/services/vod/resource_tc_vod_procedure_template.go index 865bdfd2b4..7fb8897cea 100644 --- a/tencentcloud/services/vod/resource_tc_vod_procedure_template.go +++ b/tencentcloud/services/vod/resource_tc_vod_procedure_template.go @@ -4,6 +4,7 @@ import ( "context" "log" "strconv" + "strings" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" @@ -42,7 +43,7 @@ func ResourceTencentCloudVodProcedureTemplate() *schema.Resource { "sub_app_id": { Type: schema.TypeInt, Optional: true, - Description: "Subapplication ID in VOD. If you need to access a resource in a subapplication, enter the subapplication ID in this field; otherwise, leave it empty.", + Description: "Subapplication ID in VOD. For customers who activate VOD from December 25, 2023, if they access the resources in the VOD application (whether it is the default application or the newly created application), you must fill in this field as Application ID.", }, "media_process_task": { Type: schema.TypeList, @@ -531,12 +532,18 @@ func resourceTencentCloudVodProcedureTemplateCreate(d *schema.ResourceData, meta request = vod.NewCreateProcedureTemplateRequest() ) - request.Name = helper.String(d.Get("name").(string)) + name := d.Get("name").(string) + request.Name = helper.String(name) if v, ok := d.GetOk("comment"); ok { request.Comment = helper.String(v.(string)) } + + resourceId := name if v, ok := d.GetOk("sub_app_id"); ok { - request.SubAppId = helper.IntUint64(v.(int)) + subAppId := v.(int) + resourceId += tccommon.FILED_SP + resourceId += helper.IntToStr(subAppId) + request.SubAppId = helper.IntUint64(subAppId) } if _, ok := d.GetOk("media_process_task"); ok { mediaReq := generateMediaProcessTask(d) @@ -556,7 +563,8 @@ func resourceTencentCloudVodProcedureTemplateCreate(d *schema.ResourceData, meta if err != nil { return err } - d.SetId(d.Get("name").(string)) + + d.SetId(resourceId) return resourceTencentCloudVodProcedureTemplateRead(d, meta) } @@ -566,14 +574,22 @@ func resourceTencentCloudVodProcedureTemplateRead(d *schema.ResourceData, meta i defer tccommon.InconsistentCheck(d, meta)() var ( + name string + subAppId int logId = tccommon.GetLogId(tccommon.ContextNil) ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) id = d.Id() - subAppId = d.Get("sub_app_id").(int) client = meta.(tccommon.ProviderMeta).GetAPIV3Conn() vodService = VodService{client: client} ) - template, has, err := vodService.DescribeProcedureTemplatesById(ctx, id, subAppId) + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) == 2 { + name = idSplit[0] + subAppId = helper.StrToInt(idSplit[1]) + } else { + name = id + } + template, has, err := vodService.DescribeProcedureTemplatesById(ctx, name, subAppId) if err != nil { return err } @@ -586,6 +602,9 @@ func resourceTencentCloudVodProcedureTemplateRead(d *schema.ResourceData, meta i _ = d.Set("comment", template.Comment) _ = d.Set("create_time", template.CreateTime) _ = d.Set("update_time", template.UpdateTime) + if subAppId != 0 { + _ = d.Set("sub_app_id", subAppId) + } mediaProcessTaskElem := make(map[string]interface{}) if template.MediaProcessTask != nil { @@ -788,15 +807,23 @@ func resourceTencentCloudVodProcedureTemplateUpdate(d *schema.ResourceData, meta changeFlag = false ) - request.Name = &id + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) == 2 { + request.Name = helper.String(idSplit[0]) + subAppId := helper.StrToInt(idSplit[1]) + request.SubAppId = helper.IntUint64(subAppId) + } else { + request.Name = &id + if v, ok := d.GetOk("sub_app_id"); ok { + request.SubAppId = helper.IntUint64(v.(int)) + } + } + if d.HasChange("comment") { changeFlag = true request.Comment = helper.String(d.Get("comment").(string)) } - if d.HasChange("sub_app_id") { - changeFlag = true - request.SubAppId = helper.IntUint64(d.Get("sub_app_id").(int)) - } + if d.HasChange("media_process_task") { changeFlag = true mediaReq := generateMediaProcessTask(d) @@ -831,11 +858,25 @@ func resourceTencentCloudVodProcedureTemplateDelete(d *schema.ResourceData, meta ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) id := d.Id() + idSplit := strings.Split(id, tccommon.FILED_SP) + var ( + name string + subAppId int + ) + if len(idSplit) == 2 { + name = idSplit[0] + subAppId = helper.StrToInt(idSplit[1]) + } else { + name = id + if v, ok := d.GetOk("sub_app_id"); ok { + subAppId = v.(int) + } + } vodService := VodService{ client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(), } - if err := vodService.DeleteProcedureTemplate(ctx, id, uint64(d.Get("sub_app_id").(int))); err != nil { + if err := vodService.DeleteProcedureTemplate(ctx, name, uint64(subAppId)); err != nil { return err } diff --git a/tencentcloud/services/vod/resource_tc_vod_procedure_template.md b/tencentcloud/services/vod/resource_tc_vod_procedure_template.md index b61ccc57e3..8ba2f1a452 100644 --- a/tencentcloud/services/vod/resource_tc_vod_procedure_template.md +++ b/tencentcloud/services/vod/resource_tc_vod_procedure_template.md @@ -67,9 +67,16 @@ resource "tencentcloud_vod_image_sprite_template" "foo" { resolution_adaptive = false } +resource "tencentcloud_vod_sub_application" "sub_application" { + name = "subapplication" + status = "On" + description = "this is sub application" +} + resource "tencentcloud_vod_procedure_template" "foo" { name = "tf-procedure" comment = "test" + sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1]) media_process_task { adaptive_dynamic_streaming_task_list { definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id diff --git a/tencentcloud/services/vod/resource_tc_vod_procedure_template_test.go b/tencentcloud/services/vod/resource_tc_vod_procedure_template_test.go index d838b669c3..df8385cc41 100644 --- a/tencentcloud/services/vod/resource_tc_vod_procedure_template_test.go +++ b/tencentcloud/services/vod/resource_tc_vod_procedure_template_test.go @@ -3,10 +3,12 @@ package vod_test import ( "context" "fmt" + "strings" "testing" tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" svcvod "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/vod" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -84,10 +86,9 @@ func TestAccTencentCloudVodProcedureTemplateResource(t *testing.T) { ), }, { - ResourceName: "tencentcloud_vod_procedure_template.foo", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"sub_app_id"}, + ResourceName: "tencentcloud_vod_procedure_template.foo", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -102,11 +103,16 @@ func testAccCheckVodProcedureTemplateDestroy(s *terraform.State) error { if rs.Type != "tencentcloud_vod_procedure_template" { continue } - var ( - filter = map[string]interface{}{ - "name": []string{rs.Primary.ID}, - } - ) + id := rs.Primary.ID + filter := map[string]interface{}{} + + idSplit := strings.Split(id, tccommon.FILED_SP) + if len(idSplit) == 2 { + filter["name"] = []string{idSplit[0]} + filter["sub_appid"] = helper.StrToInt(idSplit[1]) + } else { + return fmt.Errorf("can not get sub_appid") + } templates, err := vodService.DescribeProcedureTemplatesByFilter(ctx, filter) if err != nil { @@ -133,11 +139,16 @@ func testAccCheckVodProcedureTemplateExists(n string) resource.TestCheckFunc { return fmt.Errorf("vod procedure template id is not set") } vodService := svcvod.NewVodService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) - var ( - filter = map[string]interface{}{ - "name": []string{rs.Primary.ID}, - } - ) + id := rs.Primary.ID + filter := map[string]interface{}{} + + idSplit := strings.Split(id, tccommon.FILED_SP) + if len(idSplit) == 2 { + filter["name"] = []string{idSplit[0]} + filter["sub_appid"] = helper.StrToInt(idSplit[1]) + } else { + return fmt.Errorf("can not get sub_appid") + } templates, err := vodService.DescribeProcedureTemplatesByFilter(ctx, filter) if err != nil { return err @@ -150,9 +161,16 @@ func testAccCheckVodProcedureTemplateExists(n string) resource.TestCheckFunc { } const testAccVodProcedureTemplate = testAccVodAdaptiveDynamicStreamingTemplate + testAccVodSnapshotByTimeOffsetTemplate + testAccVodImageSpriteTemplate + ` +resource "tencentcloud_vod_sub_application" "sub_application" { + name = "subapplication" + status = "On" + description = "this is sub application" +} + resource "tencentcloud_vod_procedure_template" "foo" { name = "tf-procedure0" comment = "test" + sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1]) media_process_task { adaptive_dynamic_streaming_task_list { definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id @@ -171,9 +189,16 @@ resource "tencentcloud_vod_procedure_template" "foo" { ` const testAccVodProcedureTemplateUpdate = testAccVodAdaptiveDynamicStreamingTemplate + testAccVodSnapshotByTimeOffsetTemplate + testAccVodImageSpriteTemplate + ` +resource "tencentcloud_vod_sub_application" "sub_application" { + name = "subapplication" + status = "On" + description = "this is sub application" +} + resource "tencentcloud_vod_procedure_template" "foo" { name = "tf-procedure0" comment = "test-update" + sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1]) media_process_task { adaptive_dynamic_streaming_task_list { definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id diff --git a/tencentcloud/services/vod/service_tencentcloud_vod.go b/tencentcloud/services/vod/service_tencentcloud_vod.go index 742a9bd951..7041f93d6d 100644 --- a/tencentcloud/services/vod/service_tencentcloud_vod.go +++ b/tencentcloud/services/vod/service_tencentcloud_vod.go @@ -171,10 +171,12 @@ func (me *VodService) DescribeProcedureTemplatesByFilter(ctx context.Context, fi func (me *VodService) DescribeProcedureTemplatesById(ctx context.Context, templateId string, subAppId int) (templateInfo *vod.ProcedureTemplate, has bool, errRet error) { var ( filter = map[string]interface{}{ - "name": []string{templateId}, - "sub_appid": subAppId, + "name": []string{templateId}, } ) + if subAppId != 0 { + filter["sub_appid"] = subAppId + } templates, errRet := me.DescribeProcedureTemplatesByFilter(ctx, filter) if errRet != nil { diff --git a/website/docs/r/vod_procedure_template.html.markdown b/website/docs/r/vod_procedure_template.html.markdown index 1dbd68d143..e5d885f57f 100644 --- a/website/docs/r/vod_procedure_template.html.markdown +++ b/website/docs/r/vod_procedure_template.html.markdown @@ -78,9 +78,16 @@ resource "tencentcloud_vod_image_sprite_template" "foo" { resolution_adaptive = false } +resource "tencentcloud_vod_sub_application" "sub_application" { + name = "subapplication" + status = "On" + description = "this is sub application" +} + resource "tencentcloud_vod_procedure_template" "foo" { - name = "tf-procedure" - comment = "test" + name = "tf-procedure" + comment = "test" + sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1]) media_process_task { adaptive_dynamic_streaming_task_list { definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id @@ -105,7 +112,7 @@ The following arguments are supported: * `name` - (Required, String, ForceNew) Task flow name (up to 20 characters). * `comment` - (Optional, String) Template description. Length limit: 256 characters. * `media_process_task` - (Optional, List) Parameter of video processing task. -* `sub_app_id` - (Optional, Int) Subapplication ID in VOD. If you need to access a resource in a subapplication, enter the subapplication ID in this field; otherwise, leave it empty. +* `sub_app_id` - (Optional, Int) Subapplication ID in VOD. For customers who activate VOD from December 25, 2023, if they access the resources in the VOD application (whether it is the default application or the newly created application), you must fill in this field as Application ID. The `adaptive_dynamic_streaming_task_list` object of `media_process_task` supports the following: