Skip to content

Commit 279b8fb

Browse files
authored
Feat/support css auth key and cert binding (#1587)
* support authkey config and certification binding * passed the e2e case * update doc * add changelog * update e2e
1 parent 262bc26 commit 279b8fb

14 files changed

+1226
-6
lines changed

.changelog/1587.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-resource
2+
tencentcloud_css_play_domain_cert_attachment
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_css_play_auth_key_config
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_css_push_auth_key_config
11+
```

tencentcloud/basic_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,15 @@ const (
833833

834834
// CSS
835835
const (
836-
defaultCSSLiveType = "PullLivePushLive"
837-
defaultCSSDomainName = "177154.push.tlivecloud.com"
838-
defaultCSSStreamName = defaultCSSPrefix + "test_stream_name"
839-
defaultCSSAppName = "live"
840-
defaultCSSOperator = "tf_admin"
841-
defaultCSSPrefix = "tf_css_"
836+
defaultCSSLiveType = "PullLivePushLive"
837+
defaultCSSDomainName = "177154.push.tlivecloud.com"
838+
defaultCSSStreamName = defaultCSSPrefix + "test_stream_name"
839+
defaultCSSAppName = "live"
840+
defaultCSSOperator = "tf_admin"
841+
defaultCSSPrefix = "tf_css_"
842+
defaultCSSPlayDomainName = "test122.jingxhu.top"
843+
defaultCSSPushDomainName = "177154.push.tlivecloud.com"
844+
defaultCSSBindingCertName = "keep_ssl_css_domain_test"
842845
)
843846

844847
// End of CSS

tencentcloud/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ Cloud Streaming Services(CSS)
832832
tencentcloud_css_live_transcode_rule_attachment
833833
tencentcloud_css_domain
834834
tencentcloud_css_authenticate_domain_owner_operation
835+
tencentcloud_css_play_domain_cert_attachment
836+
tencentcloud_css_play_auth_key_config
837+
tencentcloud_css_push_auth_key_config
835838
Data Source
836839
tencentcloud_css_domains
837840
@@ -1640,6 +1643,9 @@ func Provider() terraform.ResourceProvider {
16401643
"tencentcloud_css_live_transcode_rule_attachment": resourceTencentCloudCssLiveTranscodeRuleAttachment(),
16411644
"tencentcloud_css_domain": resourceTencentCloudCssDomain(),
16421645
"tencentcloud_css_authenticate_domain_owner_operation": resourceTencentCloudCssAuthenticateDomainOwnerOperation(),
1646+
"tencentcloud_css_play_domain_cert_attachment": resourceTencentCloudCssPlayDomainCertAttachment(),
1647+
"tencentcloud_css_play_auth_key_config": resourceTencentCloudCssPlayAuthKeyConfig(),
1648+
"tencentcloud_css_push_auth_key_config": resourceTencentCloudCssPushAuthKeyConfig(),
16431649
"tencentcloud_pts_project": resourceTencentCloudPtsProject(),
16441650
"tencentcloud_pts_alert_channel": resourceTencentCloudPtsAlertChannel(),
16451651
"tencentcloud_pts_scenario": resourceTencentCloudPtsScenario(),
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
Provides a resource to create a css play_auth_key_config
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_css_play_auth_key_config" "play_auth_key_config" {
8+
domain_name = "your_play_domain_name"
9+
enable = 1
10+
auth_key = "testauthkey"
11+
auth_delta = 3600
12+
auth_back_key = "testbackkey"
13+
}
14+
```
15+
16+
Import
17+
18+
css play_auth_key_config can be imported using the id, e.g.
19+
20+
```
21+
terraform import tencentcloud_css_play_auth_key_config.play_auth_key_config play_auth_key_config_id
22+
```
23+
*/
24+
package tencentcloud
25+
26+
import (
27+
"context"
28+
"log"
29+
30+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
31+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
32+
css "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
33+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
34+
)
35+
36+
func resourceTencentCloudCssPlayAuthKeyConfig() *schema.Resource {
37+
return &schema.Resource{
38+
Create: resourceTencentCloudCssPlayAuthKeyConfigCreate,
39+
Read: resourceTencentCloudCssPlayAuthKeyConfigRead,
40+
Update: resourceTencentCloudCssPlayAuthKeyConfigUpdate,
41+
Delete: resourceTencentCloudCssPlayAuthKeyConfigDelete,
42+
Importer: &schema.ResourceImporter{
43+
State: schema.ImportStatePassthrough,
44+
},
45+
Schema: map[string]*schema.Schema{
46+
"domain_name": {
47+
Required: true,
48+
Type: schema.TypeString,
49+
Description: "Domain Name.",
50+
},
51+
52+
"enable": {
53+
Optional: true,
54+
Type: schema.TypeInt,
55+
Description: "Enable or not, 0: Close, 1: Enable. No transfer means that the current value is not modified.",
56+
},
57+
58+
"auth_key": {
59+
Optional: true,
60+
Type: schema.TypeString,
61+
Description: "Authentication key. No transfer means that the current value is not modified.",
62+
},
63+
64+
"auth_delta": {
65+
Optional: true,
66+
Type: schema.TypeInt,
67+
Description: "Valid time, unit: second. No transfer means that the current value is not modified.",
68+
},
69+
70+
"auth_back_key": {
71+
Optional: true,
72+
Type: schema.TypeString,
73+
Description: "Alternate key for authentication. No transfer means that the current value is not modified.",
74+
},
75+
},
76+
}
77+
}
78+
79+
func resourceTencentCloudCssPlayAuthKeyConfigCreate(d *schema.ResourceData, meta interface{}) error {
80+
defer logElapsed("resource.tencentcloud_css_play_auth_key_config.create")()
81+
defer inconsistentCheck(d, meta)()
82+
83+
var domainName string
84+
if v, ok := d.GetOk("domain_name"); ok {
85+
domainName = v.(string)
86+
}
87+
88+
d.SetId(domainName)
89+
90+
return resourceTencentCloudCssPlayAuthKeyConfigUpdate(d, meta)
91+
}
92+
93+
func resourceTencentCloudCssPlayAuthKeyConfigRead(d *schema.ResourceData, meta interface{}) error {
94+
defer logElapsed("resource.tencentcloud_css_play_auth_key_config.read")()
95+
defer inconsistentCheck(d, meta)()
96+
97+
logId := getLogId(contextNil)
98+
99+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
100+
101+
service := CssService{client: meta.(*TencentCloudClient).apiV3Conn}
102+
103+
domainName := d.Id()
104+
105+
playAuthKeyConfig, err := service.DescribeCssPlayAuthKeyConfigById(ctx, domainName)
106+
if err != nil {
107+
return err
108+
}
109+
110+
if playAuthKeyConfig == nil {
111+
d.SetId("")
112+
log.Printf("[WARN]%s resource `CssPlayAuthKeyConfig` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
113+
return nil
114+
}
115+
116+
if playAuthKeyConfig.DomainName != nil {
117+
_ = d.Set("domain_name", playAuthKeyConfig.DomainName)
118+
}
119+
120+
if playAuthKeyConfig.Enable != nil {
121+
_ = d.Set("enable", playAuthKeyConfig.Enable)
122+
}
123+
124+
if playAuthKeyConfig.AuthKey != nil {
125+
_ = d.Set("auth_key", playAuthKeyConfig.AuthKey)
126+
}
127+
128+
if playAuthKeyConfig.AuthDelta != nil {
129+
_ = d.Set("auth_delta", playAuthKeyConfig.AuthDelta)
130+
}
131+
132+
if playAuthKeyConfig.AuthBackKey != nil {
133+
_ = d.Set("auth_back_key", playAuthKeyConfig.AuthBackKey)
134+
}
135+
136+
return nil
137+
}
138+
139+
func resourceTencentCloudCssPlayAuthKeyConfigUpdate(d *schema.ResourceData, meta interface{}) error {
140+
defer logElapsed("resource.tencentcloud_css_play_auth_key_config.update")()
141+
defer inconsistentCheck(d, meta)()
142+
143+
logId := getLogId(contextNil)
144+
145+
request := css.NewModifyLivePlayAuthKeyRequest()
146+
147+
request.DomainName = helper.String(d.Id())
148+
149+
if v, ok := d.GetOkExists("enable"); ok {
150+
request.Enable = helper.IntInt64(v.(int))
151+
}
152+
153+
if d.HasChange("auth_key") {
154+
if v, ok := d.GetOk("auth_key"); ok {
155+
request.AuthKey = helper.String(v.(string))
156+
}
157+
}
158+
159+
if d.HasChange("auth_delta") {
160+
if v, _ := d.GetOk("auth_delta"); v != nil {
161+
request.AuthDelta = helper.IntUint64(v.(int))
162+
}
163+
}
164+
165+
if d.HasChange("auth_back_key") {
166+
if v, ok := d.GetOk("auth_back_key"); ok {
167+
request.AuthBackKey = helper.String(v.(string))
168+
}
169+
}
170+
171+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
172+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseCssClient().ModifyLivePlayAuthKey(request)
173+
if e != nil {
174+
return retryError(e)
175+
} else {
176+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
177+
}
178+
return nil
179+
})
180+
if err != nil {
181+
log.Printf("[CRITAL]%s update css playAuthKeyConfig failed, reason:%+v", logId, err)
182+
return err
183+
}
184+
185+
return resourceTencentCloudCssPlayAuthKeyConfigRead(d, meta)
186+
}
187+
188+
func resourceTencentCloudCssPlayAuthKeyConfigDelete(d *schema.ResourceData, meta interface{}) error {
189+
defer logElapsed("resource.tencentcloud_css_play_auth_key_config.delete")()
190+
defer inconsistentCheck(d, meta)()
191+
//donothing
192+
return nil
193+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package tencentcloud
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
)
9+
10+
func TestAccTencentCloudCssPlayAuthKeyConfigResource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: fmt.Sprintf(testAccCssPlayAuthKeyConfig, defaultCSSPlayDomainName),
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttrSet("tencentcloud_css_play_auth_key_config.play_auth_key_config", "id"),
22+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "domain_name", defaultCSSPlayDomainName),
23+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "enable", "0"),
24+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "auth_key", "test000key"),
25+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "auth_back_key", "test000backkey"),
26+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "auth_delta", "1800"),
27+
),
28+
},
29+
{
30+
Config: fmt.Sprintf(testAccCssPlayAuthKeyConfig_update, defaultCSSPlayDomainName),
31+
Check: resource.ComposeTestCheckFunc(
32+
resource.TestCheckResourceAttrSet("tencentcloud_css_play_auth_key_config.play_auth_key_config", "id"),
33+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "domain_name", defaultCSSPlayDomainName),
34+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "enable", "1"),
35+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "auth_key", "test000key000updated"),
36+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "auth_back_key", "test000backkey000updated"),
37+
resource.TestCheckResourceAttr("tencentcloud_css_play_auth_key_config.play_auth_key_config", "auth_delta", "3600"),
38+
),
39+
},
40+
{
41+
ResourceName: "tencentcloud_css_play_auth_key_config.play_auth_key_config",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
},
45+
},
46+
})
47+
}
48+
49+
const testAccCssPlayAuthKeyConfig = `
50+
51+
resource "tencentcloud_css_play_auth_key_config" "play_auth_key_config" {
52+
domain_name = "%s"
53+
enable = 0
54+
auth_key = "test000key"
55+
auth_delta = 1800
56+
auth_back_key = "test000backkey"
57+
}
58+
59+
`
60+
61+
const testAccCssPlayAuthKeyConfig_update = `
62+
63+
resource "tencentcloud_css_play_auth_key_config" "play_auth_key_config" {
64+
domain_name = "%s"
65+
enable = 1
66+
auth_key = "test000key000updated"
67+
auth_delta = 3600
68+
auth_back_key = "test000backkey000updated"
69+
}
70+
71+
`

0 commit comments

Comments
 (0)