|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of gaap check proxy create |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_gaap_check_proxy_create" "check_proxy_create" { |
| 8 | + access_region = "Guangzhou" |
| 9 | + real_server_region = "Beijing" |
| 10 | + bandwidth = 10 |
| 11 | + concurrent = 2 |
| 12 | + ip_address_version = "IPv4" |
| 13 | + network_type = "normal" |
| 14 | + package_type = "Thunder" |
| 15 | + http3_supported = 0 |
| 16 | +} |
| 17 | +``` |
| 18 | +*/ |
| 19 | +package tencentcloud |
| 20 | + |
| 21 | +import ( |
| 22 | + "context" |
| 23 | + |
| 24 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 25 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 26 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 27 | +) |
| 28 | + |
| 29 | +func dataSourceTencentCloudGaapCheckProxyCreate() *schema.Resource { |
| 30 | + return &schema.Resource{ |
| 31 | + Read: dataSourceTencentCloudGaapCheckProxyCreateRead, |
| 32 | + Schema: map[string]*schema.Schema{ |
| 33 | + "access_region": { |
| 34 | + Required: true, |
| 35 | + Type: schema.TypeString, |
| 36 | + Description: "The access (acceleration) area of the proxy. The value can be obtained through the interface DescribeAccessRegionsByDestRegion.", |
| 37 | + }, |
| 38 | + |
| 39 | + "real_server_region": { |
| 40 | + Required: true, |
| 41 | + Type: schema.TypeString, |
| 42 | + Description: "The origin area of the proxy. The value can be obtained through the interface DescribeDestRegions.", |
| 43 | + }, |
| 44 | + |
| 45 | + "bandwidth": { |
| 46 | + Required: true, |
| 47 | + Type: schema.TypeInt, |
| 48 | + Description: "The upper limit of proxy bandwidth, in Mbps.", |
| 49 | + }, |
| 50 | + |
| 51 | + "concurrent": { |
| 52 | + Required: true, |
| 53 | + Type: schema.TypeInt, |
| 54 | + Description: "The upper limit of chanproxynel concurrency, representing the number of simultaneous online connections, in tens of thousands.", |
| 55 | + }, |
| 56 | + |
| 57 | + "group_id": { |
| 58 | + Optional: true, |
| 59 | + Type: schema.TypeString, |
| 60 | + Description: "If creating a proxy under a proxy group, you need to fill in the ID of the proxy group.", |
| 61 | + }, |
| 62 | + |
| 63 | + "ip_address_version": { |
| 64 | + Optional: true, |
| 65 | + Type: schema.TypeString, |
| 66 | + Description: "IP version, can be taken as IPv4 or IPv6, with a default value of IPv4.", |
| 67 | + }, |
| 68 | + |
| 69 | + "network_type": { |
| 70 | + Optional: true, |
| 71 | + Type: schema.TypeString, |
| 72 | + Description: "Network type, can take values 'normal', 'cn2', default value normal.", |
| 73 | + }, |
| 74 | + |
| 75 | + "package_type": { |
| 76 | + Optional: true, |
| 77 | + Type: schema.TypeString, |
| 78 | + Description: "Channel package type. Thunder represents the standard proxy group, Accelerator represents the game accelerator proxy, and CrossBorder represents the cross-border proxy.", |
| 79 | + }, |
| 80 | + |
| 81 | + "check_flag": { |
| 82 | + Computed: true, |
| 83 | + Type: schema.TypeInt, |
| 84 | + Description: "Query whether the proxy with the given configuration can be created, 1 can be created, 0 cannot be created.", |
| 85 | + }, |
| 86 | + |
| 87 | + "result_output_file": { |
| 88 | + Type: schema.TypeString, |
| 89 | + Optional: true, |
| 90 | + Description: "Used to save results.", |
| 91 | + }, |
| 92 | + }, |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +func dataSourceTencentCloudGaapCheckProxyCreateRead(d *schema.ResourceData, meta interface{}) error { |
| 97 | + defer logElapsed("data_source.tencentcloud_gaap_check_proxy_create.read")() |
| 98 | + defer inconsistentCheck(d, meta)() |
| 99 | + |
| 100 | + logId := getLogId(contextNil) |
| 101 | + |
| 102 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 103 | + |
| 104 | + paramMap := make(map[string]interface{}) |
| 105 | + if v, ok := d.GetOk("access_region"); ok { |
| 106 | + paramMap["AccessRegion"] = helper.String(v.(string)) |
| 107 | + } |
| 108 | + |
| 109 | + if v, ok := d.GetOk("real_server_region"); ok { |
| 110 | + paramMap["RealServerRegion"] = helper.String(v.(string)) |
| 111 | + } |
| 112 | + |
| 113 | + if v, _ := d.GetOk("bandwidth"); v != nil { |
| 114 | + paramMap["Bandwidth"] = helper.IntUint64(v.(int)) |
| 115 | + } |
| 116 | + |
| 117 | + if v, _ := d.GetOk("concurrent"); v != nil { |
| 118 | + paramMap["Concurrent"] = helper.IntUint64(v.(int)) |
| 119 | + } |
| 120 | + |
| 121 | + if v, ok := d.GetOk("group_id"); ok { |
| 122 | + paramMap["GroupId"] = helper.String(v.(string)) |
| 123 | + } |
| 124 | + |
| 125 | + if v, ok := d.GetOk("ip_address_version"); ok { |
| 126 | + paramMap["IPAddressVersion"] = helper.String(v.(string)) |
| 127 | + } |
| 128 | + |
| 129 | + if v, ok := d.GetOk("network_type"); ok { |
| 130 | + paramMap["NetworkType"] = helper.String(v.(string)) |
| 131 | + } |
| 132 | + |
| 133 | + if v, ok := d.GetOk("package_type"); ok { |
| 134 | + paramMap["PackageType"] = helper.String(v.(string)) |
| 135 | + } |
| 136 | + |
| 137 | + service := GaapService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 138 | + |
| 139 | + var checkFlag *uint64 |
| 140 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 141 | + result, e := service.DescribeGaapCheckProxyCreate(ctx, paramMap) |
| 142 | + if e != nil { |
| 143 | + return retryError(e) |
| 144 | + } |
| 145 | + checkFlag = result |
| 146 | + return nil |
| 147 | + }) |
| 148 | + if err != nil { |
| 149 | + return err |
| 150 | + } |
| 151 | + |
| 152 | + result := map[string]interface{}{} |
| 153 | + |
| 154 | + if checkFlag != nil { |
| 155 | + _ = d.Set("check_flag", *checkFlag) |
| 156 | + result["check_flag"] = *checkFlag |
| 157 | + } |
| 158 | + |
| 159 | + d.SetId(helper.BuildToken()) |
| 160 | + output, ok := d.GetOk("result_output_file") |
| 161 | + if ok && output.(string) != "" { |
| 162 | + if e := writeToFile(output.(string), result); e != nil { |
| 163 | + return e |
| 164 | + } |
| 165 | + } |
| 166 | + return nil |
| 167 | +} |
0 commit comments