diff --git a/tencentcloud/resource_tc_ci_bucket_attachment_test.go b/tencentcloud/resource_tc_ci_bucket_attachment_test.go index 070e240da4..7437c13bf8 100644 --- a/tencentcloud/resource_tc_ci_bucket_attachment_test.go +++ b/tencentcloud/resource_tc_ci_bucket_attachment_test.go @@ -95,7 +95,7 @@ func testAccCheckCiBucketAttachmentExists(re string) resource.TestCheckFunc { const testAccCiBucketAttachment = ` resource "tencentcloud_ci_bucket_attachment" "bucket_attachment" { - bucket = "terraform-ci-1308919341" + bucket = "terraform-ci-test-1308919341" } ` diff --git a/tencentcloud/resource_tc_ci_media_animation_template.go b/tencentcloud/resource_tc_ci_media_animation_template.go index fba91bbbc2..05ce67c0bd 100644 --- a/tencentcloud/resource_tc_ci_media_animation_template.go +++ b/tencentcloud/resource_tc_ci_media_animation_template.go @@ -28,14 +28,6 @@ resource "tencentcloud_ci_media_animation_template" "media_animation_template" { } } ``` - -Import - -ci media_animation_template can be imported using the bucket#templateId, e.g. - -``` -terraform import tencentcloud_ci_media_animation_template.media_animation_template terraform-ci-xxxxxx#t18210645f96564eaf80e86b1f58c20152 -``` */ package tencentcloud @@ -58,9 +50,9 @@ func resourceTencentCloudCiMediaAnimationTemplate() *schema.Resource { Read: resourceTencentCloudCiMediaAnimationTemplateRead, Update: resourceTencentCloudCiMediaAnimationTemplateUpdate, Delete: resourceTencentCloudCiMediaAnimationTemplateDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, + // Importer: &schema.ResourceImporter{ + // State: schema.ImportStatePassthrough, + // }, Schema: map[string]*schema.Schema{ "bucket": { Required: true, @@ -244,7 +236,7 @@ func resourceTencentCloudCiMediaAnimationTemplateCreate(d *schema.ResourceData, if e != nil { return retryError(e) } else { - log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%v]\n", logId, "CreateMediaAnimationTemplate", request, result) + log.Printf("[DEBUG]%s api[%s] success, request body [%+v], response body [%+v]\n", logId, "CreateMediaAnimationTemplate", request, result) } response = result return nil @@ -287,11 +279,13 @@ func resourceTencentCloudCiMediaAnimationTemplateRead(d *schema.ResourceData, me return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if template.Name != "" { _ = d.Set("name", template.Name) } - mediaAnimationTemplate := template.Animation + mediaAnimationTemplate := template.TransTpl if mediaAnimationTemplate != nil { if mediaAnimationTemplate.Container != nil { containerMap := map[string]interface{}{} @@ -322,23 +316,26 @@ func resourceTencentCloudCiMediaAnimationTemplateRead(d *schema.ResourceData, me videoMap["fps"] = mediaAnimationTemplate.Video.Fps } - if mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame != "" { - videoMap["animate_only_keep_key_frame"] = mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame - } + // if mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame != "" { + // videoMap["animate_only_keep_key_frame"] = mediaAnimationTemplate.Video.AnimateOnlyKeepKeyFrame + // } - if mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame != "" { - videoMap["animate_time_interval_of_frame"] = mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame - } + // if mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame != "" { + // videoMap["animate_time_interval_of_frame"] = mediaAnimationTemplate.Video.AnimateTimeIntervalOfFrame + // } - if mediaAnimationTemplate.Video.AnimateFramesPerSecond != "" { - videoMap["animate_frames_per_second"] = mediaAnimationTemplate.Video.AnimateFramesPerSecond - } + // if mediaAnimationTemplate.Video.AnimateFramesPerSecond != "" { + // videoMap["animate_frames_per_second"] = mediaAnimationTemplate.Video.AnimateFramesPerSecond + // } - if mediaAnimationTemplate.Video.Quality != "" { - videoMap["quality"] = mediaAnimationTemplate.Video.Quality - } + // if mediaAnimationTemplate.Video.Quality != "" { + // videoMap["quality"] = mediaAnimationTemplate.Video.Quality + // } - _ = d.Set("video", []interface{}{videoMap}) + err = d.Set("video", []interface{}{videoMap}) + if err != nil { + return err + } } if mediaAnimationTemplate.TimeInterval != nil { @@ -352,7 +349,10 @@ func resourceTencentCloudCiMediaAnimationTemplateRead(d *schema.ResourceData, me timeIntervalMap["duration"] = mediaAnimationTemplate.TimeInterval.Duration } - _ = d.Set("time_interval", []interface{}{timeIntervalMap}) + err = d.Set("time_interval", []interface{}{timeIntervalMap}) + if err != nil { + return err + } } } diff --git a/tencentcloud/resource_tc_ci_media_animation_template_test.go b/tencentcloud/resource_tc_ci_media_animation_template_test.go index 7c7de81be5..29dfd4e586 100644 --- a/tencentcloud/resource_tc_ci_media_animation_template_test.go +++ b/tencentcloud/resource_tc_ci_media_animation_template_test.go @@ -1,56 +1,146 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) +// go test -i; go test -test.run TestAccTencentCloudCiMediaAnimationTemplateResource_basic -v func TestAccTencentCloudCiMediaAnimationTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaAnimationTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaAnimationTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_animation_template.media_animation_template", "id")), - }, - { - ResourceName: "tencentcloud_ci_media_animation_template.media_animation_template", - ImportState: true, - ImportStateVerify: true, + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaAnimationTemplateExists("tencentcloud_ci_media_animation_template.media_animation_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_animation_template.media_animation_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "name", "animation_template_test"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "container.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "container.0.format", "gif"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.codec", "gif"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.width", "1280"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.height", ""), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.fps", "20"), + // resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "video.0.animate_only_keep_key_frame", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "time_interval.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "time_interval.0.start", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_animation_template.media_animation_template", "time_interval.0.duration", "60"), + ), }, + // { + // ResourceName: "tencentcloud_ci_media_animation_template.media_animation_template", + // ImportState: true, + // ImportStateVerify: true, + // }, }, }) } -const testAccCiMediaAnimationTemplate = ` +func testAccCheckCiMediaAnimationTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_animation_template" { + continue + } -resource "tencentcloud_ci_media_animation_template" "media_animation_template" { - name = <nil> - container { - format = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] - } - video { - codec = <nil> - width = <nil> - height = <nil> - fps = <nil> - animate_only_keep_key_frame = <nil> - animate_time_interval_of_frame = <nil> - animate_frames_per_second = <nil> - quality = <nil> + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } - } - time_interval { - start = <nil> - duration = <nil> + if res != nil { + return fmt.Errorf("ci media animation template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaAnimationTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media animation template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media animation template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaAnimationTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } + +` + +const testAccCiMediaAnimationTemplate = testAccCiMediaAnimationTemplateVar + ` + +resource "tencentcloud_ci_media_animation_template" "media_animation_template" { + bucket = var.bucket + name = "animation_template_test" + container { + format = "gif" + } + video { + codec = "gif" + width = "1280" + height = "" + fps = "20" + animate_only_keep_key_frame = "" + animate_time_interval_of_frame = "" + animate_frames_per_second = "" + quality = "" + + } + time_interval { + start = "0" + duration = "60" + + } } ` diff --git a/tencentcloud/resource_tc_ci_media_concat_template.go b/tencentcloud/resource_tc_ci_media_concat_template.go index 8b06792a40..ec25c56f79 100644 --- a/tencentcloud/resource_tc_ci_media_concat_template.go +++ b/tencentcloud/resource_tc_ci_media_concat_template.go @@ -26,7 +26,7 @@ resource "tencentcloud_ci_media_concat_template" "media_concat_template" { codec = "H.264" width = "1280" height = "" - bitrate = "1000" + bitrate = "1000" fps = "25" crf = "" remove = "" @@ -43,7 +43,7 @@ resource "tencentcloud_ci_media_concat_template" "media_concat_template" { enable_start_fadein = "true" start_fadein_time = "3" enable_end_fadeout = "false" - end_fadeout_time = "0" + end_fadeout_time = "0.1" enable_bgm_fade = "true" bgm_fade_time = "1.7" } @@ -193,6 +193,7 @@ func resourceTencentCloudCiMediaConcatTemplate() *schema.Resource { "remove": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "Whether to delete the source audio stream, the value is true, false.", }, "rotate": { @@ -264,6 +265,7 @@ func resourceTencentCloudCiMediaConcatTemplate() *schema.Resource { "end_fadeout_time": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "fade out time, greater than 0, support floating point numbers.", }, "enable_bgm_fade": { @@ -469,6 +471,8 @@ func resourceTencentCloudCiMediaConcatTemplateRead(d *schema.ResourceData, meta return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if mediaConcatTemplate.Name != "" { _ = d.Set("name", mediaConcatTemplate.Name) } @@ -488,7 +492,7 @@ func resourceTencentCloudCiMediaConcatTemplateRead(d *schema.ResourceData, meta } concatFragmentList = append(concatFragmentList, concatFragmentMap) } - concatTemplateMap["concat_fragment"] = []interface{}{concatFragmentList} + concatTemplateMap["concat_fragment"] = concatFragmentList } if mediaConcatTemplate.ConcatTemplate.Audio != nil { @@ -611,7 +615,7 @@ func resourceTencentCloudCiMediaConcatTemplateRead(d *schema.ResourceData, meta audioMixList = append(audioMixList, audioMixMap) } - concatTemplateMap["audio_mix"] = []interface{}{audioMixList} + concatTemplateMap["audio_mix"] = audioMixList } _ = d.Set("concat_template", []interface{}{concatTemplateMap}) diff --git a/tencentcloud/resource_tc_ci_media_concat_template_test.go b/tencentcloud/resource_tc_ci_media_concat_template_test.go index 9e43c76b43..392538f37f 100644 --- a/tencentcloud/resource_tc_ci_media_concat_template_test.go +++ b/tencentcloud/resource_tc_ci_media_concat_template_test.go @@ -1,22 +1,88 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_concat_template + resource.AddTestSweepers("tencentcloud_ci_media_concat_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_concat_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "concat_templates", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaConcatTemplateResource_basic -v func TestAccTencentCloudCiMediaConcatTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaConcatTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaConcatTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_concat_template.media_concat_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaConcatTemplateTemplateExists("tencentcloud_ci_media_concat_template.media_concat_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_concat_template.media_concat_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "name", "concat_templates"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.concat_fragment.#", "2"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.concat_fragment.0.url", "https://"+defaultCiBucket+".cos.ap-guangzhou.myqcloud.com/mp4%2Fmp4-test.mp4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.concat_fragment.0.mode", "Start"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.concat_fragment.1.url", "https://"+defaultCiBucket+".cos.ap-guangzhou.myqcloud.com/mp4%2Fmp4-test.mp4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.concat_fragment.1.mode", "End"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio.0.codec", "mp3"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.video.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.video.0.codec", "H.264"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.video.0.width", "1280"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.video.0.bitrate", "1000"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.video.0.fps", "25"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.container.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.container.0.format", "mp4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.audio_source", "https://"+defaultCiBucket+".cos.ap-guangzhou.myqcloud.com/mp3%2Fnizhan-test.mp3"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.mix_mode", "Once"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.replace", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.effect_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.effect_config.0.enable_start_fadein", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.effect_config.0.start_fadein_time", "3"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.effect_config.0.enable_end_fadeout", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.effect_config.0.enable_bgm_fade", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_concat_template.media_concat_template", "concat_template.0.audio_mix.0.effect_config.0.bgm_fade_time", "1.7"), + ), }, { ResourceName: "tencentcloud_ci_media_concat_template.media_concat_template", @@ -27,49 +93,122 @@ func TestAccTencentCloudCiMediaConcatTemplateResource_basic(t *testing.T) { }) } -const testAccCiMediaConcatTemplate = ` +func testAccCheckCiMediaConcatTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_concat_template" { + continue + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media concat template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaConcatTemplateTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media concat template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media concat template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaConcatTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" + } + +` + +const testAccCiMediaConcatTemplate = testAccCiMediaConcatTemplateVar + ` resource "tencentcloud_ci_media_concat_template" "media_concat_template" { - name = <nil> - concat_template { + bucket = var.bucket + name = "concat_templates" + concat_template { + concat_fragment { + url = "https://` + defaultCiBucket + `.cos.ap-guangzhou.myqcloud.com/mp4%2Fmp4-test.mp4" + mode = "Start" + } concat_fragment { - url = <nil> - mode = <nil> + url = "https://` + defaultCiBucket + `.cos.ap-guangzhou.myqcloud.com/mp4%2Fmp4-test.mp4" + mode = "End" } audio { - codec = <nil> - samplerate = <nil> - bitrate = <nil> - channels = <nil> + codec = "mp3" + samplerate = "" + bitrate = "" + channels = "" } video { - codec = <nil> - width = <nil> - height = <nil> - fps = <nil> - crf = <nil> - remove = <nil> - rotate = <nil> + codec = "H.264" + width = "1280" + height = "" + bitrate = "1000" + fps = "25" + crf = "" + remove = "" + rotate = "" } container { - format = <nil> + format = "mp4" } audio_mix { - audio_source = <nil> - mix_mode = <nil> - replace = <nil> + audio_source = "https://` + defaultCiBucket + `.cos.ap-guangzhou.myqcloud.com/mp3%2Fnizhan-test.mp3" + mix_mode = "Once" + replace = "true" effect_config { - enable_start_fadein = <nil> - start_fadein_time = <nil> - enable_end_fadeout = <nil> - end_fadeout_time = <nil> - enable_bgm_fade = <nil> - bgm_fade_time = <nil> + enable_start_fadein = "true" + start_fadein_time = "3" + enable_end_fadeout = "false" + # end_fadeout_time = "1" + enable_bgm_fade = "true" + bgm_fade_time = "1.7" } } - direct_concat = <nil> - + } } -} ` diff --git a/tencentcloud/resource_tc_ci_media_pic_process_template.go b/tencentcloud/resource_tc_ci_media_pic_process_template.go index d5170dd2f4..504d8dad37 100644 --- a/tencentcloud/resource_tc_ci_media_pic_process_template.go +++ b/tencentcloud/resource_tc_ci_media_pic_process_template.go @@ -126,7 +126,7 @@ func resourceTencentCloudCiMediaPicProcessTemplateCreate(d *schema.ResourceData, if e != nil { return retryError(e) } else { - log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%v]\n", logId, "CreateMediaPicProcessTemplate", request, result) + log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%+v]\n", logId, "CreateMediaPicProcessTemplate", request, result) } response = result return nil @@ -168,6 +168,8 @@ func resourceTencentCloudCiMediaPicProcessTemplateRead(d *schema.ResourceData, m return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if mediaPicProcessTemplate.Name != "" { _ = d.Set("name", mediaPicProcessTemplate.Name) } @@ -183,7 +185,10 @@ func resourceTencentCloudCiMediaPicProcessTemplateRead(d *schema.ResourceData, m picProcessMap["process_rule"] = mediaPicProcessTemplate.PicProcess.ProcessRule } - _ = d.Set("pic_process", []interface{}{picProcessMap}) + err = d.Set("pic_process", []interface{}{picProcessMap}) + if err != nil { + return err + } } return nil diff --git a/tencentcloud/resource_tc_ci_media_pic_process_template_test.go b/tencentcloud/resource_tc_ci_media_pic_process_template_test.go index e20871c029..8987a0a5ed 100644 --- a/tencentcloud/resource_tc_ci_media_pic_process_template_test.go +++ b/tencentcloud/resource_tc_ci_media_pic_process_template_test.go @@ -1,22 +1,66 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_pic_process_template + resource.AddTestSweepers("tencentcloud_ci_media_pic_process_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_pic_process_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "pic_process_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaPicProcessTemplateResource_basic -v func TestAccTencentCloudCiMediaPicProcessTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaPicProcessTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaPicProcessTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaPicProcessTemplateTemplateExists("tencentcloud_ci_media_pic_process_template.media_pic_process_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "name", "pic_process_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "pic_process.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "pic_process.0.is_pic_info", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_pic_process_template.media_pic_process_template", "pic_process.0.process_rule", "imageMogr2/rotate/90"), + ), }, { ResourceName: "tencentcloud_ci_media_pic_process_template.media_pic_process_template", @@ -27,14 +71,85 @@ func TestAccTencentCloudCiMediaPicProcessTemplateResource_basic(t *testing.T) { }) } -const testAccCiMediaPicProcessTemplate = ` +func testAccCheckCiMediaPicProcessTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_pic_process_template" { + continue + } -resource "tencentcloud_ci_media_pic_process_template" "media_pic_process_template" { - pic_process { - is_pic_info = <nil> - process_rule = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media pic process template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} +func testAccCheckCiMediaPicProcessTemplateTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media pic process template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media pic process template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaPicProcessTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } + +` + +const testAccCiMediaPicProcessTemplate = testAccCiMediaPicProcessTemplateVar + ` + +resource "tencentcloud_ci_media_pic_process_template" "media_pic_process_template" { + bucket = var.bucket + name = "pic_process_template" + pic_process { + is_pic_info = "true" + process_rule = "imageMogr2/rotate/90" + + } } ` diff --git a/tencentcloud/resource_tc_ci_media_smart_cover_template.go b/tencentcloud/resource_tc_ci_media_smart_cover_template.go index ccf633db13..c56aebf617 100644 --- a/tencentcloud/resource_tc_ci_media_smart_cover_template.go +++ b/tencentcloud/resource_tc_ci_media_smart_cover_template.go @@ -194,6 +194,8 @@ func resourceTencentCloudCiMediaSmartCoverTemplateRead(d *schema.ResourceData, m return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if mediaSmartCoverTemplate.Name != "" { _ = d.Set("name", mediaSmartCoverTemplate.Name) } diff --git a/tencentcloud/resource_tc_ci_media_smart_cover_template_test.go b/tencentcloud/resource_tc_ci_media_smart_cover_template_test.go index 10177166a2..a444bafbf1 100644 --- a/tencentcloud/resource_tc_ci_media_smart_cover_template_test.go +++ b/tencentcloud/resource_tc_ci_media_smart_cover_template_test.go @@ -1,22 +1,69 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_smart_cover_template + resource.AddTestSweepers("tencentcloud_ci_media_smart_cover_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_smart_cover_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "smart_cover_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaSmartCoverTemplateResource_basic -v func TestAccTencentCloudCiMediaSmartCoverTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaSmartCoverTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaSmartCoverTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaSmartCoverTemplateTemplateExists("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "name", "smart_cover_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "smart_cover.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "smart_cover.0.format", "jpg"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "smart_cover.0.width", "1280"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "smart_cover.0.height", "960"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "smart_cover.0.count", "10"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", "smart_cover.0.delete_duplicates", "true"), + ), }, { ResourceName: "tencentcloud_ci_media_smart_cover_template.media_smart_cover_template", @@ -27,18 +74,87 @@ func TestAccTencentCloudCiMediaSmartCoverTemplateResource_basic(t *testing.T) { }) } -const testAccCiMediaSmartCoverTemplate = ` +func testAccCheckCiMediaSmartCoverTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_smart_cover_template" { + continue + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media smart cover template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaSmartCoverTemplateTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media smart cover template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media smart cover template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaSmartCoverTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" + } + +` + +const testAccCiMediaSmartCoverTemplate = testAccCiMediaSmartCoverTemplateVar + ` resource "tencentcloud_ci_media_smart_cover_template" "media_smart_cover_template" { - bucket = "terraform-ci-1308919341" + bucket = var.bucket name = "smart_cover_template" smart_cover { - format = "jpg" - width = "1280" - height = "960" - count = "10" - delete_duplicates = "true" + format = "jpg" + width = "1280" + height = "960" + count = "10" + delete_duplicates = "true" } - } +} ` diff --git a/tencentcloud/resource_tc_ci_media_snapshot_template.go b/tencentcloud/resource_tc_ci_media_snapshot_template.go index b5f51aedc3..ec87572177 100644 --- a/tencentcloud/resource_tc_ci_media_snapshot_template.go +++ b/tencentcloud/resource_tc_ci_media_snapshot_template.go @@ -6,28 +6,16 @@ Example Usage ```hcl resource "tencentcloud_ci_media_snapshot_template" "media_snapshot_template" { bucket = "terraform-ci-xxxxxx" - name = "snapshot_template" + name = "snapshot_template_test" snapshot { - # mode = "" - # start = "" - # time_interval = "" count = "10" - # width = "" - # height = "" - # ci_param = "" - # is_check_count = "" - # is_check_black = "" - # black_level = "" - # pixel_black_threshold = "" - # snapshot_out_mode = "" + snapshot_out_mode = "SnapshotAndSprite" sprite_snapshot_config { - # cell_width = "" - # cell_height = "" - # padding = "" - # margin = "" - color = "0xF0F8FF" + color = "White" columns = "10" lines = "10" + margin = "10" + padding = "10" } } } @@ -298,7 +286,7 @@ func resourceTencentCloudCiMediaSnapshotTemplateCreate(d *schema.ResourceData, m if v, ok := dMap["snapshot_out_mode"]; ok { snapshot.SnapshotOutMode = v.(string) } - if spriteSnapshotConfigMap, ok := helper.InterfacesHeadMap(d, "sprite_snapshot_config"); ok { + if spriteSnapshotConfigMap, ok := helper.InterfaceToMap(dMap, "sprite_snapshot_config"); ok { spriteSnapshotConfig := cos.SpriteSnapshotConfig{} if v, ok := spriteSnapshotConfigMap["cell_width"]; ok { spriteSnapshotConfig.CellWidth = v.(string) @@ -327,13 +315,13 @@ func resourceTencentCloudCiMediaSnapshotTemplateCreate(d *schema.ResourceData, m } var response *cos.CreateMediaTemplateResult - ciClient := meta.(*TencentCloudClient).apiV3Conn.UsePicClient(bucket) + ciClient := meta.(*TencentCloudClient).apiV3Conn.UseCiClient(bucket) err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { result, _, e := ciClient.CI.CreateMediaSnapshotTemplate(ctx, &request) if e != nil { return retryError(e) } else { - log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%v]\n", logId, "CreateMediaSnapshotTemplate", request, result) + log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%+v]\n", logId, "CreateMediaSnapshotTemplate", request, result) } response = result return nil @@ -380,6 +368,7 @@ func resourceTencentCloudCiMediaSnapshotTemplateRead(d *schema.ResourceData, met _ = d.Set("name", mediaSnapshotTemplate.Name) } + log.Printf("[DEBUG]Snapshot api[%+v]", mediaSnapshotTemplate.Snapshot) if mediaSnapshotTemplate.Snapshot != nil { snapshotMap := map[string]interface{}{} @@ -411,8 +400,8 @@ func resourceTencentCloudCiMediaSnapshotTemplateRead(d *schema.ResourceData, met snapshotMap["ci_param"] = mediaSnapshotTemplate.Snapshot.CIParam } - snapshotMap["is_check_count"] = mediaSnapshotTemplate.Snapshot.IsCheckCount - snapshotMap["is_check_black"] = mediaSnapshotTemplate.Snapshot.IsCheckBlack + snapshotMap["is_check_count"] = fmt.Sprintf("%t", mediaSnapshotTemplate.Snapshot.IsCheckCount) + snapshotMap["is_check_black"] = fmt.Sprintf("%t", mediaSnapshotTemplate.Snapshot.IsCheckBlack) if mediaSnapshotTemplate.Snapshot.BlackLevel != "" { snapshotMap["black_level"] = mediaSnapshotTemplate.Snapshot.BlackLevel @@ -460,7 +449,10 @@ func resourceTencentCloudCiMediaSnapshotTemplateRead(d *schema.ResourceData, met snapshotMap["sprite_snapshot_config"] = []interface{}{spriteSnapshotConfigMap} } - _ = d.Set("snapshot", []interface{}{snapshotMap}) + err = d.Set("snapshot", []interface{}{snapshotMap}) + if err != nil { + return err + } } if mediaSnapshotTemplate.TemplateId != "" { @@ -568,7 +560,7 @@ func resourceTencentCloudCiMediaSnapshotTemplateUpdate(d *schema.ResourceData, m } err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { - result, _, e := meta.(*TencentCloudClient).apiV3Conn.UsePicClient(bucket).CI.UpdateMediaSnapshotTemplate(ctx, &request, templateId) + result, _, e := meta.(*TencentCloudClient).apiV3Conn.UseCiClient(bucket).CI.UpdateMediaSnapshotTemplate(ctx, &request, templateId) if e != nil { return retryError(e) } else { diff --git a/tencentcloud/resource_tc_ci_media_snapshot_template_test.go b/tencentcloud/resource_tc_ci_media_snapshot_template_test.go new file mode 100644 index 0000000000..5c1234050f --- /dev/null +++ b/tencentcloud/resource_tc_ci_media_snapshot_template_test.go @@ -0,0 +1,134 @@ +package tencentcloud + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +// go test -i; go test -test.run TestAccTencentCloudCiMediaSnapshotTemplateResource_basic -v +func TestAccTencentCloudCiMediaSnapshotTemplateResource_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaSnapshotTemplateDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCiMediaSnapshotTemplate, + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaSnapshotTemplateTemplateExists("tencentcloud_ci_media_snapshot_template.media_snapshot_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "name", "snapshot_template_test"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.0.count", "10"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.0.snapshot_out_mode", "SnapshotAndSprite"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.0.sprite_snapshot_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.0.sprite_snapshot_config.0.color", "White"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.0.sprite_snapshot_config.0.columns", "10"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_snapshot_template.media_snapshot_template", "snapshot.0.sprite_snapshot_config.0.lines", "10"), + ), + }, + { + ResourceName: "tencentcloud_ci_media_snapshot_template.media_snapshot_template", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckCiMediaSnapshotTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_snapshot_template" { + continue + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media snapshot template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaSnapshotTemplateTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media snapshot template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media snapshot template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaSnapshotTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" + } + +` + +const testAccCiMediaSnapshotTemplate = testAccCiMediaSnapshotTemplateVar + ` + +resource "tencentcloud_ci_media_snapshot_template" "media_snapshot_template" { + bucket = var.bucket + name = "snapshot_template_test" + snapshot { + count = "10" + snapshot_out_mode = "SnapshotAndSprite" + sprite_snapshot_config { + color = "White" + columns = "10" + lines = "10" + margin = "10" + padding = "10" + } + } +} + +` diff --git a/tencentcloud/resource_tc_ci_media_speech_recognition_template.go b/tencentcloud/resource_tc_ci_media_speech_recognition_template.go index 370d13f9b7..9787d58d79 100644 --- a/tencentcloud/resource_tc_ci_media_speech_recognition_template.go +++ b/tencentcloud/resource_tc_ci_media_speech_recognition_template.go @@ -239,6 +239,8 @@ func resourceTencentCloudCiMediaSpeechRecognitionTemplateRead(d *schema.Resource return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if mediaSpeechRecognitionTemplate.Name != "" { _ = d.Set("name", mediaSpeechRecognitionTemplate.Name) } diff --git a/tencentcloud/resource_tc_ci_media_speech_recognition_template_test.go b/tencentcloud/resource_tc_ci_media_speech_recognition_template_test.go index e2dfd25831..31a58fa067 100644 --- a/tencentcloud/resource_tc_ci_media_speech_recognition_template_test.go +++ b/tencentcloud/resource_tc_ci_media_speech_recognition_template_test.go @@ -1,22 +1,74 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_speech_recognition_template + resource.AddTestSweepers("tencentcloud_ci_media_speech_recognition_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_speech_recognition_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "speech_recognition_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaSpeechRecognitionTemplateResource_basic -v func TestAccTencentCloudCiMediaSpeechRecognitionTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaSpeechRecognitionTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaSpeechRecognitionTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaSpeechRecognitionTemplateExists("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "name", "speech_recognition_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.engine_model_type", "16k_zh"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.channel_num", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.res_text_format", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.filter_dirty", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.filter_modal", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.convert_num_mode", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.speaker_diarization", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.speaker_number", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.filter_punc", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", "speech_recognition.0.output_file_type", "txt"), + ), }, { ResourceName: "tencentcloud_ci_media_speech_recognition_template.media_speech_recognition_template", @@ -27,23 +79,92 @@ func TestAccTencentCloudCiMediaSpeechRecognitionTemplateResource_basic(t *testin }) } -const testAccCiMediaSpeechRecognitionTemplate = ` +func testAccCheckCiMediaSpeechRecognitionTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_speech_recognition_template" { + continue + } -resource "tencentcloud_ci_media_speech_recognition_template" "media_speech_recognition_template" { - name = <nil> - speech_recognition { - engine_model_type = <nil> - channel_num = <nil> - res_text_format = <nil> - filter_dirty = <nil> - filter_modal = <nil> - convert_num_mode = <nil> - speaker_diarization = <nil> - speaker_number = <nil> - filter_punc = <nil> - output_file_type = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media speech recognition template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} +func testAccCheckCiMediaSpeechRecognitionTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media speech recognition template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media speech recognition template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaSpeechRecognitionTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } + +` + +const testAccCiMediaSpeechRecognitionTemplate = testAccCiMediaSpeechRecognitionTemplateVar + ` + +resource "tencentcloud_ci_media_speech_recognition_template" "media_speech_recognition_template" { + bucket = var.bucket + name = "speech_recognition_template" + speech_recognition { + engine_model_type = "16k_zh" + channel_num = "1" + res_text_format = "1" + filter_dirty = "0" + filter_modal = "1" + convert_num_mode = "0" + speaker_diarization = "1" + speaker_number = "0" + filter_punc = "0" + output_file_type = "txt" + } } ` diff --git a/tencentcloud/resource_tc_ci_media_super_resolution_template.go b/tencentcloud/resource_tc_ci_media_super_resolution_template.go index 55fcba7fc8..e757bf99f5 100644 --- a/tencentcloud/resource_tc_ci_media_super_resolution_template.go +++ b/tencentcloud/resource_tc_ci_media_super_resolution_template.go @@ -163,6 +163,8 @@ func resourceTencentCloudCiMediaSuperResolutionTemplateRead(d *schema.ResourceDa return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if template.Name != "" { _ = d.Set("name", template.Name) } diff --git a/tencentcloud/resource_tc_ci_media_super_resolution_template_test.go b/tencentcloud/resource_tc_ci_media_super_resolution_template_test.go index 6fb5e1b7aa..85ccd05edd 100644 --- a/tencentcloud/resource_tc_ci_media_super_resolution_template_test.go +++ b/tencentcloud/resource_tc_ci_media_super_resolution_template_test.go @@ -1,22 +1,66 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_super_resolution_template + resource.AddTestSweepers("tencentcloud_ci_media_super_resolution_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_super_resolution_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "super_resolution_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaSuperResolutionTemplateResource_basic -v func TestAccTencentCloudCiMediaSuperResolutionTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaSuperResolutionTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaSuperResolutionTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaSuperResolutionTemplateExists("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "name", "super_resolution_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "resolution", "sdtohd"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "enable_scale_up", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", "version", "Enhance"), + ), }, { ResourceName: "tencentcloud_ci_media_super_resolution_template.media_super_resolution_template", @@ -27,13 +71,82 @@ func TestAccTencentCloudCiMediaSuperResolutionTemplateResource_basic(t *testing. }) } -const testAccCiMediaSuperResolutionTemplate = ` +func testAccCheckCiMediaSuperResolutionTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_super_resolution_template" { + continue + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media super resolution template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaSuperResolutionTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media super resolution template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media super resolution template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaSuperResolutionTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" + } +` + +const testAccCiMediaSuperResolutionTemplate = testAccCiMediaSuperResolutionTemplateVar + ` resource "tencentcloud_ci_media_super_resolution_template" "media_super_resolution_template" { - name = <nil> - resolution = <nil> - enable_scale_up = <nil> - version = <nil> + bucket = var.bucket + name = "super_resolution_template" + resolution = "sdtohd" + enable_scale_up = "true" + version = "Enhance" } ` diff --git a/tencentcloud/resource_tc_ci_media_transcode_pro_template.go b/tencentcloud/resource_tc_ci_media_transcode_pro_template.go index 7a07f1bf37..bd24417fcd 100644 --- a/tencentcloud/resource_tc_ci_media_transcode_pro_template.go +++ b/tencentcloud/resource_tc_ci_media_transcode_pro_template.go @@ -19,7 +19,7 @@ resource "tencentcloud_ci_media_transcode_pro_template" "media_transcode_pro_tem profile = "XAVC-HD_422_10bit" width = "1920" height = "1080" - interlaced = "true" + interlaced = "true" fps = "30000/1001" bitrate = "50000" # rotate = "" diff --git a/tencentcloud/resource_tc_ci_media_transcode_pro_template_test.go b/tencentcloud/resource_tc_ci_media_transcode_pro_template_test.go index 22473c7f4c..df83289aff 100644 --- a/tencentcloud/resource_tc_ci_media_transcode_pro_template_test.go +++ b/tencentcloud/resource_tc_ci_media_transcode_pro_template_test.go @@ -1,78 +1,169 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccTencentCloudCiMediaTranscodeProTemplateResource_basic(t *testing.T) { +// go test -i; go test -test.run TestAccTencentCloudCiMediaTranscodeProTemplateResource_basic -v +func TestAccTencentCloudNeedFixCiMediaTranscodeProTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaTranscodeProTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaTranscodeProTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "id")), - }, - { - ResourceName: "tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", - ImportState: true, - ImportStateVerify: true, + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaTranscodeProTemplateExists("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "name", "transcode_pro_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "container.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "container.0.format", "mxf"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.codec", "xavc"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.profile", "XAVC-HD_422_10bit"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.width", "1920"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.height", "1080"), + // resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.interlaced", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.fps", "30000/1001"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "video.0.bitrate", "50000"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "audio.#", "1"), + // resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "audio.0.codec", "pcm_s24le"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "audio.0.remove", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.adj_dar_method", "scale"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.is_check_reso", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.reso_adj_method", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.is_check_video_bitrate", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.video_bitrate_adj_method", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.is_check_audio_bitrate", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.audio_bitrate_adj_method", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.delete_metadata", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", "trans_config.0.is_hdr2_sdr", "false"), + ), }, + // { + // ResourceName: "tencentcloud_ci_media_transcode_pro_template.media_transcode_pro_template", + // ImportState: true, + // ImportStateVerify: true, + // }, }, }) } -const testAccCiMediaTranscodeProTemplate = ` +func testAccCheckCiMediaTranscodeProTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_transcode_pro_template" { + continue + } -resource "tencentcloud_ci_media_transcode_pro_template" "media_transcode_pro_template" { - name = <nil> - container { - format = <nil> - clip_config { - duration = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) } + bucket := idSplit[0] + templateId := idSplit[1] - } - video { - codec = <nil> - profile = <nil> - width = <nil> - height = <nil> - interlaced = <nil> - fps = <nil> - bitrate = <nil> - rotate = <nil> + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } - } - time_interval { - start = <nil> - duration = <nil> + if res != nil { + return fmt.Errorf("ci media transcode pro template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} - } - audio { - codec = <nil> - remove = <nil> +func testAccCheckCiMediaTranscodeProTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} - } - trans_config { - adj_dar_method = <nil> - is_check_reso = <nil> - reso_adj_method = <nil> - is_check_video_bitrate = <nil> - video_bitrate_adj_method = <nil> - is_check_audio_bitrate = <nil> - audio_bitrate_adj_method = <nil> - is_check_video_fps = <nil> - video_fps_adj_method = <nil> - delete_metadata = <nil> - is_hdr2_sdr = <nil> + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media transcode pro template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media transcode pro template not found, Id: %v", rs.Primary.ID) + } + return nil + } +} + +const testAccCiMediaTranscodeProTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } +` + +const testAccCiMediaTranscodeProTemplate = testAccCiMediaTranscodeProTemplateVar + ` + +resource "tencentcloud_ci_media_transcode_pro_template" "media_transcode_pro_template" { + bucket = var.bucket + name = "transcode_pro_template" + container { + format = "mxf" + } + video { + codec = "xavc" + profile = "XAVC-HD_422_10bit" + width = "1920" + height = "1080" + interlaced = "true" + fps = "30000/1001" + bitrate = "50000" + } + time_interval { + start = "" + duration = "" + } + audio { + codec = "pcm_s24le" + remove = "true" + } + trans_config { + adj_dar_method = "scale" + is_check_reso = "false" + reso_adj_method = "1" + is_check_video_bitrate = "false" + video_bitrate_adj_method = "0" + is_check_audio_bitrate = "false" + audio_bitrate_adj_method = "0" + delete_metadata = "false" + is_hdr2_sdr = "false" + } } ` diff --git a/tencentcloud/resource_tc_ci_media_transcode_template_test.go b/tencentcloud/resource_tc_ci_media_transcode_template_test.go index 4bbd365cf7..b4e4ee936d 100644 --- a/tencentcloud/resource_tc_ci_media_transcode_template_test.go +++ b/tencentcloud/resource_tc_ci_media_transcode_template_test.go @@ -1,128 +1,215 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccTencentCloudCiMediaTranscodeTemplateResource_basic(t *testing.T) { +// go test -i; go test -test.run TestAccTencentCloudCiMediaTranscodeTemplateResource_basic -v +func TestAccTencentCloudNeedFixCiMediaTranscodeTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaTranscodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaTranscodeTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_transcode_template.media_transcode_template", "id")), - }, - { - ResourceName: "tencentcloud_ci_media_transcode_template.media_transcode_template", - ImportState: true, - ImportStateVerify: true, + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaTranscodeTemplateExists("tencentcloud_ci_media_transcode_template.media_transcode_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_transcode_template.media_transcode_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "name", "transcode_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "container.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "container.0.format", "mp4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.codec", "H.264"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.width", "1280"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.fps", "30"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.remove", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.profile", "high"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.bitrate", "1000"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.preset", "medium"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "video.0.long_short_mode", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "time_interval.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "time_interval.0.start", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "time_interval.0.duration", "60"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.codec", "aac"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.samplerate", "44100"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.bitrate", "128"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.channels", "4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.remove", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.keep_two_tracks", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio.0.switch_track", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.adj_dar_method", "scale"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.is_check_reso", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.reso_adj_method", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.is_check_video_bitrate", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.video_bitrate_adj_method", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.is_check_audio_bitrate", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.audio_bitrate_adj_method", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.delete_metadata", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.is_hdr2_sdr", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.hls_encrypt.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "trans_config.0.hls_encrypt.0.is_hls_encrypt", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.audio_source", "https://"+defaultCiBucket+".cos.ap-guangzhou.myqcloud.com/mp3%2Fnizhan-test.mp3"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.mix_mode", "Once"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.replace", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.0.enable_start_fadein", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.0.start_fadein_time", "3"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.0.enable_end_fadeout", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.0.end_fadeout_time", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.0.enable_bgm_fade", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_transcode_template.media_transcode_template", "audio_mix.0.effect_config.0.bgm_fade_time", "1.7"), + ), }, + // { + // ResourceName: "tencentcloud_ci_media_transcode_template.media_transcode_template", + // ImportState: true, + // ImportStateVerify: true, + // }, }, }) } -const testAccCiMediaTranscodeTemplate = ` +func testAccCheckCiMediaTranscodeTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_transcode_template" { + continue + } -resource "tencentcloud_ci_media_transcode_template" "media_transcode_template" { - name = "" - container { - format = "" - clip_config { - duration = "" + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) } + bucket := idSplit[0] + templateId := idSplit[1] - } - video { - codec = "" - width = "" - height = "" - fps = "" - remove = "" - profile = "" - bitrate = "" - crf = "" - gop = "" - preset = "" - bufsize = "" - maxrate = "" - pixfmt = "" - long_short_mode = "" - rotate = "" + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } - } - time_interval { - start = "" - duration = "" + if res != nil { + return fmt.Errorf("ci media transcode template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} - } - audio { - codec = "" - samplerate = "" - bitrate = "" - bitrate = "" - remove = "" - keep_two_tracks = "" - switch_track = "" - sample_format = "" +func testAccCheckCiMediaTranscodeTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} - } - trans_config { - adj_dar_method = "" - is_check_reso = "" - reso_adj_method = "" - is_check_video_bitrate = "" - video_bitrate_adj_method = "" - is_check_audio_bitrate = "" - audio_bitrate_adj_method = "" - is_check_video_fps = "" - video_fps_adj_method = "" - delete_metadata = "" - is_hdr2_sdr = "" - transcode_index = "" - hls_encrypt { - is_hls_encrypt = "" - uri_key = "" + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media transcode template %s is not found", re) } - dash_encrypt { - is_encrypt = "" - uri_key = "" + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") } - } - audio_mix { - audio_source = "" - mix_mode = "" - replace = "" - effect_config { - enable_start_fadein = "" - start_fadein_time = "" - enable_end_fadeout = "" - end_fadeout_time = "" - enable_bgm_fade = "" - bgm_fade_time = "" + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media transcode template not found, Id: %v", rs.Primary.ID) } + return nil + } +} + +const testAccCiMediaTranscodeTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } - audio_mix_array { - audio_source = "" - mix_mode = "" - replace = "" +` + +const testAccCiMediaTranscodeTemplate = testAccCiMediaTranscodeTemplateVar + ` + +resource "tencentcloud_ci_media_transcode_template" "media_transcode_template" { + bucket = var.bucket + name = "transcode_template" + container { + format = "mp4" + } + video { + codec = "H.264" + width = "1280" + fps = "30" + remove = "false" + profile = "high" + bitrate = "1000" + preset = "medium" + long_short_mode = "false" + } + time_interval { + start = "0" + duration = "60" + } + audio { + codec = "aac" + samplerate = "44100" + bitrate = "128" + channels = "4" + remove = "false" + keep_two_tracks = "false" + switch_track = "false" + sample_format = "" + } + trans_config { + adj_dar_method = "scale" + is_check_reso = "false" + reso_adj_method = "1" + is_check_video_bitrate = "false" + video_bitrate_adj_method = "0" + is_check_audio_bitrate = "false" + audio_bitrate_adj_method = "0" + delete_metadata = "false" + is_hdr2_sdr = "false" + hls_encrypt { + is_hls_encrypt = "true" + # uri_key = "" + } + } + audio_mix { + audio_source = "https://` + defaultCiBucket + `.cos.ap-guangzhou.myqcloud.com/mp3%2Fnizhan-test.mp3" + mix_mode = "Once" + replace = "true" effect_config { - enable_start_fadein = "" - start_fadein_time = "" - enable_end_fadeout = "" - end_fadeout_time = "" - enable_bgm_fade = "" - bgm_fade_time = "" + enable_start_fadein = "true" + start_fadein_time = "3" + enable_end_fadeout = "false" + end_fadeout_time = "0" + enable_bgm_fade = "true" + bgm_fade_time = "1.7" } - + } } -} ` diff --git a/tencentcloud/resource_tc_ci_media_tts_template.go b/tencentcloud/resource_tc_ci_media_tts_template.go index b79a8f97ba..ad60a361a4 100644 --- a/tencentcloud/resource_tc_ci_media_tts_template.go +++ b/tencentcloud/resource_tc_ci_media_tts_template.go @@ -180,6 +180,8 @@ func resourceTencentCloudCiMediaTtsTemplateRead(d *schema.ResourceData, meta int return err } + _ = d.Set("bucket", bucket) + if template == nil { d.SetId("") return fmt.Errorf("resource `track` %s does not exist", d.Id()) diff --git a/tencentcloud/resource_tc_ci_media_tts_template_test.go b/tencentcloud/resource_tc_ci_media_tts_template_test.go index e4b1aa921a..50de9830c7 100644 --- a/tencentcloud/resource_tc_ci_media_tts_template_test.go +++ b/tencentcloud/resource_tc_ci_media_tts_template_test.go @@ -1,22 +1,37 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) +// go test -i; go test -test.run TestAccTencentCloudCiMediaTtsTemplateResource_basic -v func TestAccTencentCloudCiMediaTtsTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaTtsTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaTtsTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_tts_template.media_tts_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaTtsTemplateExists("tencentcloud_ci_media_tts_template.media_tts_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_tts_template.media_tts_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "name", "tts_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "mode", "Asyc"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "codec", "pcm"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "voice_type", "ruxue"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "volume", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_tts_template.media_tts_template", "speed", "100"), + ), }, { ResourceName: "tencentcloud_ci_media_tts_template.media_tts_template", @@ -27,10 +42,78 @@ func TestAccTencentCloudCiMediaTtsTemplateResource_basic(t *testing.T) { }) } -const testAccCiMediaTtsTemplate = ` +func testAccCheckCiMediaTtsTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_tts_template" { + continue + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media tts template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaTtsTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media tts template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media tts template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaTtsTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" + } +` + +const testAccCiMediaTtsTemplate = testAccCiMediaTtsTemplateVar + ` resource "tencentcloud_ci_media_tts_template" "media_tts_template" { - bucket = "terraform-ci-1308919341" + bucket = var.bucket name = "tts_template" mode = "Asyc" codec = "pcm" diff --git a/tencentcloud/resource_tc_ci_media_video_montage_template.go b/tencentcloud/resource_tc_ci_media_video_montage_template.go index 662e4c30e1..7f8c6a2ebb 100644 --- a/tencentcloud/resource_tc_ci_media_video_montage_template.go +++ b/tencentcloud/resource_tc_ci_media_video_montage_template.go @@ -434,6 +434,8 @@ func resourceTencentCloudCiMediaVideoMontageTemplateRead(d *schema.ResourceData, return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if template.Name != "" { _ = d.Set("name", template.Name) } diff --git a/tencentcloud/resource_tc_ci_media_video_montage_template_test.go b/tencentcloud/resource_tc_ci_media_video_montage_template_test.go index 80038d9f3d..652569ab8d 100644 --- a/tencentcloud/resource_tc_ci_media_video_montage_template_test.go +++ b/tencentcloud/resource_tc_ci_media_video_montage_template_test.go @@ -1,22 +1,81 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_video_montage_template + resource.AddTestSweepers("tencentcloud_ci_media_video_montage_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_video_montage_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "video_montage_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaVideoMontageTemplateResource_basic -v func TestAccTencentCloudCiMediaVideoMontageTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaVideoMontageTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaVideoMontageTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaVideoMontageTemplateExists("tencentcloud_ci_media_video_montage_template.media_video_montage_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "name", "video_montage_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "duration", "10.5"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio.0.codec", "aac"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio.0.samplerate", "44100"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio.0.bitrate", "128"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio.0.channels", "4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio.0.remove", "false"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "video.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "video.0.codec", "H.264"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "video.0.width", "1280"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "video.0.bitrate", "1000"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "video.0.fps", "25"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "container.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "container.0.format", "mp4"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio_mix.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio_mix.0.audio_source", "https://"+defaultCiBucket+".cos.ap-guangzhou.myqcloud.com/mp3%2Fnizhan-test.mp3"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio_mix.0.mix_mode", "Once"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_montage_template.media_video_montage_template", "audio_mix.0.replace", "true"), + ), }, { ResourceName: "tencentcloud_ci_media_video_montage_template.media_video_montage_template", @@ -27,48 +86,104 @@ func TestAccTencentCloudCiMediaVideoMontageTemplateResource_basic(t *testing.T) }) } -const testAccCiMediaVideoMontageTemplate = ` +func testAccCheckCiMediaVideoMontageTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_video_montage_template" { + continue + } -resource "tencentcloud_ci_media_video_montage_template" "media_video_montage_template" { - name = <nil> - duration = <nil> - audio { - codec = <nil> - samplerate = <nil> - bitrate = <nil> - channels = <nil> - remove = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] - } - video { - codec = <nil> - width = <nil> - height = <nil> - bitrate = <nil> - fps = <nil> - crf = <nil> - remove = <nil> - rotate = <nil> + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } - } - container { - format = <nil> + if res != nil { + return fmt.Errorf("ci media video montage template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} - } - audio_mix { - audio_source = <nil> - mix_mode = <nil> - replace = <nil> - effect_config { - enable_start_fadein = <nil> - start_fadein_time = <nil> - enable_end_fadeout = <nil> - end_fadeout_time = <nil> - enable_bgm_fade = <nil> - bgm_fade_time = <nil> +func testAccCheckCiMediaVideoMontageTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media video montage template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err } + if result == nil { + return fmt.Errorf("ci media video montage template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaVideoMontageTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } +` + +const testAccCiMediaVideoMontageTemplate = testAccCiMediaVideoMontageTemplateVar + ` + +resource "tencentcloud_ci_media_video_montage_template" "media_video_montage_template" { + bucket = var.bucket + name = "video_montage_template" + duration = "10.5" + audio { + codec = "aac" + samplerate = "44100" + bitrate = "128" + channels = "4" + remove = "false" + } + video { + codec = "H.264" + width = "1280" + height = "" + bitrate = "1000" + fps = "25" + crf = "" + remove = "" + } + container { + format = "mp4" + } + audio_mix { + audio_source = "https://` + defaultCiBucket + `.cos.ap-guangzhou.myqcloud.com/mp3%2Fnizhan-test.mp3" + mix_mode = "Once" + replace = "true" + } } ` diff --git a/tencentcloud/resource_tc_ci_media_video_process_template.go b/tencentcloud/resource_tc_ci_media_video_process_template.go index 607945a437..3dd9ce9186 100644 --- a/tencentcloud/resource_tc_ci_media_video_process_template.go +++ b/tencentcloud/resource_tc_ci_media_video_process_template.go @@ -224,6 +224,8 @@ func resourceTencentCloudCiMediaVideoProcessTemplateRead(d *schema.ResourceData, return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if template.Name != "" { _ = d.Set("name", template.Name) } diff --git a/tencentcloud/resource_tc_ci_media_video_process_template_test.go b/tencentcloud/resource_tc_ci_media_video_process_template_test.go index 72d6e49cff..95a3d0000e 100644 --- a/tencentcloud/resource_tc_ci_media_video_process_template_test.go +++ b/tencentcloud/resource_tc_ci_media_video_process_template_test.go @@ -1,22 +1,67 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_video_process_template + resource.AddTestSweepers("tencentcloud_ci_media_video_process_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_video_process_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "video_process_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaVideoProcessTemplateResource_basic -v func TestAccTencentCloudCiMediaVideoProcessTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaVideoProcessTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaVideoProcessTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_video_process_template.media_video_process_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaVideoProcessTemplateExists("tencentcloud_ci_media_video_process_template.media_video_process_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_video_process_template.media_video_process_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_process_template.media_video_process_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_process_template.media_video_process_template", "name", "video_process_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_process_template.media_video_process_template", "color_enhance.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_process_template.media_video_process_template", "color_enhance.0.enable", "true"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_process_template.media_video_process_template", "ms_sharpen.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_video_process_template.media_video_process_template", "ms_sharpen.0.enable", "false"), + ), }, { ResourceName: "tencentcloud_ci_media_video_process_template.media_video_process_template", @@ -27,22 +72,85 @@ func TestAccTencentCloudCiMediaVideoProcessTemplateResource_basic(t *testing.T) }) } -const testAccCiMediaVideoProcessTemplate = ` +func testAccCheckCiMediaVideoProcessTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_video_process_template" { + continue + } -resource "tencentcloud_ci_media_video_process_template" "media_video_process_template" { - name = <nil> - color_enhance { - enable = <nil> - contrast = <nil> - correction = <nil> - saturation = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] - } - ms_sharpen { - enable = <nil> - sharpen_level = <nil> + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media video process template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaVideoProcessTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media video process template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media video process template not found, Id: %v", rs.Primary.ID) + } + return nil + } +} + +const testAccCiMediaVideoProcessTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } +` + +const testAccCiMediaVideoProcessTemplate = testAccCiMediaVideoProcessTemplateVar + ` + +resource "tencentcloud_ci_media_video_process_template" "media_video_process_template" { + bucket = var.bucket + name = "video_process_template" + color_enhance { + enable = "true" + } + ms_sharpen { + enable = "false" + } } ` diff --git a/tencentcloud/resource_tc_ci_media_voice_separate_template.go b/tencentcloud/resource_tc_ci_media_voice_separate_template.go index 1f7c06795f..b917f5f9d5 100644 --- a/tencentcloud/resource_tc_ci_media_voice_separate_template.go +++ b/tencentcloud/resource_tc_ci_media_voice_separate_template.go @@ -196,6 +196,8 @@ func resourceTencentCloudCiMediaVoiceSeparateTemplateRead(d *schema.ResourceData return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if template.Name != "" { _ = d.Set("name", template.Name) } diff --git a/tencentcloud/resource_tc_ci_media_voice_separate_template_test.go b/tencentcloud/resource_tc_ci_media_voice_separate_template_test.go index c8f5f57db3..36373ba963 100644 --- a/tencentcloud/resource_tc_ci_media_voice_separate_template_test.go +++ b/tencentcloud/resource_tc_ci_media_voice_separate_template_test.go @@ -1,22 +1,69 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_voice_separate_template + resource.AddTestSweepers("tencentcloud_ci_media_voice_separate_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_voice_separate_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "voice_separate_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaVoiceSeparateTemplateResource_basic -v func TestAccTencentCloudCiMediaVoiceSeparateTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaVoiceSeparateTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaVoiceSeparateTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaVoiceSeparateTemplateExists("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "name", "voice_separate_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "audio_mode", "IsAudio"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "audio_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "audio_config.0.codec", "aac"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "audio_config.0.samplerate", "44100"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "audio_config.0.bitrate", "128"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", "audio_config.0.channels", "4"), + ), }, { ResourceName: "tencentcloud_ci_media_voice_separate_template.media_voice_separate_template", @@ -27,18 +74,86 @@ func TestAccTencentCloudCiMediaVoiceSeparateTemplateResource_basic(t *testing.T) }) } -const testAccCiMediaVoiceSeparateTemplate = ` +func testAccCheckCiMediaVoiceSeparateTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_voice_separate_template" { + continue + } -resource "tencentcloud_ci_media_voice_separate_template" "media_voice_separate_template" { - name = <nil> - audio_mode = <nil> - audio_config { - codec = <nil> - samplerate = <nil> - bitrate = <nil> - channels = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] - } + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if res != nil { + return fmt.Errorf("ci media video separate template still exist, Id: %v\n", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckCiMediaVoiceSeparateTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media video separate template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media video separate template not found, Id: %v", rs.Primary.ID) + } + + return nil + } } +const testAccCiMediaVoiceSeparateTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" + } +` + +const testAccCiMediaVoiceSeparateTemplate = testAccCiMediaVoiceSeparateTemplateVar + ` + +resource "tencentcloud_ci_media_voice_separate_template" "media_voice_separate_template" { + bucket = var.bucket + name = "voice_separate_template" + audio_mode = "IsAudio" + audio_config { + codec = "aac" + samplerate = "44100" + bitrate = "128" + channels = "4" + } + } + ` diff --git a/tencentcloud/resource_tc_ci_media_watermark_template.go b/tencentcloud/resource_tc_ci_media_watermark_template.go index 963bc11a00..0c10fe6728 100644 --- a/tencentcloud/resource_tc_ci_media_watermark_template.go +++ b/tencentcloud/resource_tc_ci_media_watermark_template.go @@ -5,31 +5,31 @@ Example Usage ```hcl resource "tencentcloud_ci_media_watermark_template" "media_watermark_template" { - name = "" + bucket = "terraform-ci-1308919341" + name = "watermark_template" watermark { - type = "" - pos = "" - loc_mode = "" - dx = "" - dy = "" - start_time = "" - end_time = "" - image { - url = "" - mode = "" - width = "" - height = "" - transparency = "" - background = "" - } + type = "Text" + pos = "TopRight" + loc_mode = "Absolute" + dx = "128" + dy = "128" + start_time = "0" + end_time = "100.5" + # image { + # url = "" + # mode = "" + # width = "" + # height = "" + # transparency = "" + # background = "" + # } text { - font_size = "" - font_type = "" - font_color = "" - transparency = "" - text = "" + font_size = "30" + font_type = "simfang.ttf" + font_color = "0xF0F8F0" + transparency = "30" + text = "watermark-content" } - } } ``` @@ -344,6 +344,8 @@ func resourceTencentCloudCiMediaWatermarkTemplateRead(d *schema.ResourceData, me return fmt.Errorf("resource `track` %s does not exist", d.Id()) } + _ = d.Set("bucket", bucket) + if mediaWatermarkTemplate.Name != "" { _ = d.Set("name", mediaWatermarkTemplate.Name) } diff --git a/tencentcloud/resource_tc_ci_media_watermark_template_test.go b/tencentcloud/resource_tc_ci_media_watermark_template_test.go index f32185c8a8..c569b1a22a 100644 --- a/tencentcloud/resource_tc_ci_media_watermark_template_test.go +++ b/tencentcloud/resource_tc_ci_media_watermark_template_test.go @@ -1,22 +1,77 @@ package tencentcloud import ( + "context" + "fmt" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/tencentyun/cos-go-sdk-v5" ) +func init() { + // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_ci_media_watermark_template + resource.AddTestSweepers("tencentcloud_ci_media_watermark_template", &resource.Sweeper{ + Name: "tencentcloud_ci_media_watermark_template", + F: func(r string) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + cli, _ := sharedClientForRegion(r) + client := cli.(*TencentCloudClient).apiV3Conn + service := CiService{client: client} + + response, _, err := service.client.UseCiClient(defaultCiBucket).CI.DescribeMediaTemplate(ctx, &cos.DescribeMediaTemplateOptions{ + Name: "watermark_template", + }) + if err != nil { + return err + } + + for _, v := range response.TemplateList { + err := service.DeleteCiMediaTemplateById(ctx, defaultCiBucket, v.TemplateId) + if err != nil { + continue + } + } + + return nil + }, + }) +} + +// go test -i; go test -test.run TestAccTencentCloudCiMediaWatermarkTemplateResource_basic -v func TestAccTencentCloudCiMediaWatermarkTemplateResource_basic(t *testing.T) { t.Parallel() + resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCiMediaWatermarkTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCiMediaWatermarkTemplate, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ci_media_watermark_template.media_watermark_template", "id")), + Check: resource.ComposeTestCheckFunc( + testAccCheckCiMediaWatermarkTemplateExists("tencentcloud_ci_media_watermark_template.media_watermark_template"), + resource.TestCheckResourceAttrSet("tencentcloud_ci_media_watermark_template.media_watermark_template", "id"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "bucket", defaultCiBucket), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "name", "watermark_template"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.type", "Text"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.pos", "TopRight"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.loc_mode", "Absolute"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.dx", "128"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.dy", "128"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.start_time", "0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.end_time", "100.5"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.text.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.text.0.font_size", "30"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.text.0.font_type", "simfang.ttf"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.text.0.font_color", "0xF0F8F0"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.text.0.transparency", "30"), + resource.TestCheckResourceAttr("tencentcloud_ci_media_watermark_template.media_watermark_template", "watermark.0.text.0.text", "watermark-content"), + ), }, { ResourceName: "tencentcloud_ci_media_watermark_template.media_watermark_template", @@ -27,40 +82,95 @@ func TestAccTencentCloudCiMediaWatermarkTemplateResource_basic(t *testing.T) { }) } -const testAccCiMediaWatermarkTemplate = ` +func testAccCheckCiMediaWatermarkTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_ci_media_voice_separate_template" { + continue + } -resource "tencentcloud_ci_media_watermark_template" "media_watermark_template" { - name = <nil> - watermark { - type = <nil> - pos = <nil> - loc_mode = <nil> - dx = <nil> - dy = <nil> - start_time = <nil> - end_time = <nil> - slide_config { - slide_mode = <nil> - x_slide_speed = <nil> - x_slide_speed = <nil> + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) } - image { - url = <nil> - mode = <nil> - width = <nil> - height = <nil> - transparency = <nil> - background = <nil> + bucket := idSplit[0] + templateId := idSplit[1] + + res, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err } - text { - font_size = <nil> - font_type = <nil> - font_color = <nil> - transparency = <nil> - text = <nil> + + if res != nil { + return fmt.Errorf("ci media video separate template still exist, Id: %v\n", rs.Primary.ID) } + } + return nil +} +func testAccCheckCiMediaWatermarkTemplateExists(re string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := CiService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + + rs, ok := s.RootModule().Resources[re] + if !ok { + return fmt.Errorf("ci media video separate template %s is not found", re) + } + if rs.Primary.ID == "" { + return fmt.Errorf(" id is not set") + } + + idSplit := strings.Split(rs.Primary.ID, FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", rs.Primary.ID) + } + bucket := idSplit[0] + templateId := idSplit[1] + + result, err := service.DescribeCiMediaTemplateById(ctx, bucket, templateId) + if err != nil { + return err + } + + if result == nil { + return fmt.Errorf("ci media video separate template not found, Id: %v", rs.Primary.ID) + } + + return nil + } +} + +const testAccCiMediaWatermarkTemplateVar = ` +variable "bucket" { + default = "` + defaultCiBucket + `" } +` + +const testAccCiMediaWatermarkTemplate = testAccCiMediaWatermarkTemplateVar + ` + +resource "tencentcloud_ci_media_watermark_template" "media_watermark_template" { + bucket = var.bucket + name = "watermark_template" + watermark { + type = "Text" + pos = "TopRight" + loc_mode = "Absolute" + dx = "128" + dy = "128" + start_time = "0" + end_time = "100.5" + text { + font_size = "30" + font_type = "simfang.ttf" + font_color = "0xF0F8F0" + transparency = "30" + text = "watermark-content" + } + } } ` diff --git a/tencentcloud/service_tencentcloud_ci.go b/tencentcloud/service_tencentcloud_ci.go index e23714731c..8a862f6c96 100644 --- a/tencentcloud/service_tencentcloud_ci.go +++ b/tencentcloud/service_tencentcloud_ci.go @@ -6,14 +6,13 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" "github.com/tencentyun/cos-go-sdk-v5" - ci "github.com/tencentyun/cos-go-sdk-v5" ) type CiService struct { client *connectivity.TencentCloudClient } -func (me *CiService) DescribeCiBucketById(ctx context.Context, bucket string) (serviceResult *ci.CIServiceResult, errRet error) { +func (me *CiService) DescribeCiBucketById(ctx context.Context, bucket string) (serviceResult *cos.CIServiceResult, errRet error) { logId := getLogId(ctx) defer func() { @@ -52,7 +51,7 @@ func (me *CiService) DeleteCiBucketById(ctx context.Context, bucket string) (err return } -func (me *CiService) DescribeCiBucketPicStyleById(ctx context.Context, bucket, styleName string) (styleRule *ci.StyleRule, errRet error) { +func (me *CiService) DescribeCiBucketPicStyleById(ctx context.Context, bucket, styleName string) (styleRule *cos.StyleRule, errRet error) { logId := getLogId(ctx) defer func() { @@ -61,7 +60,7 @@ func (me *CiService) DescribeCiBucketPicStyleById(ctx context.Context, bucket, s } }() - styleResult, response, err := me.client.UsePicClient(bucket).CI.GetStyle(ctx, &ci.GetStyleOptions{ + styleResult, response, err := me.client.UsePicClient(bucket).CI.GetStyle(ctx, &cos.GetStyleOptions{ StyleName: styleName, }) if err != nil { @@ -93,7 +92,7 @@ func (me *CiService) DeleteCiBucketPicStyleById(ctx context.Context, bucket, sty } }() - response, err := me.client.UsePicClient(bucket).CI.DeleteStyle(ctx, &ci.DeleteStyleOptions{ + response, err := me.client.UsePicClient(bucket).CI.DeleteStyle(ctx, &cos.DeleteStyleOptions{ StyleName: styleName, }) if err != nil { @@ -105,7 +104,7 @@ func (me *CiService) DeleteCiBucketPicStyleById(ctx context.Context, bucket, sty return } -func (me *CiService) DescribeCiHotLinkById(ctx context.Context, bucket string) (hotLink *ci.HotLinkResult, errRet error) { +func (me *CiService) DescribeCiHotLinkById(ctx context.Context, bucket string) (hotLink *cos.HotLinkResult, errRet error) { logId := getLogId(ctx) defer func() { @@ -131,7 +130,7 @@ func (me *CiService) DescribeCiHotLinkById(ctx context.Context, bucket string) ( return } -func (me *CiService) DescribeCiMediaTemplateById(ctx context.Context, bucket, templateId string) (mediaSnapshotTemplate *ci.Template, errRet error) { +func (me *CiService) DescribeCiMediaTemplateById(ctx context.Context, bucket, templateId string) (mediaSnapshotTemplate *cos.Template, errRet error) { logId := getLogId(ctx) defer func() { @@ -147,7 +146,7 @@ func (me *CiService) DescribeCiMediaTemplateById(ctx context.Context, bucket, te errRet = err return } - log.Printf("[DEBUG]%s api[%s] success, request body [%v], response body [%v]\n", logId, "DescribeMediaTemplate", bucket, response) + log.Printf("[DEBUG]%s api[%s] success, request body [%v, %v], response body [%+v]\n", logId, "DescribeMediaTemplate", bucket, templateId, response) if len(response.TemplateList) < 1 { return @@ -171,7 +170,7 @@ func (me *CiService) DeleteCiMediaTemplateById(ctx context.Context, bucket, temp errRet = err return } - log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, "DeleteMediaTemplate", bucket, response) + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%+v]\n", logId, "DeleteMediaTemplate", bucket, response) return } @@ -220,7 +219,7 @@ func (me *CiService) OpenCiOriginalImageProtectionById(ctx context.Context, buck return } -func (me *CiService) GetCiOriginalImageProtectionById(ctx context.Context, bucket string) (*ci.OriginProtectResult, error) { +func (me *CiService) GetCiOriginalImageProtectionById(ctx context.Context, bucket string) (*cos.OriginProtectResult, error) { var errRet error logId := getLogId(ctx) @@ -241,7 +240,7 @@ func (me *CiService) GetCiOriginalImageProtectionById(ctx context.Context, bucke } log.Printf("[DEBUG]%s api[%s] success, request body [%s]\n", logId, "GetCIOriginalImageProtection", bucket) - return resRaw.(*ci.OriginProtectResult), nil + return resRaw.(*cos.OriginProtectResult), nil } func (me *CiService) CloseCiGuetzliById(ctx context.Context, bucket string) (errRet error) { @@ -288,7 +287,7 @@ func (me *CiService) OpenCiGuetzliById(ctx context.Context, bucket string) (errR return } -func (me *CiService) GetCiGuetzliById(ctx context.Context, bucket string) (*ci.GetGuetzliResult, error) { +func (me *CiService) GetCiGuetzliById(ctx context.Context, bucket string) (*cos.GetGuetzliResult, error) { var errRet error logId := getLogId(ctx) @@ -309,5 +308,5 @@ func (me *CiService) GetCiGuetzliById(ctx context.Context, bucket string) (*ci.G } log.Printf("[DEBUG]%s api[%s] success, request body [%s]\n", logId, "GetCIGuetzli", bucket) - return resRaw.(*ci.GetGuetzliResult), nil + return resRaw.(*cos.GetGuetzliResult), nil } diff --git a/website/docs/r/ci_media_animation_template.html.markdown b/website/docs/r/ci_media_animation_template.html.markdown index 02f4dddc8a..67a6f8f071 100644 --- a/website/docs/r/ci_media_animation_template.html.markdown +++ b/website/docs/r/ci_media_animation_template.html.markdown @@ -77,11 +77,3 @@ In addition to all arguments above, the following attributes are exported: -## Import - -ci media_animation_template can be imported using the bucket#templateId, e.g. - -``` -terraform import tencentcloud_ci_media_animation_template.media_animation_template terraform-ci-xxxxxx#t18210645f96564eaf80e86b1f58c20152 -``` - diff --git a/website/docs/r/ci_media_concat_template.html.markdown b/website/docs/r/ci_media_concat_template.html.markdown index 39f0902952..7d83404401 100644 --- a/website/docs/r/ci_media_concat_template.html.markdown +++ b/website/docs/r/ci_media_concat_template.html.markdown @@ -53,7 +53,7 @@ resource "tencentcloud_ci_media_concat_template" "media_concat_template" { enable_start_fadein = "true" start_fadein_time = "3" enable_end_fadeout = "false" - end_fadeout_time = "0" + end_fadeout_time = "0.1" enable_bgm_fade = "true" bgm_fade_time = "1.7" } diff --git a/website/docs/r/ci_media_snapshot_template.html.markdown b/website/docs/r/ci_media_snapshot_template.html.markdown index 79dcd581f9..c35d22239f 100644 --- a/website/docs/r/ci_media_snapshot_template.html.markdown +++ b/website/docs/r/ci_media_snapshot_template.html.markdown @@ -16,28 +16,16 @@ Provides a resource to create a ci media_snapshot_template ```hcl resource "tencentcloud_ci_media_snapshot_template" "media_snapshot_template" { bucket = "terraform-ci-xxxxxx" - name = "snapshot_template" + name = "snapshot_template_test" snapshot { - # mode = "" - # start = "" - # time_interval = "" - count = "10" - # width = "" - # height = "" - # ci_param = "" - # is_check_count = "" - # is_check_black = "" - # black_level = "" - # pixel_black_threshold = "" - # snapshot_out_mode = "" + count = "10" + snapshot_out_mode = "SnapshotAndSprite" sprite_snapshot_config { - # cell_width = "" - # cell_height = "" - # padding = "" - # margin = "" - color = "0xF0F8FF" + color = "White" columns = "10" lines = "10" + margin = "10" + padding = "10" } } } diff --git a/website/docs/r/ci_media_watermark_template.html.markdown b/website/docs/r/ci_media_watermark_template.html.markdown index 5202f688c4..a8a2eea0bb 100644 --- a/website/docs/r/ci_media_watermark_template.html.markdown +++ b/website/docs/r/ci_media_watermark_template.html.markdown @@ -15,31 +15,31 @@ Provides a resource to create a ci media_watermark_template ```hcl resource "tencentcloud_ci_media_watermark_template" "media_watermark_template" { - name = "" + bucket = "terraform-ci-1308919341" + name = "watermark_template" watermark { - type = "" - pos = "" - loc_mode = "" - dx = "" - dy = "" - start_time = "" - end_time = "" - image { - url = "" - mode = "" - width = "" - height = "" - transparency = "" - background = "" - } + type = "Text" + pos = "TopRight" + loc_mode = "Absolute" + dx = "128" + dy = "128" + start_time = "0" + end_time = "100.5" + # image { + # url = "" + # mode = "" + # width = "" + # height = "" + # transparency = "" + # background = "" + # } text { - font_size = "" - font_type = "" - font_color = "" - transparency = "" - text = "" + font_size = "30" + font_type = "simfang.ttf" + font_color = "0xF0F8F0" + transparency = "30" + text = "watermark-content" } - } } ```