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