Terraform-provider-aws: Improve filters for data source aws_autoscaling_group

Created on 26 Feb 2018  路  3Comments  路  Source: hashicorp/terraform-provider-aws

When using aws_autoscaling_group as a data source, I expect to be able to filter autoscaling groups similar to how I can filter other resource (i.e. aws_ami).

Terraform Version

Any

Affected Resource(s)

aws_autoscaling_groups

Terraform Configuration Files

data "aws_autoscaling_groups" "asgs" {
  filter {
    name = "tag:some-arbitrary-tag"
    values = ["some-arbitrary-value", "some-other-arbitrary-value"]
  }
}

Expected Behavior

Finds AutoScaling groups that have a tag with a key some-arbitrary-value and either some-arbitrary-value or some-other-arbitrary-value as values.

Actual Behavior

This behavior isn't supported.

Preliminary Findings

I spent a little time seeing if I could implement this behavior myself. I can see why this isn't currently supported :). The data provider (terraform-provider-aws/aws/data_source_aws_autoscaling_groups.go) basically just encapsulates the behavior of the AWS SDK's DescribeTags() functionality, which means this data source isn't doing what we (users) would intuitively expect. I see two possible routes to fix this:

  1. Increase the complexity of the data source by implementing the desired behavior
  2. Cooperate with Amazon to improve the quality of the SDK in this instance

Option 1 is probably the way to solve the issue fastest, but the real problem is that the SDK doesn't easily support the desired behavior, so option 2 is probably the correct solution. Perhaps we implement a temporary workaround, while looking at how we can improve the SDK to better suit this behavior?

Anyway, I'd be willing to help on this issue of the team provides some feedback on the proper approach.

enhancement servicautoscaling

Most helpful comment

This issue is pretty old but the data source supports filters now... however, it only seems to support one tag filter at a time, or maybe it is ORing them together. If you try to do something like filter on Role=myapp, Environment=qa you get everything from Environment=qa and everything from Role=myapp. This is not how filters normally work in AWS I think, I mean if you use the console to filter it ANDs the filters together

All 3 comments

this might take a while, as the raw API does not support filters, so AWS will need to update their API endpoint first, before the SDK's can be updated.

A good source for this is the raw API doc's for AWS's API
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeAutoScalingGroups.html

@madmax88 it is using the describe tags function, looks like it needs some debugging. if I get time will take a look.

This issue is pretty old but the data source supports filters now... however, it only seems to support one tag filter at a time, or maybe it is ORing them together. If you try to do something like filter on Role=myapp, Environment=qa you get everything from Environment=qa and everything from Role=myapp. This is not how filters normally work in AWS I think, I mean if you use the console to filter it ANDs the filters together

Was this page helpful?
0 / 5 - 0 ratings