|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of tse access_address |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_tse_access_address" "access_address" { |
| 8 | + instance_id = "ins-7eb7eea7" |
| 9 | + # vpc_id = "vpc-xxxxxx" |
| 10 | + # subnet_id = "subnet-xxxxxx" |
| 11 | + # workload = "pushgateway" |
| 12 | + engine_region = "ap-guangzhou" |
| 13 | +} |
| 14 | +``` |
| 15 | +*/ |
| 16 | +package tencentcloud |
| 17 | + |
| 18 | +import ( |
| 19 | + "context" |
| 20 | + |
| 21 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 22 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 23 | + tse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse/v20201207" |
| 24 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 25 | +) |
| 26 | + |
| 27 | +func dataSourceTencentCloudTseAccessAddress() *schema.Resource { |
| 28 | + return &schema.Resource{ |
| 29 | + Read: dataSourceTencentCloudTseAccessAddressRead, |
| 30 | + Schema: map[string]*schema.Schema{ |
| 31 | + "instance_id": { |
| 32 | + Required: true, |
| 33 | + Type: schema.TypeString, |
| 34 | + Description: "engine instance Id.", |
| 35 | + }, |
| 36 | + |
| 37 | + "vpc_id": { |
| 38 | + Optional: true, |
| 39 | + Type: schema.TypeString, |
| 40 | + Description: "VPC ID, Zookeeper does not need to pass vpcid and subnetid; nacos and Polaris need to pass vpcid and subnetid.", |
| 41 | + }, |
| 42 | + |
| 43 | + "subnet_id": { |
| 44 | + Optional: true, |
| 45 | + Type: schema.TypeString, |
| 46 | + Description: "Subnet ID, Zookeeper does not need to pass vpcid and subnetid; nacos and Polaris need to pass vpcid and subnetid.", |
| 47 | + }, |
| 48 | + |
| 49 | + "workload": { |
| 50 | + Optional: true, |
| 51 | + Type: schema.TypeString, |
| 52 | + Description: "Name of other engine components(pushgateway, polaris-limiter).", |
| 53 | + }, |
| 54 | + |
| 55 | + "engine_region": { |
| 56 | + Optional: true, |
| 57 | + Type: schema.TypeString, |
| 58 | + Description: "Deploy region.", |
| 59 | + }, |
| 60 | + |
| 61 | + "intranet_address": { |
| 62 | + Computed: true, |
| 63 | + Type: schema.TypeString, |
| 64 | + Description: "Intranet access address.", |
| 65 | + }, |
| 66 | + |
| 67 | + "internet_address": { |
| 68 | + Computed: true, |
| 69 | + Type: schema.TypeString, |
| 70 | + Description: "Public access address.", |
| 71 | + }, |
| 72 | + |
| 73 | + "env_address_infos": { |
| 74 | + Computed: true, |
| 75 | + Type: schema.TypeList, |
| 76 | + Description: "Apollo Multi-environment public ip address.", |
| 77 | + Elem: &schema.Resource{ |
| 78 | + Schema: map[string]*schema.Schema{ |
| 79 | + "env_name": { |
| 80 | + Type: schema.TypeString, |
| 81 | + Computed: true, |
| 82 | + Description: "env name.", |
| 83 | + }, |
| 84 | + "enable_config_internet": { |
| 85 | + Type: schema.TypeBool, |
| 86 | + Computed: true, |
| 87 | + Description: "Whether to enable the config public network.", |
| 88 | + }, |
| 89 | + "config_internet_service_ip": { |
| 90 | + Type: schema.TypeString, |
| 91 | + Computed: true, |
| 92 | + Description: "config public network ip.", |
| 93 | + }, |
| 94 | + "config_intranet_address": { |
| 95 | + Type: schema.TypeString, |
| 96 | + Computed: true, |
| 97 | + Description: "config Intranet access addressNote: This field may return null, indicating that a valid value is not available.", |
| 98 | + }, |
| 99 | + "enable_config_intranet": { |
| 100 | + Type: schema.TypeBool, |
| 101 | + Computed: true, |
| 102 | + Description: "Whether to enable the config Intranet clbNote: This field may return null, indicating that a valid value is not available.", |
| 103 | + }, |
| 104 | + "internet_band_width": { |
| 105 | + Type: schema.TypeInt, |
| 106 | + Computed: true, |
| 107 | + Description: "Client public network bandwidthNote: This field may return null, indicating that a valid value is not available.", |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + }, |
| 112 | + |
| 113 | + "console_internet_address": { |
| 114 | + Computed: true, |
| 115 | + Type: schema.TypeString, |
| 116 | + Description: "Console public network access addressNote: This field may return null, indicating that a valid value is not available.", |
| 117 | + }, |
| 118 | + |
| 119 | + "console_intranet_address": { |
| 120 | + Computed: true, |
| 121 | + Type: schema.TypeString, |
| 122 | + Description: "Console Intranet access addressNote: This field may return null, indicating that a valid value is not available.", |
| 123 | + }, |
| 124 | + |
| 125 | + "internet_band_width": { |
| 126 | + Computed: true, |
| 127 | + Type: schema.TypeInt, |
| 128 | + Description: "Client public network bandwidthNote: This field may return null, indicating that a valid value is not available.", |
| 129 | + }, |
| 130 | + |
| 131 | + "console_internet_band_width": { |
| 132 | + Computed: true, |
| 133 | + Type: schema.TypeInt, |
| 134 | + Description: "Console public network bandwidthNote: This field may return null, indicating that a valid value is not available.", |
| 135 | + }, |
| 136 | + |
| 137 | + "limiter_address_infos": { |
| 138 | + Computed: true, |
| 139 | + Type: schema.TypeList, |
| 140 | + Description: "Access IP address of the Polaris traffic limiting server nodeNote: This field may return null, indicating that a valid value is not available.", |
| 141 | + Elem: &schema.Resource{ |
| 142 | + Schema: map[string]*schema.Schema{ |
| 143 | + "intranet_address": { |
| 144 | + Type: schema.TypeString, |
| 145 | + Computed: true, |
| 146 | + Description: "VPC access IP address listNote: This field may return null, indicating that a valid value is not available.", |
| 147 | + }, |
| 148 | + }, |
| 149 | + }, |
| 150 | + }, |
| 151 | + |
| 152 | + "result_output_file": { |
| 153 | + Type: schema.TypeString, |
| 154 | + Optional: true, |
| 155 | + Description: "Used to save results.", |
| 156 | + }, |
| 157 | + }, |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +func dataSourceTencentCloudTseAccessAddressRead(d *schema.ResourceData, meta interface{}) error { |
| 162 | + defer logElapsed("data_source.tencentcloud_tse_access_address.read")() |
| 163 | + defer inconsistentCheck(d, meta)() |
| 164 | + |
| 165 | + logId := getLogId(contextNil) |
| 166 | + |
| 167 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 168 | + |
| 169 | + paramMap := make(map[string]interface{}) |
| 170 | + if v, ok := d.GetOk("instance_id"); ok { |
| 171 | + paramMap["InstanceId"] = helper.String(v.(string)) |
| 172 | + } |
| 173 | + |
| 174 | + if v, ok := d.GetOk("vpc_id"); ok { |
| 175 | + paramMap["VpcId"] = helper.String(v.(string)) |
| 176 | + } |
| 177 | + |
| 178 | + if v, ok := d.GetOk("subnet_id"); ok { |
| 179 | + paramMap["SubnetId"] = helper.String(v.(string)) |
| 180 | + } |
| 181 | + |
| 182 | + if v, ok := d.GetOk("workload"); ok { |
| 183 | + paramMap["Workload"] = helper.String(v.(string)) |
| 184 | + } |
| 185 | + |
| 186 | + if v, ok := d.GetOk("engine_region"); ok { |
| 187 | + paramMap["EngineRegion"] = helper.String(v.(string)) |
| 188 | + } |
| 189 | + |
| 190 | + service := TseService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 191 | + var accessAddress *tse.DescribeSREInstanceAccessAddressResponseParams |
| 192 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 193 | + result, e := service.DescribeTseAccessAddressByFilter(ctx, paramMap) |
| 194 | + if e != nil { |
| 195 | + return retryError(e) |
| 196 | + } |
| 197 | + accessAddress = result |
| 198 | + return nil |
| 199 | + }) |
| 200 | + if err != nil { |
| 201 | + return err |
| 202 | + } |
| 203 | + |
| 204 | + ids := []string{""} |
| 205 | + if accessAddress.IntranetAddress != nil { |
| 206 | + ids = append(ids, *accessAddress.IntranetAddress) |
| 207 | + _ = d.Set("intranet_address", accessAddress.IntranetAddress) |
| 208 | + } |
| 209 | + |
| 210 | + if accessAddress.InternetAddress != nil { |
| 211 | + _ = d.Set("internet_address", accessAddress.InternetAddress) |
| 212 | + } |
| 213 | + |
| 214 | + if accessAddress.EnvAddressInfos != nil { |
| 215 | + tmpList := make([]map[string]interface{}, 0, len(accessAddress.EnvAddressInfos)) |
| 216 | + for _, envAddressInfo := range accessAddress.EnvAddressInfos { |
| 217 | + envAddressInfoMap := map[string]interface{}{} |
| 218 | + |
| 219 | + if envAddressInfo.EnvName != nil { |
| 220 | + envAddressInfoMap["env_name"] = envAddressInfo.EnvName |
| 221 | + } |
| 222 | + |
| 223 | + if envAddressInfo.EnableConfigInternet != nil { |
| 224 | + envAddressInfoMap["enable_config_internet"] = envAddressInfo.EnableConfigInternet |
| 225 | + } |
| 226 | + |
| 227 | + if envAddressInfo.ConfigInternetServiceIp != nil { |
| 228 | + envAddressInfoMap["config_internet_service_ip"] = envAddressInfo.ConfigInternetServiceIp |
| 229 | + } |
| 230 | + |
| 231 | + if envAddressInfo.ConfigIntranetAddress != nil { |
| 232 | + envAddressInfoMap["config_intranet_address"] = envAddressInfo.ConfigIntranetAddress |
| 233 | + } |
| 234 | + |
| 235 | + if envAddressInfo.EnableConfigIntranet != nil { |
| 236 | + envAddressInfoMap["enable_config_intranet"] = envAddressInfo.EnableConfigIntranet |
| 237 | + } |
| 238 | + |
| 239 | + if envAddressInfo.InternetBandWidth != nil { |
| 240 | + envAddressInfoMap["internet_band_width"] = envAddressInfo.InternetBandWidth |
| 241 | + } |
| 242 | + |
| 243 | + tmpList = append(tmpList, envAddressInfoMap) |
| 244 | + } |
| 245 | + |
| 246 | + _ = d.Set("env_address_infos", tmpList) |
| 247 | + } |
| 248 | + |
| 249 | + if accessAddress.ConsoleInternetAddress != nil { |
| 250 | + _ = d.Set("console_internet_address", accessAddress.ConsoleInternetAddress) |
| 251 | + } |
| 252 | + |
| 253 | + if accessAddress.ConsoleIntranetAddress != nil { |
| 254 | + _ = d.Set("console_intranet_address", accessAddress.ConsoleIntranetAddress) |
| 255 | + } |
| 256 | + |
| 257 | + if accessAddress.InternetBandWidth != nil { |
| 258 | + _ = d.Set("internet_band_width", accessAddress.InternetBandWidth) |
| 259 | + } |
| 260 | + |
| 261 | + if accessAddress.ConsoleInternetBandWidth != nil { |
| 262 | + _ = d.Set("console_internet_band_width", accessAddress.ConsoleInternetBandWidth) |
| 263 | + } |
| 264 | + |
| 265 | + if accessAddress.LimiterAddressInfos != nil { |
| 266 | + tmpList := make([]map[string]interface{}, 0, len(accessAddress.LimiterAddressInfos)) |
| 267 | + for _, polarisLimiterAddress := range accessAddress.LimiterAddressInfos { |
| 268 | + polarisLimiterAddressMap := map[string]interface{}{} |
| 269 | + |
| 270 | + if polarisLimiterAddress.IntranetAddress != nil { |
| 271 | + polarisLimiterAddressMap["intranet_address"] = polarisLimiterAddress.IntranetAddress |
| 272 | + } |
| 273 | + |
| 274 | + tmpList = append(tmpList, polarisLimiterAddressMap) |
| 275 | + } |
| 276 | + |
| 277 | + _ = d.Set("limiter_address_infos", tmpList) |
| 278 | + } |
| 279 | + |
| 280 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 281 | + output, ok := d.GetOk("result_output_file") |
| 282 | + if ok && output.(string) != "" { |
| 283 | + if e := writeToFile(output.(string), d); e != nil { |
| 284 | + return e |
| 285 | + } |
| 286 | + } |
| 287 | + return nil |
| 288 | +} |
0 commit comments