Skip to content

Commit a8b9c13

Browse files
committed
add ai analysis template
1 parent ac3d0f3 commit a8b9c13

File tree

4 files changed

+135
-93
lines changed

4 files changed

+135
-93
lines changed

tencentcloud/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,9 @@ func Provider() terraform.ResourceProvider {
17131713
"tencentcloud_mps_snapshot_by_timeoffset_template": resourceTencentCloudMpsSnapshotByTimeoffsetTemplate(),
17141714
"tencentcloud_mps_sample_snapshot_template": resourceTencentCloudMpsSampleSnapshotTemplate(),
17151715
"tencentcloud_mps_animated_graphics_template": resourceTencentCloudMpsAnimatedGraphicsTemplate(),
1716+
"tencentcloud_mps_ai_recognition_template": resourceTencentCloudMpsAiRecognitionTemplate(),
1717+
"tencentcloud_mps_ai_analysis_template": resourceTencentCloudMpsAiAnalysisTemplate(),
1718+
"tencentcloud_mps_adaptive_dynamic_streaming_template": resourceTencentCloudMpsAdaptiveDynamicStreamingTemplate(),
17161719
"tencentcloud_cbs_disk_backup": resourceTencentCloudCbsDiskBackup(),
17171720
"tencentcloud_cbs_snapshot_share_permission": resourceTencentCloudCbsSnapshotSharePermission(),
17181721
"tencentcloud_cbs_disk_backup_rollback_operation": resourceTencentCloudCbsDiskBackupRollbackOperation(),

tencentcloud/resource_tc_mps_adaptive_dynamic_streaming_template.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,37 @@ Provides a resource to create a mps adaptive_dynamic_streaming_template
44
Example Usage
55
66
```hcl
7-
resource "tencentcloud_mps_adaptive_dynamic_streaming_template" "adaptive_dynamic_streaming_template" {
8-
format = <nil>
9-
stream_infos {
10-
video {
11-
codec = <nil>
12-
fps = <nil>
13-
bitrate = <nil>
14-
resolution_adaptive = "open"
15-
width = 0
16-
height = 0
17-
gop = <nil>
18-
fill_type = "black"
19-
vcrf = <nil>
20-
}
21-
audio {
22-
codec = <nil>
23-
bitrate = <nil>
24-
sample_rate = <nil>
25-
audio_channel = 2
26-
}
27-
remove_audio = <nil>
28-
remove_video = <nil>
7+
resource "tencentcloud_mps_ai_recognition_template" "ai_recognition_template" {
8+
name = "terraform-test"
9+
10+
asr_full_text_configure {
11+
switch = "OFF"
12+
}
13+
14+
asr_words_configure {
15+
label_set = []
16+
switch = "OFF"
17+
}
18+
19+
face_configure {
20+
default_library_label_set = [
21+
"entertainment",
22+
"sport",
23+
]
24+
face_library = "All"
25+
score = 85
26+
switch = "ON"
27+
user_define_library_label_set = []
28+
}
29+
30+
ocr_full_text_configure {
31+
switch = "OFF"
32+
}
2933
34+
ocr_words_configure {
35+
label_set = []
36+
switch = "OFF"
3037
}
31-
name = <nil>
32-
disable_higher_video_bitrate = 0
33-
disable_higher_video_resolution = 0
34-
comment = <nil>
3538
}
3639
```
3740

tencentcloud/resource_tc_mps_ai_recognition_template.go

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,35 @@ Example Usage
55
66
```hcl
77
resource "tencentcloud_mps_ai_recognition_template" "ai_recognition_template" {
8-
name = <nil>
9-
comment = <nil>
10-
face_configure {
11-
switch = <nil>
12-
score =
13-
default_library_label_set = <nil>
14-
user_define_library_label_set = <nil>
15-
face_library = "All"
8+
name = "terraform-test"
169
10+
asr_full_text_configure {
11+
switch = "OFF"
1712
}
18-
ocr_full_text_configure {
19-
switch = <nil>
2013
14+
asr_words_configure {
15+
label_set = []
16+
switch = "OFF"
2117
}
22-
ocr_words_configure {
23-
switch = <nil>
24-
label_set = <nil>
2518
19+
face_configure {
20+
default_library_label_set = [
21+
"entertainment",
22+
"sport",
23+
]
24+
face_library = "All"
25+
score = 85
26+
switch = "ON"
27+
user_define_library_label_set = []
2628
}
27-
asr_full_text_configure {
28-
switch = <nil>
29-
subtitle_format = <nil>
3029
30+
ocr_full_text_configure {
31+
switch = "OFF"
3132
}
32-
asr_words_configure {
33-
switch = <nil>
34-
label_set = <nil>
3533
34+
ocr_words_configure {
35+
label_set = []
36+
switch = "OFF"
3637
}
3738
}
3839
```
@@ -49,7 +50,6 @@ package tencentcloud
4950

5051
import (
5152
"context"
52-
"fmt"
5353
"log"
5454

5555
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -451,27 +451,26 @@ func resourceTencentCloudMpsAiRecognitionTemplateUpdate(d *schema.ResourceData,
451451

452452
request.Definition = helper.StrToInt64Point(definition)
453453

454-
immutableArgs := []string{"name", "comment", "face_configure", "ocr_full_text_configure", "ocr_words_configure", "asr_full_text_configure", "asr_words_configure"}
454+
mutableArgs := []string{"name", "comment", "face_configure", "ocr_full_text_configure", "ocr_words_configure", "asr_full_text_configure", "asr_words_configure"}
455+
456+
needChange := false
455457

456-
for _, v := range immutableArgs {
458+
for _, v := range mutableArgs {
457459
if d.HasChange(v) {
458-
return fmt.Errorf("argument `%s` cannot be changed", v)
460+
needChange = true
461+
break
459462
}
460463
}
461464

462-
if d.HasChange("name") {
465+
if needChange {
463466
if v, ok := d.GetOk("name"); ok {
464467
request.Name = helper.String(v.(string))
465468
}
466-
}
467469

468-
if d.HasChange("comment") {
469470
if v, ok := d.GetOk("comment"); ok {
470471
request.Comment = helper.String(v.(string))
471472
}
472-
}
473473

474-
if d.HasChange("face_configure") {
475474
if dMap, ok := helper.InterfacesHeadMap(d, "face_configure"); ok {
476475
faceConfigureInfo := mps.FaceConfigureInfoForUpdate{}
477476
if v, ok := dMap["switch"]; ok {
@@ -499,19 +498,15 @@ func resourceTencentCloudMpsAiRecognitionTemplateUpdate(d *schema.ResourceData,
499498
}
500499
request.FaceConfigure = &faceConfigureInfo
501500
}
502-
}
503501

504-
if d.HasChange("ocr_full_text_configure") {
505502
if dMap, ok := helper.InterfacesHeadMap(d, "ocr_full_text_configure"); ok {
506503
ocrFullTextConfigureInfo := mps.OcrFullTextConfigureInfoForUpdate{}
507504
if v, ok := dMap["switch"]; ok {
508505
ocrFullTextConfigureInfo.Switch = helper.String(v.(string))
509506
}
510507
request.OcrFullTextConfigure = &ocrFullTextConfigureInfo
511508
}
512-
}
513509

514-
if d.HasChange("ocr_words_configure") {
515510
if dMap, ok := helper.InterfacesHeadMap(d, "ocr_words_configure"); ok {
516511
ocrWordsConfigureInfo := mps.OcrWordsConfigureInfoForUpdate{}
517512
if v, ok := dMap["switch"]; ok {
@@ -526,22 +521,18 @@ func resourceTencentCloudMpsAiRecognitionTemplateUpdate(d *schema.ResourceData,
526521
}
527522
request.OcrWordsConfigure = &ocrWordsConfigureInfo
528523
}
529-
}
530524

531-
if d.HasChange("asr_full_text_configure") {
532525
if dMap, ok := helper.InterfacesHeadMap(d, "asr_full_text_configure"); ok {
533526
asrFullTextConfigureInfo := mps.AsrFullTextConfigureInfoForUpdate{}
534527
if v, ok := dMap["switch"]; ok {
535528
asrFullTextConfigureInfo.Switch = helper.String(v.(string))
536529
}
537-
if v, ok := dMap["subtitle_format"]; ok {
530+
if v, _ := dMap["subtitle_format"]; v != "" {
538531
asrFullTextConfigureInfo.SubtitleFormat = helper.String(v.(string))
539532
}
540533
request.AsrFullTextConfigure = &asrFullTextConfigureInfo
541534
}
542-
}
543535

544-
if d.HasChange("asr_words_configure") {
545536
if dMap, ok := helper.InterfacesHeadMap(d, "asr_words_configure"); ok {
546537
asrWordsConfigureInfo := mps.AsrWordsConfigureInfoForUpdate{}
547538
if v, ok := dMap["switch"]; ok {
@@ -556,20 +547,20 @@ func resourceTencentCloudMpsAiRecognitionTemplateUpdate(d *schema.ResourceData,
556547
}
557548
request.AsrWordsConfigure = &asrWordsConfigureInfo
558549
}
559-
}
560550

561-
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
562-
result, e := meta.(*TencentCloudClient).apiV3Conn.UseMpsClient().ModifyAIRecognitionTemplate(request)
563-
if e != nil {
564-
return retryError(e)
565-
} else {
566-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
551+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
552+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseMpsClient().ModifyAIRecognitionTemplate(request)
553+
if e != nil {
554+
return retryError(e)
555+
} else {
556+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
557+
}
558+
return nil
559+
})
560+
if err != nil {
561+
log.Printf("[CRITAL]%s update mps aiRecognitionTemplate failed, reason:%+v", logId, err)
562+
return err
567563
}
568-
return nil
569-
})
570-
if err != nil {
571-
log.Printf("[CRITAL]%s update mps aiRecognitionTemplate failed, reason:%+v", logId, err)
572-
return err
573564
}
574565

575566
return resourceTencentCloudMpsAiRecognitionTemplateRead(d, meta)

tencentcloud/resource_tc_mps_ai_recognition_template_test.go

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ func TestAccTencentCloudMpsAiRecognitionTemplateResource_basic(t *testing.T) {
1818
Config: testAccMpsAiRecognitionTemplate,
1919
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_mps_ai_recognition_template.ai_recognition_template", "id")),
2020
},
21+
{
22+
Config: testAccMpsAiRecognitionTemplateUpdate,
23+
Check: resource.ComposeTestCheckFunc(
24+
resource.TestCheckResourceAttrSet("tencentcloud_mps_ai_recognition_template.ai_recognition_template", "id"),
25+
resource.TestCheckResourceAttr("tencentcloud_mps_ai_recognition_template.ai_recognition_template", "name", "terraform-for-test"),
26+
),
27+
},
2128
{
2229
ResourceName: "tencentcloud_mps_ai_recognition_template.ai_recognition_template",
2330
ImportState: true,
@@ -30,34 +37,72 @@ func TestAccTencentCloudMpsAiRecognitionTemplateResource_basic(t *testing.T) {
3037
const testAccMpsAiRecognitionTemplate = `
3138
3239
resource "tencentcloud_mps_ai_recognition_template" "ai_recognition_template" {
33-
name = <nil>
34-
comment = <nil>
35-
face_configure {
36-
switch = <nil>
37-
score =
38-
default_library_label_set = <nil>
39-
user_define_library_label_set = <nil>
40-
face_library = "All"
40+
name = "terraform-test"
4141
42+
asr_full_text_configure {
43+
switch = "OFF"
4244
}
43-
ocr_full_text_configure {
44-
switch = <nil>
4545
46+
asr_words_configure {
47+
label_set = []
48+
switch = "OFF"
49+
}
50+
51+
face_configure {
52+
default_library_label_set = [
53+
"entertainment",
54+
"sport",
55+
]
56+
face_library = "All"
57+
score = 85
58+
switch = "ON"
59+
user_define_library_label_set = []
4660
}
47-
ocr_words_configure {
48-
switch = <nil>
49-
label_set = <nil>
5061
62+
ocr_full_text_configure {
63+
switch = "OFF"
5164
}
52-
asr_full_text_configure {
53-
switch = <nil>
54-
subtitle_format = <nil>
5565
66+
ocr_words_configure {
67+
label_set = []
68+
switch = "OFF"
5669
}
70+
}
71+
72+
`
73+
74+
const testAccMpsAiRecognitionTemplateUpdate = `
75+
76+
resource "tencentcloud_mps_ai_recognition_template" "ai_recognition_template" {
77+
name = "terraform-for-test"
78+
79+
asr_full_text_configure {
80+
switch = "OFF"
81+
}
82+
5783
asr_words_configure {
58-
switch = <nil>
59-
label_set = <nil>
84+
label_set = []
85+
switch = "OFF"
86+
}
6087
88+
face_configure {
89+
default_library_label_set = [
90+
"entertainment",
91+
"sport",
92+
]
93+
face_library = "All"
94+
score = 85
95+
switch = "ON"
96+
user_define_library_label_set = []
97+
}
98+
99+
ocr_full_text_configure {
100+
switch = "OFF"
101+
}
102+
103+
ocr_words_configure {
104+
label_set = []
105+
switch = "OFF"
61106
}
62107
}
63108

0 commit comments

Comments
 (0)