@@ -75,6 +75,11 @@ func DataSourceTencentCloudClbInstances() *schema.Resource {
75
75
Computed : true ,
76
76
Description : "ID of the project." ,
77
77
},
78
+ "cluster_id" : {
79
+ Type : schema .TypeString ,
80
+ Computed : true ,
81
+ Description : "ID of the cluster." ,
82
+ },
78
83
"clb_vips" : {
79
84
Type : schema .TypeList ,
80
85
Computed : true ,
@@ -182,42 +187,49 @@ func DataSourceTencentCloudClbInstances() *schema.Resource {
182
187
func dataSourceTencentCloudClbInstancesRead (d * schema.ResourceData , meta interface {}) error {
183
188
defer tccommon .LogElapsed ("data_source.tencentcloud_clb_instances.read" )()
184
189
185
- logId := tccommon .GetLogId (tccommon .ContextNil )
186
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
190
+ var (
191
+ logId = tccommon .GetLogId (tccommon .ContextNil )
192
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
193
+ clbService = ClbService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
194
+ clbs []* clb.LoadBalancer
195
+ )
187
196
188
197
params := make (map [string ]interface {})
189
198
if v , ok := d .GetOk ("clb_id" ); ok {
190
199
params ["clb_id" ] = v .(string )
191
200
}
201
+
192
202
if v , ok := d .GetOk ("clb_name" ); ok {
193
203
params ["clb_name" ] = v .(string )
194
204
}
205
+
195
206
if v , ok := d .GetOkExists ("project_id" ); ok {
196
207
params ["project_id" ] = v .(int )
197
208
}
209
+
198
210
if v , ok := d .GetOk ("network_type" ); ok {
199
211
params ["network_type" ] = v .(string )
200
212
}
213
+
201
214
if v , ok := d .GetOk ("master_zone" ); ok {
202
215
params ["master_zone" ] = v .(string )
203
216
}
204
217
205
- clbService := ClbService {
206
- client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
207
- }
208
- var clbs []* clb.LoadBalancer
209
218
err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
210
219
results , e := clbService .DescribeLoadBalancerByFilter (ctx , params )
211
220
if e != nil {
212
221
return tccommon .RetryError (e )
213
222
}
223
+
214
224
clbs = results
215
225
return nil
216
226
})
227
+
217
228
if err != nil {
218
229
log .Printf ("[CRITAL]%s read CLB instances failed, reason:%+v" , logId , err )
219
230
return err
220
231
}
232
+
221
233
clbList := make ([]map [string ]interface {}, 0 , len (clbs ))
222
234
ids := make ([]string , 0 , len (clbs ))
223
235
for _ , clbInstance := range clbs {
@@ -238,10 +250,16 @@ func dataSourceTencentCloudClbInstancesRead(d *schema.ResourceData, meta interfa
238
250
"vip_isp" : clbInstance .VipIsp ,
239
251
"security_groups" : helper .StringsInterfaces (clbInstance .SecureGroups ),
240
252
}
253
+
254
+ if clbInstance .ClusterIds != nil && len (clbInstance .ClusterIds ) > 0 {
255
+ mapping ["cluster_id" ] = * clbInstance .ClusterIds [0 ]
256
+ }
257
+
241
258
if clbInstance .NetworkAttributes != nil {
242
259
mapping ["internet_charge_type" ] = * clbInstance .NetworkAttributes .InternetChargeType
243
260
mapping ["internet_bandwidth_max_out" ] = * clbInstance .NetworkAttributes .InternetMaxBandwidthOut
244
261
}
262
+
245
263
if clbInstance .MasterZone != nil {
246
264
mapping ["zone_id" ] = * clbInstance .MasterZone .ZoneId
247
265
mapping ["zone" ] = * clbInstance .MasterZone .Zone
@@ -255,8 +273,10 @@ func dataSourceTencentCloudClbInstancesRead(d *schema.ResourceData, meta interfa
255
273
for _ , t := range clbInstance .Tags {
256
274
tags [* t .TagKey ] = * t .TagValue
257
275
}
276
+
258
277
mapping ["tags" ] = tags
259
278
}
279
+
260
280
clbList = append (clbList , mapping )
261
281
ids = append (ids , * clbInstance .LoadBalancerId )
262
282
}
0 commit comments