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

fix(vod): [116206298]fix vod sub application && vod procedure template #2542

Merged
merged 3 commits into from
Mar 1, 2024
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
7 changes: 7 additions & 0 deletions .changelog/2542.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/tencentcloud_vod_sub_application: fix status update problem
```

```release-note:enhancement
resource/tencentcloud_vod_procedure_template: fix api must set SubAppId
```
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
15 changes: 13 additions & 2 deletions tencentcloud/services/vod/resource_tc_vod_sub_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
vod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717"

sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit"
)
Expand Down Expand Up @@ -96,8 +97,13 @@ func resourceTencentCloudVodSubApplicationCreate(d *schema.ResourceData, meta in
ratelimit.Check(statusResquest.GetAction())
_, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVodClient().ModifySubAppIdStatus(statusResquest)
if err != nil {
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
if sdkError.Code == "FailedOperation" && sdkError.Message == "invalid vod user" {
return resource.RetryableError(err)
}
}
log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error())
return tccommon.RetryError(err)
return resource.NonRetryableError(err)
}
return nil
}); err != nil {
Expand Down Expand Up @@ -209,8 +215,13 @@ func resourceTencentCloudVodSubApplicationUpdate(d *schema.ResourceData, meta in
ratelimit.Check(statusRequest.GetAction())
_, err = meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVodClient().ModifySubAppIdStatus(statusRequest)
if err != nil {
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
if sdkError.Code == "FailedOperation" && sdkError.Message == "invalid vod user" {
return resource.RetryableError(err)
}
}
log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, statusRequest.GetAction(), err.Error())
return tccommon.RetryError(err)
return resource.NonRetryableError(err)
}
return nil
})
Expand Down
43 changes: 43 additions & 0 deletions tencentcloud/services/vod/resource_tc_vod_sub_application_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package vod_test

import (
"testing"

tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"

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

func TestAccTencentCloudVodSubApplicationResource(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里不支持修改吗,是否需要加一个修改场景的测试用例

t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccVodSubApplication,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_vod_sub_application.foo", "id"),
resource.TestCheckResourceAttr("tencentcloud_vod_sub_application.foo", "name", "foo"),
resource.TestCheckResourceAttr("tencentcloud_vod_sub_application.foo", "status", "On"),
resource.TestCheckResourceAttr("tencentcloud_vod_sub_application.foo", "description", "this is sub application"),
resource.TestCheckResourceAttrSet("tencentcloud_vod_sub_application.foo", "create_time"),
),
},
{
ResourceName: "tencentcloud_vod_sub_application.foo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"status"},
},
},
})
}

const testAccVodSubApplication = `
resource "tencentcloud_vod_sub_application" "foo" {
name = "foo"
status = "On"
description = "this is sub application"
}
`
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
Loading