Skip to content

Commit f0f5c77

Browse files
tongyimingmikatong
and
mikatong
authored
fix(vod): [116206298]fix vod sub application && vod procedure template (#2542)
* fix vod sub application status * fix vod procedure template must set sub_app_id * add changelog --------- Co-authored-by: mikatong <[email protected]>
1 parent a6d6e64 commit f0f5c77

8 files changed

+176
-33
lines changed

.changelog/2542.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_vod_sub_application: fix status update problem
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_vod_procedure_template: fix api must set SubAppId
7+
```

tencentcloud/services/vod/resource_tc_vod_procedure_template.go

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"log"
66
"strconv"
7+
"strings"
78

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

@@ -42,7 +43,7 @@ func ResourceTencentCloudVodProcedureTemplate() *schema.Resource {
4243
"sub_app_id": {
4344
Type: schema.TypeInt,
4445
Optional: true,
45-
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.",
46+
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.",
4647
},
4748
"media_process_task": {
4849
Type: schema.TypeList,
@@ -531,12 +532,18 @@ func resourceTencentCloudVodProcedureTemplateCreate(d *schema.ResourceData, meta
531532
request = vod.NewCreateProcedureTemplateRequest()
532533
)
533534

534-
request.Name = helper.String(d.Get("name").(string))
535+
name := d.Get("name").(string)
536+
request.Name = helper.String(name)
535537
if v, ok := d.GetOk("comment"); ok {
536538
request.Comment = helper.String(v.(string))
537539
}
540+
541+
resourceId := name
538542
if v, ok := d.GetOk("sub_app_id"); ok {
539-
request.SubAppId = helper.IntUint64(v.(int))
543+
subAppId := v.(int)
544+
resourceId += tccommon.FILED_SP
545+
resourceId += helper.IntToStr(subAppId)
546+
request.SubAppId = helper.IntUint64(subAppId)
540547
}
541548
if _, ok := d.GetOk("media_process_task"); ok {
542549
mediaReq := generateMediaProcessTask(d)
@@ -556,7 +563,8 @@ func resourceTencentCloudVodProcedureTemplateCreate(d *schema.ResourceData, meta
556563
if err != nil {
557564
return err
558565
}
559-
d.SetId(d.Get("name").(string))
566+
567+
d.SetId(resourceId)
560568

561569
return resourceTencentCloudVodProcedureTemplateRead(d, meta)
562570
}
@@ -566,14 +574,22 @@ func resourceTencentCloudVodProcedureTemplateRead(d *schema.ResourceData, meta i
566574
defer tccommon.InconsistentCheck(d, meta)()
567575

568576
var (
577+
name string
578+
subAppId int
569579
logId = tccommon.GetLogId(tccommon.ContextNil)
570580
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
571581
id = d.Id()
572-
subAppId = d.Get("sub_app_id").(int)
573582
client = meta.(tccommon.ProviderMeta).GetAPIV3Conn()
574583
vodService = VodService{client: client}
575584
)
576-
template, has, err := vodService.DescribeProcedureTemplatesById(ctx, id, subAppId)
585+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
586+
if len(idSplit) == 2 {
587+
name = idSplit[0]
588+
subAppId = helper.StrToInt(idSplit[1])
589+
} else {
590+
name = id
591+
}
592+
template, has, err := vodService.DescribeProcedureTemplatesById(ctx, name, subAppId)
577593
if err != nil {
578594
return err
579595
}
@@ -586,6 +602,9 @@ func resourceTencentCloudVodProcedureTemplateRead(d *schema.ResourceData, meta i
586602
_ = d.Set("comment", template.Comment)
587603
_ = d.Set("create_time", template.CreateTime)
588604
_ = d.Set("update_time", template.UpdateTime)
605+
if subAppId != 0 {
606+
_ = d.Set("sub_app_id", subAppId)
607+
}
589608

590609
mediaProcessTaskElem := make(map[string]interface{})
591610
if template.MediaProcessTask != nil {
@@ -788,15 +807,23 @@ func resourceTencentCloudVodProcedureTemplateUpdate(d *schema.ResourceData, meta
788807
changeFlag = false
789808
)
790809

791-
request.Name = &id
810+
idSplit := strings.Split(d.Id(), tccommon.FILED_SP)
811+
if len(idSplit) == 2 {
812+
request.Name = helper.String(idSplit[0])
813+
subAppId := helper.StrToInt(idSplit[1])
814+
request.SubAppId = helper.IntUint64(subAppId)
815+
} else {
816+
request.Name = &id
817+
if v, ok := d.GetOk("sub_app_id"); ok {
818+
request.SubAppId = helper.IntUint64(v.(int))
819+
}
820+
}
821+
792822
if d.HasChange("comment") {
793823
changeFlag = true
794824
request.Comment = helper.String(d.Get("comment").(string))
795825
}
796-
if d.HasChange("sub_app_id") {
797-
changeFlag = true
798-
request.SubAppId = helper.IntUint64(d.Get("sub_app_id").(int))
799-
}
826+
800827
if d.HasChange("media_process_task") {
801828
changeFlag = true
802829
mediaReq := generateMediaProcessTask(d)
@@ -831,11 +858,25 @@ func resourceTencentCloudVodProcedureTemplateDelete(d *schema.ResourceData, meta
831858
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
832859

833860
id := d.Id()
861+
idSplit := strings.Split(id, tccommon.FILED_SP)
862+
var (
863+
name string
864+
subAppId int
865+
)
866+
if len(idSplit) == 2 {
867+
name = idSplit[0]
868+
subAppId = helper.StrToInt(idSplit[1])
869+
} else {
870+
name = id
871+
if v, ok := d.GetOk("sub_app_id"); ok {
872+
subAppId = v.(int)
873+
}
874+
}
834875
vodService := VodService{
835876
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
836877
}
837878

838-
if err := vodService.DeleteProcedureTemplate(ctx, id, uint64(d.Get("sub_app_id").(int))); err != nil {
879+
if err := vodService.DeleteProcedureTemplate(ctx, name, uint64(subAppId)); err != nil {
839880
return err
840881
}
841882

tencentcloud/services/vod/resource_tc_vod_procedure_template.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ resource "tencentcloud_vod_image_sprite_template" "foo" {
6767
resolution_adaptive = false
6868
}
6969
70+
resource "tencentcloud_vod_sub_application" "sub_application" {
71+
name = "subapplication"
72+
status = "On"
73+
description = "this is sub application"
74+
}
75+
7076
resource "tencentcloud_vod_procedure_template" "foo" {
7177
name = "tf-procedure"
7278
comment = "test"
79+
sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1])
7380
media_process_task {
7481
adaptive_dynamic_streaming_task_list {
7582
definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id

tencentcloud/services/vod/resource_tc_vod_procedure_template_test.go

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package vod_test
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"testing"
78

89
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
910
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
1012
svcvod "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/vod"
1113

1214
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -84,10 +86,9 @@ func TestAccTencentCloudVodProcedureTemplateResource(t *testing.T) {
8486
),
8587
},
8688
{
87-
ResourceName: "tencentcloud_vod_procedure_template.foo",
88-
ImportState: true,
89-
ImportStateVerify: true,
90-
ImportStateVerifyIgnore: []string{"sub_app_id"},
89+
ResourceName: "tencentcloud_vod_procedure_template.foo",
90+
ImportState: true,
91+
ImportStateVerify: true,
9192
},
9293
},
9394
})
@@ -102,11 +103,16 @@ func testAccCheckVodProcedureTemplateDestroy(s *terraform.State) error {
102103
if rs.Type != "tencentcloud_vod_procedure_template" {
103104
continue
104105
}
105-
var (
106-
filter = map[string]interface{}{
107-
"name": []string{rs.Primary.ID},
108-
}
109-
)
106+
id := rs.Primary.ID
107+
filter := map[string]interface{}{}
108+
109+
idSplit := strings.Split(id, tccommon.FILED_SP)
110+
if len(idSplit) == 2 {
111+
filter["name"] = []string{idSplit[0]}
112+
filter["sub_appid"] = helper.StrToInt(idSplit[1])
113+
} else {
114+
return fmt.Errorf("can not get sub_appid")
115+
}
110116

111117
templates, err := vodService.DescribeProcedureTemplatesByFilter(ctx, filter)
112118
if err != nil {
@@ -133,11 +139,16 @@ func testAccCheckVodProcedureTemplateExists(n string) resource.TestCheckFunc {
133139
return fmt.Errorf("vod procedure template id is not set")
134140
}
135141
vodService := svcvod.NewVodService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn())
136-
var (
137-
filter = map[string]interface{}{
138-
"name": []string{rs.Primary.ID},
139-
}
140-
)
142+
id := rs.Primary.ID
143+
filter := map[string]interface{}{}
144+
145+
idSplit := strings.Split(id, tccommon.FILED_SP)
146+
if len(idSplit) == 2 {
147+
filter["name"] = []string{idSplit[0]}
148+
filter["sub_appid"] = helper.StrToInt(idSplit[1])
149+
} else {
150+
return fmt.Errorf("can not get sub_appid")
151+
}
141152
templates, err := vodService.DescribeProcedureTemplatesByFilter(ctx, filter)
142153
if err != nil {
143154
return err
@@ -150,9 +161,16 @@ func testAccCheckVodProcedureTemplateExists(n string) resource.TestCheckFunc {
150161
}
151162

152163
const testAccVodProcedureTemplate = testAccVodAdaptiveDynamicStreamingTemplate + testAccVodSnapshotByTimeOffsetTemplate + testAccVodImageSpriteTemplate + `
164+
resource "tencentcloud_vod_sub_application" "sub_application" {
165+
name = "subapplication"
166+
status = "On"
167+
description = "this is sub application"
168+
}
169+
153170
resource "tencentcloud_vod_procedure_template" "foo" {
154171
name = "tf-procedure0"
155172
comment = "test"
173+
sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1])
156174
media_process_task {
157175
adaptive_dynamic_streaming_task_list {
158176
definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id
@@ -171,9 +189,16 @@ resource "tencentcloud_vod_procedure_template" "foo" {
171189
`
172190

173191
const testAccVodProcedureTemplateUpdate = testAccVodAdaptiveDynamicStreamingTemplate + testAccVodSnapshotByTimeOffsetTemplate + testAccVodImageSpriteTemplate + `
192+
resource "tencentcloud_vod_sub_application" "sub_application" {
193+
name = "subapplication"
194+
status = "On"
195+
description = "this is sub application"
196+
}
197+
174198
resource "tencentcloud_vod_procedure_template" "foo" {
175199
name = "tf-procedure0"
176200
comment = "test-update"
201+
sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1])
177202
media_process_task {
178203
adaptive_dynamic_streaming_task_list {
179204
definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id

tencentcloud/services/vod/resource_tc_vod_sub_application.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
vod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717"
1313

14+
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1415
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
1516
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit"
1617
)
@@ -96,8 +97,13 @@ func resourceTencentCloudVodSubApplicationCreate(d *schema.ResourceData, meta in
9697
ratelimit.Check(statusResquest.GetAction())
9798
_, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVodClient().ModifySubAppIdStatus(statusResquest)
9899
if err != nil {
100+
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
101+
if sdkError.Code == "FailedOperation" && sdkError.Message == "invalid vod user" {
102+
return resource.RetryableError(err)
103+
}
104+
}
99105
log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error())
100-
return tccommon.RetryError(err)
106+
return resource.NonRetryableError(err)
101107
}
102108
return nil
103109
}); err != nil {
@@ -209,8 +215,13 @@ func resourceTencentCloudVodSubApplicationUpdate(d *schema.ResourceData, meta in
209215
ratelimit.Check(statusRequest.GetAction())
210216
_, err = meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVodClient().ModifySubAppIdStatus(statusRequest)
211217
if err != nil {
218+
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
219+
if sdkError.Code == "FailedOperation" && sdkError.Message == "invalid vod user" {
220+
return resource.RetryableError(err)
221+
}
222+
}
212223
log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, statusRequest.GetAction(), err.Error())
213-
return tccommon.RetryError(err)
224+
return resource.NonRetryableError(err)
214225
}
215226
return nil
216227
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package vod_test
2+
3+
import (
4+
"testing"
5+
6+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
func TestAccTencentCloudVodSubApplicationResource(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { tcacctest.AccPreCheck(t) },
15+
Providers: tcacctest.AccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccVodSubApplication,
19+
Check: resource.ComposeTestCheckFunc(
20+
resource.TestCheckResourceAttrSet("tencentcloud_vod_sub_application.foo", "id"),
21+
resource.TestCheckResourceAttr("tencentcloud_vod_sub_application.foo", "name", "foo"),
22+
resource.TestCheckResourceAttr("tencentcloud_vod_sub_application.foo", "status", "On"),
23+
resource.TestCheckResourceAttr("tencentcloud_vod_sub_application.foo", "description", "this is sub application"),
24+
resource.TestCheckResourceAttrSet("tencentcloud_vod_sub_application.foo", "create_time"),
25+
),
26+
},
27+
{
28+
ResourceName: "tencentcloud_vod_sub_application.foo",
29+
ImportState: true,
30+
ImportStateVerify: true,
31+
ImportStateVerifyIgnore: []string{"status"},
32+
},
33+
},
34+
})
35+
}
36+
37+
const testAccVodSubApplication = `
38+
resource "tencentcloud_vod_sub_application" "foo" {
39+
name = "foo"
40+
status = "On"
41+
description = "this is sub application"
42+
}
43+
`

