Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enabled_metrics to aws_autoscaling_group data source #24691

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/24691.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/aws_autoscaling_group: Add `enabled_metrics` attribute
```
18 changes: 14 additions & 4 deletions internal/service/autoscaling/group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ func DataSourceGroup() *schema.Resource {
Read: dataSourceGroupRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -38,6 +34,13 @@ func DataSourceGroup() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"enabled_metrics": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"health_check_grace_period": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -77,6 +80,10 @@ func DataSourceGroup() *schema.Resource {
Type: schema.TypeString,
},
},
"name": {
Type: schema.TypeString,
Required: true,
},
"new_instances_protected_from_scale_in": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -169,6 +176,9 @@ func dataSourceGroupRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("default_cooldown", group.DefaultCooldown)
d.Set("desired_capacity", group.DesiredCapacity)
if err := d.Set("enabled_metrics", flattenASGEnabledMetrics(group.EnabledMetrics)); err != nil {
return fmt.Errorf("error setting enabled_metrics: %w", err)
}
d.Set("health_check_grace_period", group.HealthCheckGracePeriod)
d.Set("health_check_type", group.HealthCheckType)
d.Set("launch_configuration", group.LaunchConfigurationName)
Expand Down
4 changes: 4 additions & 0 deletions internal/service/autoscaling/group_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccAutoScalingGroupDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(datasourceName, "availability_zones.#", resourceName, "availability_zones.#"),
resource.TestCheckResourceAttrPair(datasourceName, "default_cooldown", resourceName, "default_cooldown"),
resource.TestCheckResourceAttrPair(datasourceName, "desired_capacity", resourceName, "desired_capacity"),
resource.TestCheckResourceAttrPair(datasourceName, "enabled_metrics.#", resourceName, "enabled_metrics.#"),
resource.TestCheckResourceAttrPair(datasourceName, "health_check_grace_period", resourceName, "health_check_grace_period"),
resource.TestCheckResourceAttrPair(datasourceName, "health_check_type", resourceName, "health_check_type"),
resource.TestCheckResourceAttrPair(datasourceName, "launch_configuration", resourceName, "launch_configuration"),
Expand Down Expand Up @@ -61,6 +62,7 @@ func TestAccAutoScalingGroupDataSource_launchTemplate(t *testing.T) {
resource.TestCheckResourceAttrPair(datasourceName, "availability_zones.#", resourceName, "availability_zones.#"),
resource.TestCheckResourceAttrPair(datasourceName, "default_cooldown", resourceName, "default_cooldown"),
resource.TestCheckResourceAttrPair(datasourceName, "desired_capacity", resourceName, "desired_capacity"),
resource.TestCheckResourceAttrPair(datasourceName, "enabled_metrics.#", resourceName, "enabled_metrics.#"),
resource.TestCheckResourceAttrPair(datasourceName, "health_check_grace_period", resourceName, "health_check_grace_period"),
resource.TestCheckResourceAttrPair(datasourceName, "health_check_type", resourceName, "health_check_type"),
resource.TestCheckResourceAttr(datasourceName, "launch_configuration", ""),
Expand Down Expand Up @@ -98,6 +100,7 @@ resource "aws_autoscaling_group" "match" {
health_check_grace_period = 300
health_check_type = "ELB"
desired_capacity = 0
enabled_metrics = ["GroupDesiredCapacity"]
force_delete = true
launch_configuration = aws_launch_configuration.data_source_aws_autoscaling_group_test.name
availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]
Expand All @@ -110,6 +113,7 @@ resource "aws_autoscaling_group" "no_match" {
health_check_grace_period = 300
health_check_type = "ELB"
desired_capacity = 0
enabled_metrics = ["GroupDesiredCapacity", "GroupStandbyInstances"]
force_delete = true
launch_configuration = aws_launch_configuration.data_source_aws_autoscaling_group_test.name
availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1]]
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/autoscaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interpolation.
* `availability_zones` - One or more Availability Zones for the group.
* `default_cool_down` - The amount of time, in seconds, after a scaling activity completes before another scaling activity can start.
* `desired_capacity` - The desired size of the group.
* `enabled_metrics` - The list of metrics enabled for collection.
* `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.
* `health_check_type` - The service to use for the health checks. The valid values are EC2 and ELB.
* `id` - Name of the Auto Scaling Group.
Expand Down