Skip to content

feat(teo): [122612515] support zone datasource #3248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3248.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
tencentcloud_teo_zones
```
1 change: 1 addition & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ func Provider() *schema.Provider {
"tencentcloud_dayu_eip": dayuv2.DataSourceTencentCloudDayuEip(),
"tencentcloud_teo_zone_available_plans": teo.DataSourceTencentCloudTeoZoneAvailablePlans(),
"tencentcloud_teo_rule_engine_settings": teo.DataSourceTencentCloudTeoRuleEngineSettings(),
"tencentcloud_teo_zones": teo.DataSourceTencentCloudTeoZones(),
"tencentcloud_sts_caller_identity": sts.DataSourceTencentCloudStsCallerIdentity(),
"tencentcloud_dcdb_instances": dcdb.DataSourceTencentCloudDcdbInstances(),
"tencentcloud_dcdb_accounts": dcdb.DataSourceTencentCloudDcdbAccounts(),
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ TencentCloud EdgeOne(TEO)
Data Source
tencentcloud_teo_zone_available_plans
tencentcloud_teo_rule_engine_settings
tencentcloud_teo_zones

Resource
tencentcloud_teo_zone
Expand Down
730 changes: 730 additions & 0 deletions tencentcloud/services/teo/data_source_tc_teo_zones.go

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions tencentcloud/services/teo/data_source_tc_teo_zones.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Use this data source to query detailed information of teo zoneAvailablePlans

Example Usage

```hcl
data "tencentcloud_teo_zones" "teo_zones" {
filters {
name = "zone-id"
values = ["zone-39quuimqg8r6"]
}

filters {
name = "tag-key"
values = ["createdBy"]
}

filters {
name = "tag-value"
values = ["terraform"]
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package teo
36 changes: 36 additions & 0 deletions tencentcloud/services/teo/data_source_tc_teo_zones_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package teo_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
)

func TestAccTencentCloudTeoZonesDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccTeoZonesDataSource,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_teo_zones.teo_zones"),
),
},
},
})
}

const testAccTeoZonesDataSource = `

data "tencentcloud_teo_zones" "teo_zones" {
filters {
name = "tag-value"
values = ["terraform"]
}
}
`
62 changes: 62 additions & 0 deletions tencentcloud/services/teo/service_tencentcloud_teo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1684,3 +1684,65 @@ func (me *TeoService) DescribeTeoSecurityPolicyConfigById(ctx context.Context, z
ret = response.Response.SecurityPolicy
return
}

func (me *TeoService) DescribeTeoZonesByFilter(ctx context.Context, param map[string]interface{}) (ret []*teov20220901.Zone, errRet error) {
var (
logId = tccommon.GetLogId(ctx)
request = teov20220901.NewDescribeZonesRequest()
)

defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()

for k, v := range param {
if k == "Filters" {
request.Filters = v.([]*teov20220901.AdvancedFilter)
}
if k == "Order" {
request.Order = v.(*string)
}
if k == "Direction" {
request.Direction = v.(*string)
}
}

ratelimit.Check(request.GetAction())

var (
offset int64 = 0
limit int64 = 100
)
for {
request.Offset = &offset
request.Limit = &limit
response := teo.NewDescribeZonesResponse()
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := me.client.UseTeoClient().DescribeZones(request)
if e != nil {
return tccommon.RetryError(e)
}
response = result
return nil
})
if err != nil {
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response == nil || response.Response == nil || len(response.Response.Zones) < 1 {
break
}
ret = append(ret, response.Response.Zones...)
if len(response.Response.Zones) < int(limit) {
break
}

offset += limit
}

return
}
56 changes: 56 additions & 0 deletions website/docs/d/teo_zones.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
subcategory: "TencentCloud EdgeOne(TEO)"
layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_teo_zones"
sidebar_current: "docs-tencentcloud-datasource-teo_zones"
description: |-
Use this data source to query detailed information of teo zoneAvailablePlans
---

# tencentcloud_teo_zones

Use this data source to query detailed information of teo zoneAvailablePlans

## Example Usage

```hcl
data "tencentcloud_teo_zones" "teo_zones" {
filters {
name = "zone-id"
values = ["zone-39quuimqg8r6"]
}

filters {
name = "tag-key"
values = ["createdBy"]
}

filters {
name = "tag-value"
values = ["terraform"]
}
}
```

## Argument Reference

The following arguments are supported:

* `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`.
* `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.
* `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`.
* `result_output_file` - (Optional, String) Used to save results.

The `filters` object supports the following:

* `name` - (Required, String) Field to be filtered.
* `values` - (Required, Set) Value of the filtered field.
* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `zones` - Details of sites.


3 changes: 3 additions & 0 deletions website/tencentcloud.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5226,6 +5226,9 @@
<li>
<a href="/docs/providers/tencentcloud/d/teo_zone_available_plans.html">tencentcloud_teo_zone_available_plans</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/d/teo_zones.html">tencentcloud_teo_zones</a>
</li>
</ul>
</li>
<li>
Expand Down
Loading