-
Notifications
You must be signed in to change notification settings - Fork 134
/
data_source_tc_css_pad_templates.go
165 lines (141 loc) · 4.5 KB
/
data_source_tc_css_pad_templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package css
import (
"context"
"fmt"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
css "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudCssPadTemplates() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudCssPadTemplatesRead,
Schema: map[string]*schema.Schema{
"templates": {
Computed: true,
Type: schema.TypeList,
Description: "Live pad template information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Template id.",
},
"template_name": {
Type: schema.TypeString,
Computed: true,
Description: "Template name.",
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "Pad content.",
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: "Template create time.",
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: "Template modify time.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description info.",
},
"wait_duration": {
Type: schema.TypeInt,
Computed: true,
Description: "Stream interruption waiting time.Value range: 0-30000.Unit: milliseconds.",
},
"max_duration": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum pad duration.Value range: 0 - positive infinity.Unit: milliseconds.",
},
"type": {
Type: schema.TypeInt,
Computed: true,
Description: "Pad content type: 1: Image, 2: Video. Default value: 1.",
},
},
},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}
func dataSourceTencentCloudCssPadTemplatesRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_css_pad_templates.read")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
paramMap := make(map[string]interface{})
service := CssService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
var templates []*css.PadTemplate
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCssPadTemplatesByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
templates = result
return nil
})
if err != nil {
return err
}
ids := make([]string, 0, len(templates))
tmpList := make([]map[string]interface{}, 0, len(templates))
if templates != nil {
for _, padTemplate := range templates {
padTemplateMap := map[string]interface{}{}
if padTemplate.TemplateId != nil {
padTemplateMap["template_id"] = padTemplate.TemplateId
}
if padTemplate.TemplateName != nil {
padTemplateMap["template_name"] = padTemplate.TemplateName
}
if padTemplate.Url != nil {
padTemplateMap["url"] = padTemplate.Url
}
if padTemplate.CreateTime != nil {
padTemplateMap["create_time"] = padTemplate.CreateTime
}
if padTemplate.UpdateTime != nil {
padTemplateMap["update_time"] = padTemplate.UpdateTime
}
if padTemplate.Description != nil {
padTemplateMap["description"] = padTemplate.Description
}
if padTemplate.WaitDuration != nil {
padTemplateMap["wait_duration"] = padTemplate.WaitDuration
}
if padTemplate.MaxDuration != nil {
padTemplateMap["max_duration"] = padTemplate.MaxDuration
}
if padTemplate.Type != nil {
padTemplateMap["type"] = padTemplate.Type
}
ids = append(ids, fmt.Sprintf("%d", *padTemplate.TemplateId))
tmpList = append(tmpList, padTemplateMap)
}
_ = d.Set("templates", tmpList)
}
d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
return e
}
}
return nil
}