Skip to content

Commit a5914d1

Browse files
authored
add dc (#1826)
* add dc * add changelog
1 parent bed8eea commit a5914d1

File tree

15 files changed

+2198
-212
lines changed

15 files changed

+2198
-212
lines changed

.changelog/1826.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-data-source
2+
tencentcloud_dc_access_points
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_dc_instance
7+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dbbrain v1.0.652
47-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199
47+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.633
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.572
4949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.539
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.616/go.mod
832832
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.624/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
833833
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.627/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
834834
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.628/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
835+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.633/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
835836
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.634/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
836837
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.644/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
837838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.650/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
@@ -855,8 +856,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 h1:D8qrel
855856
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335/go.mod h1:pz4s3nOhoB9cY0+uWzifuwr7lfh/Gvi1rv0ADxpPzD4=
856857
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dbbrain v1.0.652 h1:agjXNi5342DaL0TzRx1FjFlT+9VU2l6aN0yERmxiLLc=
857858
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dbbrain v1.0.652/go.mod h1:BG3Gc+jfiea3NAnmUgrYcRHmh/1ykye3k8iwKVm+KLQ=
858-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199 h1:7ShREKvI8ik2YNtLF42JR9x2YEeZS/gZvhIRfpsI8T0=
859-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199/go.mod h1:5WGSrlIZJOhwIqPjjafb6vzrPEZieSHPhPMjjGPXOSU=
859+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.633 h1:Ul5iNhXoBrrzguMdbFzTDf3lfl15QrKbvOhvVBiqxDI=
860+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.633/go.mod h1:tc6Hvf03M1cBtMC1IKSa5mlOn3kpxWOwhWU1fRy+KEE=
860861
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.572 h1:Yn1ZzciHvRg1V694c70VSZQ9tzbgZHrInvlpqE/M7wM=
861862
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.572/go.mod h1:+kYEqwZE8OlDhFMsb6hu0PD9CXQJOOnju2xOAUHp/dk=
862863
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.539 h1:V+oo20w9aLxAoSSEGVplke2kq72MdUA4OuagCv4gsiY=
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
/*
2+
Use this data source to query detailed information of dc access_points
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_dc_access_points" "access_points" {
8+
region_id = "ap-guangzhou"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
dc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc/v20180410"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudDcAccessPoints() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudDcAccessPointsRead,
26+
Schema: map[string]*schema.Schema{
27+
"region_id": {
28+
Optional: true,
29+
Type: schema.TypeString,
30+
Description: "Access point region, which can be queried through `DescribeRegions`.You can call `DescribeRegions` to get the region ID.",
31+
},
32+
33+
"access_point_set": {
34+
Computed: true,
35+
Type: schema.TypeList,
36+
Description: "Access point information.",
37+
Elem: &schema.Resource{
38+
Schema: map[string]*schema.Schema{
39+
"access_point_name": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
Description: "Access point name.",
43+
},
44+
"access_point_id": {
45+
Type: schema.TypeString,
46+
Computed: true,
47+
Description: "Unique access point ID.",
48+
},
49+
"state": {
50+
Type: schema.TypeString,
51+
Computed: true,
52+
Description: "Access point status. Valid values: available, unavailable.",
53+
},
54+
"location": {
55+
Type: schema.TypeString,
56+
Computed: true,
57+
Description: "Access point location.",
58+
},
59+
"line_operator": {
60+
Type: schema.TypeSet,
61+
Elem: &schema.Schema{
62+
Type: schema.TypeString,
63+
},
64+
Computed: true,
65+
Description: "List of ISPs supported by access point.",
66+
},
67+
"region_id": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: "ID of the region that manages the access point.",
71+
},
72+
"available_port_type": {
73+
Type: schema.TypeSet,
74+
Elem: &schema.Schema{
75+
Type: schema.TypeString,
76+
},
77+
Computed: true,
78+
Description: "Available port type at the access point. Valid values: 1000BASE-T: gigabit electrical port; 1000BASE-LX: 10 km gigabit single-mode optical port; 1000BASE-ZX: 80 km gigabit single-mode optical port; 10GBASE-LR: 10 km 10-gigabit single-mode optical port; 10GBASE-ZR: 80 km 10-gigabit single-mode optical port; 10GBASE-LH: 40 km 10-gigabit single-mode optical port; 100GBASE-LR4: 10 km 100-gigabit single-mode optical portfiber optic port.Note: this field may return `null`, indicating that no valid value is obtained.",
79+
},
80+
"coordinate": {
81+
Type: schema.TypeList,
82+
Computed: true,
83+
Description: "Latitude and longitude of the access pointNote: this field may return `null`, indicating that no valid values can be obtained.",
84+
Elem: &schema.Resource{
85+
Schema: map[string]*schema.Schema{
86+
"lat": {
87+
Type: schema.TypeFloat,
88+
Computed: true,
89+
Description: "Latitude.",
90+
},
91+
"lng": {
92+
Type: schema.TypeFloat,
93+
Computed: true,
94+
Description: "Longitude.",
95+
},
96+
},
97+
},
98+
},
99+
"city": {
100+
Type: schema.TypeString,
101+
Computed: true,
102+
Description: "City where the access point is locatedNote: this field may return `null`, indicating that no valid values can be obtained.",
103+
},
104+
"area": {
105+
Type: schema.TypeString,
106+
Computed: true,
107+
Description: "Access point regionNote: this field may return `null`, indicating that no valid values can be obtained.",
108+
},
109+
"access_point_type": {
110+
Type: schema.TypeString,
111+
Computed: true,
112+
Description: "Access point type. Valid values: `VXLAN`, `QCPL`, and `QCAR`.Note: this field may return `null`, indicating that no valid values can be obtained.",
113+
},
114+
},
115+
},
116+
},
117+
118+
"result_output_file": {
119+
Type: schema.TypeString,
120+
Optional: true,
121+
Description: "Used to save results.",
122+
},
123+
},
124+
}
125+
}
126+
127+
func dataSourceTencentCloudDcAccessPointsRead(d *schema.ResourceData, meta interface{}) error {
128+
defer logElapsed("data_source.tencentcloud_dc_access_points.read")()
129+
defer inconsistentCheck(d, meta)()
130+
131+
logId := getLogId(contextNil)
132+
133+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
134+
135+
paramMap := make(map[string]interface{})
136+
if v, ok := d.GetOk("region_id"); ok {
137+
paramMap["RegionId"] = helper.String(v.(string))
138+
}
139+
140+
service := DcService{client: meta.(*TencentCloudClient).apiV3Conn}
141+
142+
var accessPointSet []*dc.AccessPoint
143+
144+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
145+
result, e := service.DescribeDcAccessPointsByFilter(ctx, paramMap)
146+
if e != nil {
147+
return retryError(e)
148+
}
149+
accessPointSet = result
150+
return nil
151+
})
152+
if err != nil {
153+
return err
154+
}
155+
156+
ids := make([]string, 0, len(accessPointSet))
157+
tmpList := make([]map[string]interface{}, 0, len(accessPointSet))
158+
159+
if accessPointSet != nil {
160+
for _, accessPoint := range accessPointSet {
161+
accessPointMap := map[string]interface{}{}
162+
163+
if accessPoint.AccessPointName != nil {
164+
accessPointMap["access_point_name"] = accessPoint.AccessPointName
165+
}
166+
167+
if accessPoint.AccessPointId != nil {
168+
accessPointMap["access_point_id"] = accessPoint.AccessPointId
169+
}
170+
171+
if accessPoint.State != nil {
172+
accessPointMap["state"] = accessPoint.State
173+
}
174+
175+
if accessPoint.Location != nil {
176+
accessPointMap["location"] = accessPoint.Location
177+
}
178+
179+
if accessPoint.LineOperator != nil {
180+
accessPointMap["line_operator"] = accessPoint.LineOperator
181+
}
182+
183+
if accessPoint.RegionId != nil {
184+
accessPointMap["region_id"] = accessPoint.RegionId
185+
}
186+
187+
if accessPoint.AvailablePortType != nil {
188+
accessPointMap["available_port_type"] = accessPoint.AvailablePortType
189+
}
190+
191+
if accessPoint.Coordinate != nil {
192+
coordinateMap := map[string]interface{}{}
193+
194+
if accessPoint.Coordinate.Lat != nil {
195+
coordinateMap["lat"] = accessPoint.Coordinate.Lat
196+
}
197+
198+
if accessPoint.Coordinate.Lng != nil {
199+
coordinateMap["lng"] = accessPoint.Coordinate.Lng
200+
}
201+
202+
accessPointMap["coordinate"] = []interface{}{coordinateMap}
203+
}
204+
205+
if accessPoint.City != nil {
206+
accessPointMap["city"] = accessPoint.City
207+
}
208+
209+
if accessPoint.Area != nil {
210+
accessPointMap["area"] = accessPoint.Area
211+
}
212+
213+
if accessPoint.AccessPointType != nil {
214+
accessPointMap["access_point_type"] = accessPoint.AccessPointType
215+
}
216+
217+
ids = append(ids, *accessPoint.AccessPointId)
218+
tmpList = append(tmpList, accessPointMap)
219+
}
220+
221+
_ = d.Set("access_point_set", tmpList)
222+
}
223+
224+
d.SetId(helper.DataResourceIdsHash(ids))
225+
output, ok := d.GetOk("result_output_file")
226+
if ok && output.(string) != "" {
227+
if e := writeToFile(output.(string), tmpList); e != nil {
228+
return e
229+
}
230+
}
231+
return nil
232+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDcAccessPointsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccDcAccessPointsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_dc_access_points.access_points")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccDcAccessPointsDataSource = `
26+
27+
data "tencentcloud_dc_access_points" "access_points" {
28+
region_id = "ap-guangzhou"
29+
}
30+
31+
`

tencentcloud/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,14 @@ TDSQL-C MySQL(CynosDB)
368368
Direct Connect(DC)
369369
Data Source
370370
tencentcloud_dc_instances
371+
tencentcloud_dc_access_points
371372
tencentcloud_dcx_instances
372373
tencentcloud_dc_internet_address_quota
373374
tencentcloud_dc_internet_address_statistics
374375
tencentcloud_dc_public_direct_connect_tunnel_routes
375376
376377
Resource
378+
tencentcloud_dc_instance
377379
tencentcloud_dcx
378380
tencentcloud_dcx_extra_config
379381
tencentcloud_dc_share_dcx_config
@@ -1428,6 +1430,7 @@ func Provider() *schema.Provider {
14281430
"tencentcloud_ccn_cross_border_flow_monitor": dataSourceTencentCloudCcnCrossBorderFlowMonitor(),
14291431
"tencentcloud_ccn_cross_border_region_bandwidth_limits": dataSourceTencentCloudCcnCrossBorderRegionBandwidthLimits(),
14301432
"tencentcloud_dc_instances": dataSourceTencentCloudDcInstances(),
1433+
"tencentcloud_dc_access_points": dataSourceTencentCloudDcAccessPoints(),
14311434
"tencentcloud_dc_internet_address_quota": dataSourceTencentCloudDcInternetAddressQuota(),
14321435
"tencentcloud_dc_internet_address_statistics": dataSourceTencentCloudDcInternetAddressStatistics(),
14331436
"tencentcloud_dc_public_direct_connect_tunnel_routes": dataSourceTencentCloudDcPublicDirectConnectTunnelRoutes(),
@@ -1795,6 +1798,7 @@ func Provider() *schema.Provider {
17951798
"tencentcloud_ccn_routes": resourceTencentCloudCcnRoutes(),
17961799
"tencentcloud_ccn_instances_accept_attach": resourceTencentCloudCcnInstancesAcceptAttach(),
17971800
"tencentcloud_ccn_instances_reset_attach": resourceTencentCloudCcnInstancesResetAttach(),
1801+
"tencentcloud_dc_instance": resourceTencentCloudDcInstance(),
17981802
"tencentcloud_dcx": resourceTencentCloudDcxInstance(),
17991803
"tencentcloud_dcx_extra_config": resourceTencentCloudDcxExtraConfig(),
18001804
"tencentcloud_dc_share_dcx_config": resourceTencentCloudDcShareDcxConfig(),

0 commit comments

Comments
 (0)