Skip to content

Commit 475c402

Browse files
authored
Feat/support for kugou css domain requirement (#1568)
* update dts mode * feat:support css domain resource for kugou * 1. add changelog. \n2.passed e2e case.
1 parent d5e0a43 commit 475c402

15 files changed

+1386
-1
lines changed

.changelog/1568.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-resource
2+
tencentcloud_css_domain
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_css_domain_config
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_css_authenticate_domain_owner_operation
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_css_domains
15+
```
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/*
2+
Use this data source to query detailed information of css domains
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_css_domains" "domains" {
8+
domain_type = 0
9+
play_type = 1
10+
is_delay_live = 0
11+
}
12+
```
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"context"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
21+
css "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func dataSourceTencentCloudCssDomains() *schema.Resource {
26+
return &schema.Resource{
27+
Read: dataSourceTencentCloudCssDomainsRead,
28+
Schema: map[string]*schema.Schema{
29+
"domain_status": {
30+
Optional: true,
31+
Type: schema.TypeInt,
32+
Description: "domain name status filter. 0-disable, 1-enable.",
33+
},
34+
35+
"domain_type": {
36+
Optional: true,
37+
Type: schema.TypeInt,
38+
Description: "Domain name type filtering. 0-push, 1-play.",
39+
},
40+
41+
"is_delay_live": {
42+
Optional: true,
43+
Type: schema.TypeInt,
44+
Description: "0 normal live broadcast 1 slow live broadcast default 0.",
45+
},
46+
47+
"domain_prefix": {
48+
Optional: true,
49+
Type: schema.TypeString,
50+
Description: "domain name prefix.",
51+
},
52+
53+
"play_type": {
54+
Optional: true,
55+
Type: schema.TypeInt,
56+
Description: "Playing area, this parameter is meaningful only when DomainType=1. 1: Domestic.2: Global.3: Overseas.",
57+
},
58+
59+
"domain_list": {
60+
Computed: true,
61+
Type: schema.TypeList,
62+
Description: "A list of domain name details.",
63+
Elem: &schema.Resource{
64+
Schema: map[string]*schema.Schema{
65+
"name": {
66+
Type: schema.TypeString,
67+
Computed: true,
68+
Description: "Live domain name.",
69+
},
70+
"type": {
71+
Type: schema.TypeInt,
72+
Computed: true,
73+
Description: "Domain Type: 0: push stream. 1: Play.",
74+
},
75+
"status": {
76+
Type: schema.TypeInt,
77+
Computed: true,
78+
Description: "Domain Status: 0: disable. 1: Enabled.",
79+
},
80+
"create_time": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
Description: "add time.Note: This field is Beijing time (UTC+8 time zone).",
84+
},
85+
"b_c_name": {
86+
Type: schema.TypeInt,
87+
Computed: true,
88+
Description: "Is there a CName to the fixed rule domain name: 0: No. 1: Yes.",
89+
},
90+
"target_domain": {
91+
Type: schema.TypeString,
92+
Computed: true,
93+
Description: "The domain name corresponding to the cname.",
94+
},
95+
"play_type": {
96+
Type: schema.TypeInt,
97+
Computed: true,
98+
Description: "Playing area, this parameter is meaningful only when Type=1. 1: Domestic. 2: Global. 3: Overseas.",
99+
},
100+
"is_delay_live": {
101+
Type: schema.TypeInt,
102+
Computed: true,
103+
Description: "Whether to slow live broadcast: 0: normal live broadcast. 1: Slow live broadcast.",
104+
},
105+
"current_c_name": {
106+
Type: schema.TypeString,
107+
Computed: true,
108+
Description: "The cname information used by the current client.",
109+
},
110+
"rent_tag": {
111+
Type: schema.TypeInt,
112+
Computed: true,
113+
Description: "invalid parameter, can be ignored.",
114+
},
115+
"rent_expire_time": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "Failure parameter, can be ignored. Note: This field is Beijing time (UTC+8 time zone).",
119+
},
120+
"is_mini_program_live": {
121+
Type: schema.TypeInt,
122+
Computed: true,
123+
Description: "0: Standard live broadcast. 1: Mini program live broadcast. Note: This field may return null, indicating that no valid value can be obtained.",
124+
},
125+
},
126+
},
127+
},
128+
129+
"result_output_file": {
130+
Type: schema.TypeString,
131+
Optional: true,
132+
Description: "Used to save results.",
133+
},
134+
},
135+
}
136+
}
137+
138+
func dataSourceTencentCloudCssDomainsRead(d *schema.ResourceData, meta interface{}) error {
139+
defer logElapsed("data_source.tencentcloud_css_domains.read")()
140+
defer inconsistentCheck(d, meta)()
141+
142+
logId := getLogId(contextNil)
143+
144+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
145+
146+
paramMap := make(map[string]interface{})
147+
if v, ok := d.GetOkExists("domain_status"); ok {
148+
paramMap["DomainStatus"] = helper.IntUint64(v.(int))
149+
}
150+
151+
if v, ok := d.GetOkExists("domain_type"); ok {
152+
paramMap["DomainType"] = helper.IntUint64(v.(int))
153+
}
154+
155+
if v, ok := d.GetOkExists("is_delay_live"); ok {
156+
paramMap["IsDelayLive"] = helper.IntUint64(v.(int))
157+
}
158+
159+
if v, ok := d.GetOk("domain_prefix"); ok {
160+
paramMap["DomainPrefix"] = helper.String(v.(string))
161+
}
162+
163+
if v, ok := d.GetOkExists("play_type"); ok {
164+
paramMap["PlayType"] = helper.IntUint64(v.(int))
165+
}
166+
167+
service := CssService{client: meta.(*TencentCloudClient).apiV3Conn}
168+
169+
var domainList []*css.DomainInfo
170+
171+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
172+
result, e := service.DescribeCssDomainsByFilter(ctx, paramMap)
173+
if e != nil {
174+
return retryError(e)
175+
}
176+
domainList = result
177+
return nil
178+
})
179+
if err != nil {
180+
return err
181+
}
182+
183+
ids := make([]string, 0, len(domainList))
184+
tmpList := make([]map[string]interface{}, 0, len(domainList))
185+
186+
if domainList != nil {
187+
for _, domainInfo := range domainList {
188+
domainInfoMap := map[string]interface{}{}
189+
190+
if domainInfo.Name != nil {
191+
domainInfoMap["name"] = domainInfo.Name
192+
}
193+
194+
if domainInfo.Type != nil {
195+
domainInfoMap["type"] = domainInfo.Type
196+
}
197+
198+
if domainInfo.Status != nil {
199+
domainInfoMap["status"] = domainInfo.Status
200+
}
201+
202+
if domainInfo.CreateTime != nil {
203+
domainInfoMap["create_time"] = domainInfo.CreateTime
204+
}
205+
206+
if domainInfo.BCName != nil {
207+
domainInfoMap["b_c_name"] = domainInfo.BCName
208+
}
209+
210+
if domainInfo.TargetDomain != nil {
211+
domainInfoMap["target_domain"] = domainInfo.TargetDomain
212+
}
213+
214+
if domainInfo.PlayType != nil {
215+
domainInfoMap["play_type"] = domainInfo.PlayType
216+
}
217+
218+
if domainInfo.IsDelayLive != nil {
219+
domainInfoMap["is_delay_live"] = domainInfo.IsDelayLive
220+
}
221+
222+
if domainInfo.CurrentCName != nil {
223+
domainInfoMap["current_c_name"] = domainInfo.CurrentCName
224+
}
225+
226+
if domainInfo.RentTag != nil {
227+
domainInfoMap["rent_tag"] = domainInfo.RentTag
228+
}
229+
230+
if domainInfo.RentExpireTime != nil {
231+
domainInfoMap["rent_expire_time"] = domainInfo.RentExpireTime
232+
}
233+
234+
if domainInfo.IsMiniProgramLive != nil {
235+
domainInfoMap["is_mini_program_live"] = domainInfo.IsMiniProgramLive
236+
}
237+
238+
ids = append(ids, *domainInfo.Name)
239+
tmpList = append(tmpList, domainInfoMap)
240+
}
241+
242+
_ = d.Set("domain_list", tmpList)
243+
}
244+
245+
d.SetId(helper.DataResourceIdsHash(ids))
246+
output, ok := d.GetOk("result_output_file")
247+
if ok && output.(string) != "" {
248+
if e := writeToFile(output.(string), tmpList); e != nil {
249+
return e
250+
}
251+
}
252+
return nil
253+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudCssDomainsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccCssDomainsDataSource,
19+
Check: resource.ComposeTestCheckFunc(
20+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_css_domains.domains"),
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_css_domains.domains", "domain_list.#"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_css_domains.domains", "domain_list.0.name"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccCssDomainsDataSource = `
30+
31+
data "tencentcloud_css_domains" "domains" {
32+
domain_type = 0
33+
play_type = 1
34+
is_delay_live = 0
35+
}
36+
37+
`

tencentcloud/extension_css.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package tencentcloud
2+
3+
const (
4+
CSS_DOMAIN_TYPE_PUSH = 0
5+
CSS_DOMAIN_TYPE_PLAY_BACK = 1
6+
7+
CSS_DOMAIN_STATUS_DEACTIVATED = 0
8+
CSS_DOMAIN_STATUS_ACTIVATED = 1
9+
10+
CSS_PLAY_TYPE_MAINLAND = 0
11+
CSS_PLAY_TYPE_GLOBAL = 1
12+
CSS_PLAY_TYPE_OUTSIDE_MAINLAND = 2
13+
14+
CSS_DELAY_LIVE_LVB = 0
15+
CSS_DELAY_LIVE_LCB = 1
16+
17+
CSS_OWERSHIP_VIRIFIED = 0
18+
19+
CSS_VERIFY_TYPE_DB_CHECK = "dbCheck"
20+
CSS_VERIFY_TYPE_DNS_CHECK = "dnsCheck"
21+
CSS_VERIFY_TYPE_FILE_CHECK = "fileCheck"
22+
)

tencentcloud/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,10 @@ Cloud Streaming Services(CSS)
830830
tencentcloud_css_pull_stream_task
831831
tencentcloud_css_live_transcode_template
832832
tencentcloud_css_live_transcode_rule_attachment
833+
tencentcloud_css_domain
834+
tencentcloud_css_authenticate_domain_owner_operation
835+
Data Source
836+
tencentcloud_css_domains
833837
834838
Performance Testing Service(PTS)
835839
Resource
@@ -1294,6 +1298,7 @@ func Provider() terraform.ResourceProvider {
12941298
"tencentcloud_cynosdb_cluster_params": dataSourceTencentCloudCynosdbClusterParams(),
12951299
"tencentcloud_cynosdb_param_templates": dataSourceTencentCloudCynosdbParamTemplates(),
12961300
"tencentcloud_cvm_instances_modification": dataSourceTencentCloudCvmInstancesModification(),
1301+
"tencentcloud_css_domains": dataSourceTencentCloudCssDomains(),
12971302
},
12981303

12991304
ResourcesMap: map[string]*schema.Resource{
@@ -1611,6 +1616,8 @@ func Provider() terraform.ResourceProvider {
16111616
"tencentcloud_css_pull_stream_task": resourceTencentCloudCssPullStreamTask(),
16121617
"tencentcloud_css_live_transcode_template": resourceTencentCloudCssLiveTranscodeTemplate(),
16131618
"tencentcloud_css_live_transcode_rule_attachment": resourceTencentCloudCssLiveTranscodeRuleAttachment(),
1619+
"tencentcloud_css_domain": resourceTencentCloudCssDomain(),
1620+
"tencentcloud_css_authenticate_domain_owner_operation": resourceTencentCloudCssAuthenticateDomainOwnerOperation(),
16141621
"tencentcloud_pts_project": resourceTencentCloudPtsProject(),
16151622
"tencentcloud_pts_alert_channel": resourceTencentCloudPtsAlertChannel(),
16161623
"tencentcloud_pts_scenario": resourceTencentCloudPtsScenario(),

0 commit comments

Comments
 (0)