Skip to content

Commit 35fb608

Browse files
authored
Merge pull request #24691 from ed-brex/asg-group-data-add-metrics
Add enabled_metrics to aws_autoscaling_group data source
2 parents 500e507 + 8285e71 commit 35fb608

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.changelog/24691.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
data-source/aws_autoscaling_group: Add `enabled_metrics` attribute
3+
```

internal/service/autoscaling/group_data_source.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ func DataSourceGroup() *schema.Resource {
1515
Read: dataSourceGroupRead,
1616

1717
Schema: map[string]*schema.Schema{
18-
"name": {
19-
Type: schema.TypeString,
20-
Required: true,
21-
},
2218
"arn": {
2319
Type: schema.TypeString,
2420
Computed: true,
@@ -38,6 +34,13 @@ func DataSourceGroup() *schema.Resource {
3834
Type: schema.TypeInt,
3935
Computed: true,
4036
},
37+
"enabled_metrics": {
38+
Type: schema.TypeSet,
39+
Computed: true,
40+
Elem: &schema.Schema{
41+
Type: schema.TypeString,
42+
},
43+
},
4144
"health_check_grace_period": {
4245
Type: schema.TypeInt,
4346
Computed: true,
@@ -77,6 +80,10 @@ func DataSourceGroup() *schema.Resource {
7780
Type: schema.TypeString,
7881
},
7982
},
83+
"name": {
84+
Type: schema.TypeString,
85+
Required: true,
86+
},
8087
"new_instances_protected_from_scale_in": {
8188
Type: schema.TypeBool,
8289
Computed: true,
@@ -169,6 +176,9 @@ func dataSourceGroupRead(d *schema.ResourceData, meta interface{}) error {
169176
}
170177
d.Set("default_cooldown", group.DefaultCooldown)
171178
d.Set("desired_capacity", group.DesiredCapacity)
179+
if err := d.Set("enabled_metrics", flattenASGEnabledMetrics(group.EnabledMetrics)); err != nil {
180+
return fmt.Errorf("error setting enabled_metrics: %w", err)
181+
}
172182
d.Set("health_check_grace_period", group.HealthCheckGracePeriod)
173183
d.Set("health_check_type", group.HealthCheckType)
174184
d.Set("launch_configuration", group.LaunchConfigurationName)

internal/service/autoscaling/group_data_source_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestAccAutoScalingGroupDataSource_basic(t *testing.T) {
2828
resource.TestCheckResourceAttrPair(datasourceName, "availability_zones.#", resourceName, "availability_zones.#"),
2929
resource.TestCheckResourceAttrPair(datasourceName, "default_cooldown", resourceName, "default_cooldown"),
3030
resource.TestCheckResourceAttrPair(datasourceName, "desired_capacity", resourceName, "desired_capacity"),
31+
resource.TestCheckResourceAttrPair(datasourceName, "enabled_metrics.#", resourceName, "enabled_metrics.#"),
3132
resource.TestCheckResourceAttrPair(datasourceName, "health_check_grace_period", resourceName, "health_check_grace_period"),
3233
resource.TestCheckResourceAttrPair(datasourceName, "health_check_type", resourceName, "health_check_type"),
3334
resource.TestCheckResourceAttrPair(datasourceName, "launch_configuration", resourceName, "launch_configuration"),
@@ -61,6 +62,7 @@ func TestAccAutoScalingGroupDataSource_launchTemplate(t *testing.T) {
6162
resource.TestCheckResourceAttrPair(datasourceName, "availability_zones.#", resourceName, "availability_zones.#"),
6263
resource.TestCheckResourceAttrPair(datasourceName, "default_cooldown", resourceName, "default_cooldown"),
6364
resource.TestCheckResourceAttrPair(datasourceName, "desired_capacity", resourceName, "desired_capacity"),
65+
resource.TestCheckResourceAttrPair(datasourceName, "enabled_metrics.#", resourceName, "enabled_metrics.#"),
6466
resource.TestCheckResourceAttrPair(datasourceName, "health_check_grace_period", resourceName, "health_check_grace_period"),
6567
resource.TestCheckResourceAttrPair(datasourceName, "health_check_type", resourceName, "health_check_type"),
6668
resource.TestCheckResourceAttr(datasourceName, "launch_configuration", ""),
@@ -98,6 +100,7 @@ resource "aws_autoscaling_group" "match" {
98100
health_check_grace_period = 300
99101
health_check_type = "ELB"
100102
desired_capacity = 0
103+
enabled_metrics = ["GroupDesiredCapacity"]
101104
force_delete = true
102105
launch_configuration = aws_launch_configuration.data_source_aws_autoscaling_group_test.name
103106
availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]
@@ -110,6 +113,7 @@ resource "aws_autoscaling_group" "no_match" {
110113
health_check_grace_period = 300
111114
health_check_type = "ELB"
112115
desired_capacity = 0
116+
enabled_metrics = ["GroupDesiredCapacity", "GroupStandbyInstances"]
113117
force_delete = true
114118
launch_configuration = aws_launch_configuration.data_source_aws_autoscaling_group_test.name
115119
availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]

website/docs/d/autoscaling_group.html.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interpolation.
3131
* `availability_zones` - One or more Availability Zones for the group.
3232
* `default_cool_down` - The amount of time, in seconds, after a scaling activity completes before another scaling activity can start.
3333
* `desired_capacity` - The desired size of the group.
34+
* `enabled_metrics` - The list of metrics enabled for collection.
3435
* `health_check_grace_period` - The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that has come into service.
3536
* `health_check_type` - The service to use for the health checks. The valid values are EC2 and ELB.
3637
* `id` - Name of the Auto Scaling Group.

0 commit comments

Comments
 (0)