|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of gaap access regions |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_gaap_access_regions" "access_regions" { |
| 8 | +} |
| 9 | +``` |
| 10 | +*/ |
| 11 | +package tencentcloud |
| 12 | + |
| 13 | +import ( |
| 14 | + "context" |
| 15 | + |
| 16 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 17 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 18 | + gaap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529" |
| 19 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 20 | +) |
| 21 | + |
| 22 | +func dataSourceTencentCloudGaapAccessRegions() *schema.Resource { |
| 23 | + return &schema.Resource{ |
| 24 | + Read: dataSourceTencentCloudGaapAccessRegionsRead, |
| 25 | + Schema: map[string]*schema.Schema{ |
| 26 | + "access_region_set": { |
| 27 | + Computed: true, |
| 28 | + Type: schema.TypeList, |
| 29 | + Description: "Acceleration Zone Details List.", |
| 30 | + Elem: &schema.Resource{ |
| 31 | + Schema: map[string]*schema.Schema{ |
| 32 | + "region_id": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Computed: true, |
| 35 | + Description: "Region id.", |
| 36 | + }, |
| 37 | + "region_name": { |
| 38 | + Type: schema.TypeString, |
| 39 | + Computed: true, |
| 40 | + Description: "English or Chinese name of the region.", |
| 41 | + }, |
| 42 | + "region_area": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Computed: true, |
| 45 | + Description: "Region of the computer room.", |
| 46 | + }, |
| 47 | + "region_area_name": { |
| 48 | + Type: schema.TypeString, |
| 49 | + Computed: true, |
| 50 | + Description: "Name of the region to which the computer room belongs.", |
| 51 | + }, |
| 52 | + "idc_type": { |
| 53 | + Type: schema.TypeString, |
| 54 | + Computed: true, |
| 55 | + Description: "The type of computer room, where dc represents the DataCenter data center and ec represents the EdgeComputing edge node.", |
| 56 | + }, |
| 57 | + "feature_bitmap": { |
| 58 | + Type: schema.TypeInt, |
| 59 | + Computed: true, |
| 60 | + 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.", |
| 61 | + }, |
| 62 | + "support_feature": { |
| 63 | + Type: schema.TypeList, |
| 64 | + Computed: true, |
| 65 | + Description: "Ability to access regional supportNote: This field may return null, indicating that a valid value cannot be obtained.", |
| 66 | + Elem: &schema.Resource{ |
| 67 | + Schema: map[string]*schema.Schema{ |
| 68 | + "network_type": { |
| 69 | + Type: schema.TypeSet, |
| 70 | + Elem: &schema.Schema{ |
| 71 | + Type: schema.TypeString, |
| 72 | + }, |
| 73 | + Computed: true, |
| 74 | + 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.", |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + |
| 83 | + "result_output_file": { |
| 84 | + Type: schema.TypeString, |
| 85 | + Optional: true, |
| 86 | + Description: "Used to save results.", |
| 87 | + }, |
| 88 | + }, |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +func dataSourceTencentCloudGaapAccessRegionsRead(d *schema.ResourceData, meta interface{}) error { |
| 93 | + defer logElapsed("data_source.tencentcloud_gaap_access_regions.read")() |
| 94 | + defer inconsistentCheck(d, meta)() |
| 95 | + |
| 96 | + logId := getLogId(contextNil) |
| 97 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 98 | + service := GaapService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 99 | + |
| 100 | + var accessRegionSet []*gaap.RegionDetail |
| 101 | + |
| 102 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 103 | + result, e := service.DescribeGaapAccessRegions(ctx) |
| 104 | + if e != nil { |
| 105 | + return retryError(e) |
| 106 | + } |
| 107 | + accessRegionSet = result |
| 108 | + return nil |
| 109 | + }) |
| 110 | + if err != nil { |
| 111 | + return err |
| 112 | + } |
| 113 | + |
| 114 | + ids := make([]string, 0, len(accessRegionSet)) |
| 115 | + tmpList := make([]map[string]interface{}, 0, len(accessRegionSet)) |
| 116 | + |
| 117 | + if accessRegionSet != nil { |
| 118 | + for _, regionDetail := range accessRegionSet { |
| 119 | + regionDetailMap := map[string]interface{}{} |
| 120 | + |
| 121 | + if regionDetail.RegionId != nil { |
| 122 | + regionDetailMap["region_id"] = regionDetail.RegionId |
| 123 | + } |
| 124 | + |
| 125 | + if regionDetail.RegionName != nil { |
| 126 | + regionDetailMap["region_name"] = regionDetail.RegionName |
| 127 | + } |
| 128 | + |
| 129 | + if regionDetail.RegionArea != nil { |
| 130 | + regionDetailMap["region_area"] = regionDetail.RegionArea |
| 131 | + } |
| 132 | + |
| 133 | + if regionDetail.RegionAreaName != nil { |
| 134 | + regionDetailMap["region_area_name"] = regionDetail.RegionAreaName |
| 135 | + } |
| 136 | + |
| 137 | + if regionDetail.IDCType != nil { |
| 138 | + regionDetailMap["idc_type"] = regionDetail.IDCType |
| 139 | + } |
| 140 | + |
| 141 | + if regionDetail.FeatureBitmap != nil { |
| 142 | + regionDetailMap["feature_bitmap"] = regionDetail.FeatureBitmap |
| 143 | + } |
| 144 | + |
| 145 | + if regionDetail.SupportFeature != nil { |
| 146 | + supportFeatureMap := map[string]interface{}{} |
| 147 | + |
| 148 | + if regionDetail.SupportFeature.NetworkType != nil { |
| 149 | + supportFeatureMap["network_type"] = regionDetail.SupportFeature.NetworkType |
| 150 | + } |
| 151 | + |
| 152 | + regionDetailMap["support_feature"] = []interface{}{supportFeatureMap} |
| 153 | + } |
| 154 | + |
| 155 | + ids = append(ids, *regionDetail.RegionId) |
| 156 | + tmpList = append(tmpList, regionDetailMap) |
| 157 | + } |
| 158 | + |
| 159 | + _ = d.Set("access_region_set", tmpList) |
| 160 | + } |
| 161 | + |
| 162 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 163 | + output, ok := d.GetOk("result_output_file") |
| 164 | + if ok && output.(string) != "" { |
| 165 | + if e := writeToFile(output.(string), tmpList); e != nil { |
| 166 | + return e |
| 167 | + } |
| 168 | + } |
| 169 | + return nil |
| 170 | +} |
0 commit comments