|
| 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 | +} |
0 commit comments