Skip to content

Commit 5893335

Browse files
committed
feat(teo): [122612515] support zone datasource
1 parent 4a0eddf commit 5893335

9 files changed

+904
-0
lines changed

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ func Provider() *schema.Provider {
842842
"tencentcloud_dayu_eip": dayuv2.DataSourceTencentCloudDayuEip(),
843843
"tencentcloud_teo_zone_available_plans": teo.DataSourceTencentCloudTeoZoneAvailablePlans(),
844844
"tencentcloud_teo_rule_engine_settings": teo.DataSourceTencentCloudTeoRuleEngineSettings(),
845+
"tencentcloud_teo_zones": teo.DataSourceTencentCloudTeoZones(),
845846
"tencentcloud_sts_caller_identity": sts.DataSourceTencentCloudStsCallerIdentity(),
846847
"tencentcloud_dcdb_instances": dcdb.DataSourceTencentCloudDcdbInstances(),
847848
"tencentcloud_dcdb_accounts": dcdb.DataSourceTencentCloudDcdbAccounts(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ TencentCloud EdgeOne(TEO)
14731473
Data Source
14741474
tencentcloud_teo_zone_available_plans
14751475
tencentcloud_teo_rule_engine_settings
1476+
tencentcloud_teo_zones
14761477

14771478
Resource
14781479
tencentcloud_teo_zone

tencentcloud/services/teo/data_source_tc_teo_zones.go

Lines changed: 730 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Use this data source to query detailed information of teo zoneAvailablePlans
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_teo_zones" "teo_zones" {
7+
filters {
8+
name = "zone-id"
9+
values = ["zone-39quuimqg8r6"]
10+
}
11+
12+
filters {
13+
name = "tag-key"
14+
values = ["createdBy"]
15+
}
16+
17+
filters {
18+
name = "tag-value"
19+
values = ["terraform"]
20+
}
21+
}
22+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package teo
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package teo_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
8+
)
9+
10+
func TestAccTencentCloudTeoZonesDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
tcacctest.AccPreCheck(t)
15+
},
16+
Providers: tcacctest.AccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccTeoZonesDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_teo_zones.teo_zones"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccTeoZonesDataSource = `
29+
30+
data "tencentcloud_teo_zones" "teo_zones" {
31+
filters {
32+
name = "tag-value"
33+
values = ["terraform"]
34+
}
35+
}
36+
`

tencentcloud/services/teo/service_tencentcloud_teo.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,3 +1684,57 @@ func (me *TeoService) DescribeTeoSecurityPolicyConfigById(ctx context.Context, z
16841684
ret = response.Response.SecurityPolicy
16851685
return
16861686
}
1687+
1688+
func (me *TeoService) DescribeTeoZonesByFilter(ctx context.Context, param map[string]interface{}) (ret []*teov20220901.Zone, errRet error) {
1689+
var (
1690+
logId = tccommon.GetLogId(ctx)
1691+
request = teov20220901.NewDescribeZonesRequest()
1692+
)
1693+
1694+
defer func() {
1695+
if errRet != nil {
1696+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
1697+
}
1698+
}()
1699+
1700+
for k, v := range param {
1701+
if k == "Filters" {
1702+
request.Filters = v.([]*teov20220901.AdvancedFilter)
1703+
}
1704+
if k == "Order" {
1705+
request.Order = v.(*string)
1706+
}
1707+
if k == "Direction" {
1708+
request.Direction = v.(*string)
1709+
}
1710+
}
1711+
1712+
ratelimit.Check(request.GetAction())
1713+
1714+
var (
1715+
offset int64 = 0
1716+
limit int64 = 100
1717+
)
1718+
for {
1719+
request.Offset = &offset
1720+
request.Limit = &limit
1721+
response, err := me.client.UseTeoV20220901Client().DescribeZones(request)
1722+
if err != nil {
1723+
errRet = err
1724+
return
1725+
}
1726+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1727+
1728+
if response == nil || response.Response == nil || len(response.Response.Zones) < 1 {
1729+
break
1730+
}
1731+
ret = append(ret, response.Response.Zones...)
1732+
if len(response.Response.Zones) < int(limit) {
1733+
break
1734+
}
1735+
1736+
offset += limit
1737+
}
1738+
1739+
return
1740+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
subcategory: "TencentCloud EdgeOne(TEO)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_teo_zones"
5+
sidebar_current: "docs-tencentcloud-datasource-teo_zones"
6+
description: |-
7+
Use this data source to query detailed information of teo zoneAvailablePlans
8+
---
9+
10+
# tencentcloud_teo_zones
11+
12+
Use this data source to query detailed information of teo zoneAvailablePlans
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "tencentcloud_teo_zones" "teo_zones" {
18+
filters {
19+
name = "zone-id"
20+
values = ["zone-39quuimqg8r6"]
21+
}
22+
23+
filters {
24+
name = "tag-key"
25+
values = ["createdBy"]
26+
}
27+
28+
filters {
29+
name = "tag-value"
30+
values = ["terraform"]
31+
}
32+
}
33+
```
34+
35+
## Argument Reference
36+
37+
The following arguments are supported:
38+
39+
* `direction` - (Optional, String) Sort direction. If the field value is a number, sort by the numeric value. If the field value is text, sort by the ascill code. Values include: `asc`: From the smallest to largest; `desc`: From the largest to smallest. Default value: `desc`.
40+
* `filters` - (Optional, List) Filter criteria. the maximum value of Filters.Values is 20. if this parameter is left empty, all site information authorized under the current appid will be returned. detailed filter criteria are as follows: zone-name: filter by site name; zone-id: filter by site id. the site id is in the format of zone-2noz78a8ev6k; status: filter by site status; tag-key: filter by tag key; tag-value: filter by tag value; alias-zone-name: filter by identical site identifier. when performing a fuzzy query, the fields that support filtering are named zone-name or alias-zone-name.
41+
* `order` - (Optional, String) Sort the returned results according to this field. Values include: `type`: Connection mode; `area`: Acceleration region; `create-time`: Creation time; `zone-name`: Site name; `use-time`: Last used time; `active-status` Effective status. Default value: `create-time`.
42+
* `result_output_file` - (Optional, String) Used to save results.
43+
44+
The `filters` object supports the following:
45+
46+
* `name` - (Required, String) Field to be filtered.
47+
* `values` - (Required, Set) Value of the filtered field.
48+
* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query.
49+
50+
## Attributes Reference
51+
52+
In addition to all arguments above, the following attributes are exported:
53+
54+
* `zones` - Details of sites.
55+
56+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,6 +5226,9 @@
52265226
<li>
52275227
<a href="/docs/providers/tencentcloud/d/teo_zone_available_plans.html">tencentcloud_teo_zone_available_plans</a>
52285228
</li>
5229+
<li>
5230+
<a href="/docs/providers/tencentcloud/d/teo_zones.html">tencentcloud_teo_zones</a>
5231+
</li>
52295232
</ul>
52305233
</li>
52315234
<li>

0 commit comments

Comments
 (0)