Skip to content

Commit

Permalink
fix vod procedure template must set sub_app_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mikatong committed Feb 27, 2024
1 parent 0170a6a commit e1dc0ed
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 31 deletions.
65 changes: 53 additions & 12 deletions tencentcloud/services/vod/resource_tc_vod_procedure_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log"
"strconv"
"strings"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
},
})
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tencentcloud/services/vod/service_tencentcloud_vod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions website/docs/r/vod_procedure_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:

Expand Down

0 comments on commit e1dc0ed

Please sign in to comment.