tencentcloud/services/vod/service_tencentcloud_vod.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ func (me *VodService) DescribeProcedureTemplatesByFilter(ctx context.Context, fi
171171
func (me *VodService) DescribeProcedureTemplatesById(ctx context.Context, templateId string, subAppId int) (templateInfo *vod.ProcedureTemplate, has bool, errRet error) {
172172
var (
173173
filter = map[string]interface{}{
174-
"name": []string{templateId},
175-
"sub_appid": subAppId,
174+
"name": []string{templateId},
176175
}
177176
)
177+
if subAppId != 0 {
178+
filter["sub_appid"] = subAppId
179+
}
178180

179181
templates, errRet := me.DescribeProcedureTemplatesByFilter(ctx, filter)
180182
if errRet != nil {

website/docs/r/vod_procedure_template.html.markdown

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ resource "tencentcloud_vod_image_sprite_template" "foo" {
7878
resolution_adaptive = false
7979
}
8080
81+
resource "tencentcloud_vod_sub_application" "sub_application" {
82+
name = "subapplication"
83+
status = "On"
84+
description = "this is sub application"
85+
}
86+
8187
resource "tencentcloud_vod_procedure_template" "foo" {
82-
name = "tf-procedure"
83-
comment = "test"
88+
name = "tf-procedure"
89+
comment = "test"
90+
sub_app_id = tonumber(split("#", tencentcloud_vod_sub_application.sub_application.id)[1])
8491
media_process_task {
8592
adaptive_dynamic_streaming_task_list {
8693
definition = tencentcloud_vod_adaptive_dynamic_streaming_template.foo.id
@@ -105,7 +112,7 @@ The following arguments are supported:
105112
* `name` - (Required, String, ForceNew) Task flow name (up to 20 characters).
106113
* `comment` - (Optional, String) Template description. Length limit: 256 characters.
107114
* `media_process_task` - (Optional, List) Parameter of video processing task.
108-
* `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.
115+
* `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.
109116

110117
The `adaptive_dynamic_streaming_task_list` object of `media_process_task` supports the following:
111118

0 commit comments

Comments
 (0)