@@ -40,11 +40,18 @@ func dataSourceTencentCloudAsScalingGroups() *schema.Resource {
40
40
Optional : true ,
41
41
Description : "A scaling group name used to query." ,
42
42
},
43
+ "tags" : {
44
+ Type : schema .TypeMap ,
45
+ Optional : true ,
46
+ Description : "Tags used to query." ,
47
+ },
43
48
"result_output_file" : {
44
49
Type : schema .TypeString ,
45
50
Optional : true ,
46
51
Description : "Used to save results." ,
47
52
},
53
+
54
+ // computed
48
55
"scaling_group_list" : {
49
56
Type : schema .TypeList ,
50
57
Computed : true ,
@@ -183,6 +190,11 @@ func dataSourceTencentCloudAsScalingGroups() *schema.Resource {
183
190
Computed : true ,
184
191
Description : "The time when the AS group was created." ,
185
192
},
193
+ "tags" : {
194
+ Type : schema .TypeMap ,
195
+ Computed : true ,
196
+ Description : "Tags of the scaling group." ,
197
+ },
186
198
},
187
199
},
188
200
},
@@ -213,47 +225,55 @@ func dataSourceTencentCloudAsScalingGroupRead(d *schema.ResourceData, meta inter
213
225
scalingGroupName = v .(string )
214
226
}
215
227
216
- scalingGroups , err := asService .DescribeAutoScalingGroupByFilter (ctx , scalingGroupId , configurationId , scalingGroupName )
228
+ tags := getTags (d , "tags" )
229
+
230
+ scalingGroups , err := asService .DescribeAutoScalingGroupByFilter (ctx , scalingGroupId , configurationId , scalingGroupName , tags )
217
231
if err != nil {
218
232
return err
219
233
}
220
234
221
235
scalingGroupList := make ([]map [string ]interface {}, 0 , len (scalingGroups ))
222
236
for _ , scalingGroup := range scalingGroups {
237
+ tags := make (map [string ]string , len (scalingGroup .Tags ))
238
+ for _ , tag := range scalingGroup .Tags {
239
+ tags [* tag .Key ] = * tag .Value
240
+ }
241
+
223
242
mapping := map [string ]interface {}{
224
- "scaling_group_id" : * scalingGroup .AutoScalingGroupId ,
225
- "scaling_group_name" : * scalingGroup .AutoScalingGroupName ,
226
- "configuration_id" : * scalingGroup .LaunchConfigurationId ,
227
- "status" : * scalingGroup .AutoScalingGroupStatus ,
228
- "instance_count" : * scalingGroup .InstanceCount ,
229
- "max_size" : * scalingGroup .MaxSize ,
230
- "min_size" : * scalingGroup .MinSize ,
231
- "vpc_id" : * scalingGroup .VpcId ,
243
+ "scaling_group_id" : scalingGroup .AutoScalingGroupId ,
244
+ "scaling_group_name" : scalingGroup .AutoScalingGroupName ,
245
+ "configuration_id" : scalingGroup .LaunchConfigurationId ,
246
+ "status" : scalingGroup .AutoScalingGroupStatus ,
247
+ "instance_count" : scalingGroup .InstanceCount ,
248
+ "max_size" : scalingGroup .MaxSize ,
249
+ "min_size" : scalingGroup .MinSize ,
250
+ "vpc_id" : scalingGroup .VpcId ,
232
251
"subnet_ids" : flattenStringList (scalingGroup .SubnetIdSet ),
233
252
"zones" : flattenStringList (scalingGroup .ZoneSet ),
234
- "default_cooldown" : * scalingGroup .DefaultCooldown ,
235
- "desired_capacity" : * scalingGroup .DesiredCapacity ,
253
+ "default_cooldown" : scalingGroup .DefaultCooldown ,
254
+ "desired_capacity" : scalingGroup .DesiredCapacity ,
236
255
"load_balancer_ids" : flattenStringList (scalingGroup .LoadBalancerIdSet ),
237
256
"termination_policies" : flattenStringList (scalingGroup .TerminationPolicySet ),
238
- "retry_policy" : * scalingGroup .RetryPolicy ,
239
- "create_time" : * scalingGroup .CreatedTime ,
257
+ "retry_policy" : scalingGroup .RetryPolicy ,
258
+ "create_time" : scalingGroup .CreatedTime ,
259
+ "tags" : tags ,
240
260
}
241
261
if scalingGroup .ForwardLoadBalancerSet != nil && len (scalingGroup .ForwardLoadBalancerSet ) > 0 {
242
262
forwardLoadBalancers := make ([]map [string ]interface {}, 0 , len (scalingGroup .ForwardLoadBalancerSet ))
243
263
for _ , v := range scalingGroup .ForwardLoadBalancerSet {
244
264
targetAttributes := make ([]map [string ]interface {}, 0 , len (v .TargetAttributes ))
245
265
for _ , vv := range v .TargetAttributes {
246
266
targetAttribute := map [string ]interface {}{
247
- "port" : * vv .Port ,
248
- "weight" : * vv .Weight ,
267
+ "port" : vv .Port ,
268
+ "weight" : vv .Weight ,
249
269
}
250
270
targetAttributes = append (targetAttributes , targetAttribute )
251
271
}
252
272
forwardLoadBalancer := map [string ]interface {}{
253
- "load_balancer_id" : * v .LoadBalancerId ,
254
- "listener_id" : * v .ListenerId ,
273
+ "load_balancer_id" : v .LoadBalancerId ,
274
+ "listener_id" : v .ListenerId ,
255
275
"target_attributes" : targetAttributes ,
256
- "location_id" : * v .LocationId ,
276
+ "location_id" : v .LocationId ,
257
277
}
258
278
forwardLoadBalancers = append (forwardLoadBalancers , forwardLoadBalancer )
259
279
}
0 commit comments