Skip to content

Commit a1909e5

Browse files
authored
Feat/support css watermark rule (#2156)
* feat:support css watermark_rule * feat:support css watermark_rule * add e2e * 1.fix golangci-lint issues 2.add changelog
1 parent 49af7ad commit a1909e5

File tree

13 files changed

+8241
-2363
lines changed

13 files changed

+8241
-2363
lines changed

.changelog/2156.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_css_watermark_rule_attachment
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ require (
6060
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.514
6161
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563
6262
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729
63-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.535
63+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.756
6464
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672
6565
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.651
6666
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.734

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729 h1:
902902
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729/go.mod h1:lLoyD7Z6OQQDFxDGGTe8wmirhUFZ36l5OaxzP75853Y=
903903
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.535 h1:hSwG4ZbcP2Ht+AWHI81EMCvJdDTyTT7zP/qjOe/VcZg=
904904
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.535/go.mod h1:mYKqy56uKaI0aPySeUByymvwDerPTmdMJQPQKC/NU1s=
905+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.756 h1:uwlWCqnsEXlafj/SixOJyyJojgEsjxkGtVOFGRhKk5I=
906+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.756/go.mod h1:MWQuFxqztpy6xLJ/XXuAxjBXcjpCLbyN42P3eub1yEs=
905907
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672 h1:sR3MyM9RBw1PNRdWoBrtK+2M9Qbb0i6DfQSrvZ4/4os=
906908
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672/go.mod h1:o3rBKhtfIJfw4BG22M0CQVLQAc0WqIsbyRI/EW52Ka0=
907909
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.651 h1:Ohb58H6gIlTcd73CF+goUlEdNJ2CYkYUHTYxV/M4UL4=

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ Real User Monitoring(RUM)
13221322
Cloud Streaming Services(CSS)
13231323
Resource
13241324
tencentcloud_css_watermark
1325+
tencentcloud_css_watermark_rule_attachment
13251326
tencentcloud_css_pull_stream_task
13261327
tencentcloud_css_live_transcode_template
13271328
tencentcloud_css_live_transcode_rule_attachment
@@ -2893,6 +2894,7 @@ func Provider() *schema.Provider {
28932894
"tencentcloud_tdcpg_cluster": resourceTencentCloudTdcpgCluster(),
28942895
"tencentcloud_tdcpg_instance": resourceTencentCloudTdcpgInstance(),
28952896
"tencentcloud_css_watermark": resourceTencentCloudCssWatermark(),
2897+
"tencentcloud_css_watermark_rule_attachment": resourceTencentCloudCssWatermarkRuleAttachment(),
28962898
"tencentcloud_css_pull_stream_task": resourceTencentCloudCssPullStreamTask(),
28972899
"tencentcloud_css_live_transcode_template": resourceTencentCloudCssLiveTranscodeTemplate(),
28982900
"tencentcloud_css_live_transcode_rule_attachment": resourceTencentCloudCssLiveTranscodeRuleAttachment(),
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/*
2+
Provides a resource to create a css watermark_rule
3+
4+
Example Usage
5+
6+
Binding watermark rule with a css stream
7+
8+
```hcl
9+
resource "tencentcloud_css_pull_stream_task" "example" {
10+
stream_name = "tf_example_stream_name"
11+
source_type = "PullLivePushLive"
12+
source_urls = ["rtmp://xxx.com/live/stream"]
13+
domain_name = "test.domain.com"
14+
app_name = "live"
15+
start_time = "2023-09-27T10:28:21Z"
16+
end_time = "2023-09-27T17:28:21Z"
17+
operator = "tf_admin"
18+
comment = "This is a e2e test case."
19+
}
20+
21+
resource "tencentcloud_css_watermark" "example" {
22+
picture_url = "picture_url"
23+
watermark_name = "watermark_name"
24+
x_position = 0
25+
y_position = 0
26+
width = 0
27+
height = 0
28+
}
29+
30+
resource "tencentcloud_css_watermark_rule_attachment" "watermark_rule_attachment" {
31+
domain_name = tencentcloud_css_pull_stream_task.example.domain_name
32+
app_name = tencentcloud_css_pull_stream_task.example.app_name
33+
stream_name = tencentcloud_css_pull_stream_task.example.stream_name
34+
template_id = tencentcloud_css_watermark.example.id
35+
}
36+
```
37+
38+
Import
39+
40+
css watermark_rule_attachment can be imported using the id, e.g.
41+
42+
```
43+
terraform import tencentcloud_css_watermark_rule_attachment.watermark_rule domain_name#app_name#stream_name#template_id
44+
```
45+
*/
46+
package tencentcloud
47+
48+
import (
49+
"context"
50+
"fmt"
51+
"log"
52+
"strings"
53+
54+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
55+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
56+
css "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
57+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
58+
)
59+
60+
func resourceTencentCloudCssWatermarkRuleAttachment() *schema.Resource {
61+
return &schema.Resource{
62+
Create: resourceTencentCloudCssWatermarkRuleAttachmentCreate,
63+
Read: resourceTencentCloudCssWatermarkRuleAttachmentRead,
64+
Delete: resourceTencentCloudCssWatermarkRuleAttachmentDelete,
65+
Importer: &schema.ResourceImporter{
66+
State: schema.ImportStatePassthrough,
67+
},
68+
Schema: map[string]*schema.Schema{
69+
"domain_name": {
70+
Required: true,
71+
ForceNew: true,
72+
Type: schema.TypeString,
73+
Description: "rule domain name.",
74+
},
75+
76+
"app_name": {
77+
Required: true,
78+
ForceNew: true,
79+
Type: schema.TypeString,
80+
Description: "rule app name.",
81+
},
82+
83+
"stream_name": {
84+
Required: true,
85+
ForceNew: true,
86+
Type: schema.TypeString,
87+
Description: "rule stream name.",
88+
},
89+
90+
"template_id": {
91+
Required: true,
92+
ForceNew: true,
93+
Type: schema.TypeInt,
94+
Description: "The template Id can be acquired by the Id of `tencentcloud_css_watermark`.",
95+
},
96+
97+
"create_time": {
98+
Computed: true,
99+
Type: schema.TypeString,
100+
Description: "create time.",
101+
},
102+
103+
"update_time": {
104+
Computed: true,
105+
Type: schema.TypeString,
106+
Description: "update time.",
107+
},
108+
},
109+
}
110+
}
111+
112+
func resourceTencentCloudCssWatermarkRuleAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
113+
defer logElapsed("resource.tencentcloud_css_watermark_rule_attachment.create")()
114+
defer inconsistentCheck(d, meta)()
115+
116+
logId := getLogId(contextNil)
117+
118+
var (
119+
request = css.NewCreateLiveWatermarkRuleRequest()
120+
domainName string
121+
appName string
122+
streamName string
123+
templateId int
124+
)
125+
if v, ok := d.GetOk("domain_name"); ok {
126+
domainName = v.(string)
127+
request.DomainName = helper.String(domainName)
128+
}
129+
130+
if v, ok := d.GetOk("app_name"); ok {
131+
appName = v.(string)
132+
request.AppName = helper.String(appName)
133+
}
134+
135+
if v, ok := d.GetOk("stream_name"); ok {
136+
streamName = v.(string)
137+
request.StreamName = helper.String(streamName)
138+
}
139+
140+
if v, ok := d.GetOkExists("template_id"); ok {
141+
templateId = v.(int)
142+
request.TemplateId = helper.IntInt64(templateId)
143+
}
144+
145+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
146+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseCssClient().CreateLiveWatermarkRule(request)
147+
if e != nil {
148+
return retryError(e)
149+
} else {
150+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
151+
}
152+
return nil
153+
})
154+
if err != nil {
155+
log.Printf("[CRITAL]%s create css watermarkRule failed, reason:%+v", logId, err)
156+
return err
157+
}
158+
159+
d.SetId(strings.Join([]string{domainName, appName, streamName, helper.IntToStr(templateId)}, FILED_SP))
160+
161+
return resourceTencentCloudCssWatermarkRuleAttachmentRead(d, meta)
162+
}
163+
164+
func resourceTencentCloudCssWatermarkRuleAttachmentRead(d *schema.ResourceData, meta interface{}) error {
165+
defer logElapsed("resource.tencentcloud_css_watermark_rule_attachment.read")()
166+
defer inconsistentCheck(d, meta)()
167+
168+
logId := getLogId(contextNil)
169+
170+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
171+
172+
service := CssService{client: meta.(*TencentCloudClient).apiV3Conn}
173+
174+
idSplit := strings.Split(d.Id(), FILED_SP)
175+
if len(idSplit) != 4 {
176+
return fmt.Errorf("id is broken,%s", d.Id())
177+
}
178+
domainName := idSplit[0]
179+
appName := idSplit[1]
180+
streamName := idSplit[2]
181+
templateId := idSplit[3]
182+
183+
watermarkRule, err := service.DescribeCssWatermarkRuleAttachment(ctx, domainName, appName, streamName, templateId)
184+
if err != nil {
185+
return err
186+
}
187+
188+
if watermarkRule == nil {
189+
d.SetId("")
190+
log.Printf("[WARN]%s resource `CssWatermarkRule` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
191+
return nil
192+
}
193+
194+
if watermarkRule.DomainName != nil {
195+
_ = d.Set("domain_name", watermarkRule.DomainName)
196+
}
197+
198+
if watermarkRule.AppName != nil {
199+
_ = d.Set("app_name", watermarkRule.AppName)
200+
}
201+
202+
if watermarkRule.StreamName != nil {
203+
_ = d.Set("stream_name", watermarkRule.StreamName)
204+
}
205+
206+
if watermarkRule.TemplateId != nil {
207+
_ = d.Set("template_id", watermarkRule.TemplateId)
208+
}
209+
210+
if watermarkRule.CreateTime != nil {
211+
_ = d.Set("create_time", watermarkRule.CreateTime)
212+
}
213+
214+
if watermarkRule.UpdateTime != nil {
215+
_ = d.Set("update_time", watermarkRule.UpdateTime)
216+
}
217+
218+
return nil
219+
}
220+
221+
func resourceTencentCloudCssWatermarkRuleAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
222+
defer logElapsed("resource.tencentcloud_css_watermark_rule_attachment.delete")()
223+
defer inconsistentCheck(d, meta)()
224+
225+
logId := getLogId(contextNil)
226+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
227+
228+
service := CssService{client: meta.(*TencentCloudClient).apiV3Conn}
229+
idSplit := strings.Split(d.Id(), FILED_SP)
230+
if len(idSplit) != 4 {
231+
return fmt.Errorf("id is broken,%s", d.Id())
232+
}
233+
domainName := idSplit[0]
234+
appName := idSplit[1]
235+
streamName := idSplit[2]
236+
237+
if err := service.DetachCssWatermarkRuleAttachment(ctx, domainName, appName, streamName); err != nil {
238+
return err
239+
}
240+
241+
return nil
242+
}

0 commit comments

Comments
 (0)