Skip to content

Commit

Permalink
add gaap datasource (#2183)
Browse files Browse the repository at this point in the history
* add gaap datasource

* add changelog and update doc

---------

Co-authored-by: mikatong <[email protected]>
  • Loading branch information
tongyiming and mikatong authored Oct 9, 2023
1 parent c741d4c commit 6b02333
Show file tree
Hide file tree
Showing 43 changed files with 5,412 additions and 1,396 deletions.
43 changes: 43 additions & 0 deletions .changelog/2183.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
```release-note:new-data-source
tencentcloud_gaap_access_regions
```

```release-note:new-data-source
tencentcloud_gaap_access_regions_by_dest_region
```

```release-note:new-data-source
tencentcloud_gaap_black_header
```

```release-note:new-data-source
tencentcloud_gaap_country_area_mapping
```

```release-note:new-data-source
tencentcloud_gaap_custom_header
```

```release-note:new-data-source
tencentcloud_gaap_dest_regions
```

```release-note:new-data-source
tencentcloud_gaap_proxy_detail
```

```release-note:new-data-source
tencentcloud_gaap_proxy_groups
```

```release-note:new-data-source
tencentcloud_gaap_proxy_statistics
```

```release-note:new-data-source
tencentcloud_gaap_proxy_group_statistics
```

```release-note:new-data-source
tencentcloud_gaap_real_servers_status
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.725
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.699
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.514
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.760
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.756
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.699 h1:7lFObucm
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.699/go.mod h1:Iq+JZDHZlYu/dcmpT48SLFESqxL+C9GjRKrQHcw+FjQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.514 h1:MKSaqFCa4PCzzb2gVV+oFpxsiPmnCf6uDJwxf9eOoNU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.514/go.mod h1:uTfhkzPZOwop+tSo83QHrMWtesWdQApxJuFZEXGKXH0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.760 h1:Fs6q2kYxWAZPbeAs8t5edzhRX7iiyXvHR0qaCHMZgDU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.760/go.mod h1:yVviYUc0zcxhibofZpMTIUGh4wCgya9derdkIVlUQLo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563 h1:FoX+MK4vHThvPO6FbP5q98zD8S3n+d5+DbtK7skl++c=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729 h1:WQpzm3x27Jo/5uh6/Yqe/gbJ7r2ui9hc9ST7Ml2eP9Y=
Expand Down
170 changes: 170 additions & 0 deletions tencentcloud/data_source_tc_gaap_access_regions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
Use this data source to query detailed information of gaap access regions
Example Usage
```hcl
data "tencentcloud_gaap_access_regions" "access_regions" {
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
gaap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudGaapAccessRegions() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudGaapAccessRegionsRead,
Schema: map[string]*schema.Schema{
"access_region_set": {
Computed: true,
Type: schema.TypeList,
Description: "Acceleration Zone Details List.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"region_id": {
Type: schema.TypeString,
Computed: true,
Description: "Region id.",
},
"region_name": {
Type: schema.TypeString,
Computed: true,
Description: "English or Chinese name of the region.",
},
"region_area": {
Type: schema.TypeString,
Computed: true,
Description: "Region of the computer room.",
},
"region_area_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the region to which the computer room belongs.",
},
"idc_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of computer room, where dc represents the DataCenter data center and ec represents the EdgeComputing edge node.",
},
"feature_bitmap": {
Type: schema.TypeInt,
Computed: true,
Description: "Property bitmap, where each bit represents a property, where:0, indicates that the feature is not supported;1, indicates support for this feature.The meaning of the feature bitmap is as follows (from right to left):The first bit supports 4-layer acceleration;The second bit supports 7-layer acceleration;The third bit supports Http3 access;The fourth bit supports IPv6;The fifth bit supports high-quality BGP access;The 6th bit supports three network access;The 7th bit supports QoS acceleration in the access segment.Note: This field may return null, indicating that a valid value cannot be obtained.",
},
"support_feature": {
Type: schema.TypeList,
Computed: true,
Description: "Ability to access regional supportNote: This field may return null, indicating that a valid value cannot be obtained.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_type": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Computed: true,
Description: "A list of network types supported by the access area, with normal indicating support for regular BGP, cn2 indicating premium BGP, triple indicating three networks, and secure_ EIP represents a custom secure EIP.",
},
},
},
},
},
},
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudGaapAccessRegionsRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_gaap_access_regions.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)
service := GaapService{client: meta.(*TencentCloudClient).apiV3Conn}

var accessRegionSet []*gaap.RegionDetail

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeGaapAccessRegions(ctx)
if e != nil {
return retryError(e)
}
accessRegionSet = result
return nil
})
if err != nil {
return err
}

ids := make([]string, 0, len(accessRegionSet))
tmpList := make([]map[string]interface{}, 0, len(accessRegionSet))

if accessRegionSet != nil {
for _, regionDetail := range accessRegionSet {
regionDetailMap := map[string]interface{}{}

if regionDetail.RegionId != nil {
regionDetailMap["region_id"] = regionDetail.RegionId
}

if regionDetail.RegionName != nil {
regionDetailMap["region_name"] = regionDetail.RegionName
}

if regionDetail.RegionArea != nil {
regionDetailMap["region_area"] = regionDetail.RegionArea
}

if regionDetail.RegionAreaName != nil {
regionDetailMap["region_area_name"] = regionDetail.RegionAreaName
}

if regionDetail.IDCType != nil {
regionDetailMap["idc_type"] = regionDetail.IDCType
}

if regionDetail.FeatureBitmap != nil {
regionDetailMap["feature_bitmap"] = regionDetail.FeatureBitmap
}

if regionDetail.SupportFeature != nil {
supportFeatureMap := map[string]interface{}{}

if regionDetail.SupportFeature.NetworkType != nil {
supportFeatureMap["network_type"] = regionDetail.SupportFeature.NetworkType
}

regionDetailMap["support_feature"] = []interface{}{supportFeatureMap}
}

ids = append(ids, *regionDetail.RegionId)
tmpList = append(tmpList, regionDetailMap)
}

_ = d.Set("access_region_set", tmpList)
}

d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), tmpList); e != nil {
return e
}
}
return nil
}
Loading

0 comments on commit 6b02333

Please sign in to comment.