Terraform-provider-aws: AWS Data Source for Autoscaling Group

Created on 29 Nov 2017  ยท  7Comments  ยท  Source: hashicorp/terraform-provider-aws

So, the Autoscaling Group Resource is great, and provides useful information about the autoscaling group being created. However, if you are using Elastic Beanstalk, the autoscaling group is created for you. The autoscaling group name created by beanstalk is made available in the beanstalk environment resource attributes (https://www.terraform.io/docs/providers/aws/r/elastic_beanstalk_environment.html#autoscaling_groups). However, it doesn't seem possible to get information about that autoscaling group (such target group arns).

Once I had the autoscaling group, I would be able to get the target group arn, and create a target_group data source.

My specific use case is that I have a beanstalk app with an application autoscaling group, and would love to create a cloudwatch alarm on a ApplicationELB PerTargetGroup metric.

Implementation Notes

It should be noted that
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names works, and returns all necessary information.

It appears that data_source_aws_autoscaling_groups is ultimately calling this same endpoint, but not parsing the full response, and just getting the ASG names.

Relation to Target Tracking Autoscaling

This may also help people work-around #1156, since the target group name and ID is needed to create a target tracking autoscaling policy.
Currently, I have to just use the AWS CLI to run the following command:

AUTOSCALING_GROUP=$1
RESOURCE_LABEL=$2 # Format app/load-balancer-name/load-balancer-id/targetgroup/target-group-name/target-group-id , where app/load-balancer-name/load-balancer-id is the final portion of the load balancer ARN, and targetgroup/target-group-name/target-group-id is the final portion of the target group ARN

aws autoscaling put-scaling-policy --policy-name 26_requests_per_second --auto-scaling-group-name "$AUTOSCALING_GROUP" --policy-type TargetTrackingScaling --target-tracking-configuration '{"TargetValue": 26.66, "PredefinedMetricSpecification":{"PredefinedMetricType": "ALBRequestCountPerTarget", "ResourceLabel": "'"$RESOURCE_LABEL"'" }}'

Unfortunately, I have to manually look up the pieces needed to create $RESOURCE_LABEL, but with an autoscaling data source, I would be able to get the necessary information about my target groups and at least have terraform generate the resource label for me.

enhancement servicautoscaling stale

Most helpful comment

I ran into something similar, and was able to do it like this:

resource_label = "${aws_lb.test_lb.arn_suffix}/${aws_lb_target_group.test_tg.arn_suffix}"

All 7 comments

Furthermore, It looks like the autoscaling resource already has a parsing function defined. It might just need to be generalized to work with the data source.

p.s. I'd be interested in contributing / implementing the fix for this as well.

It seems like, due to the fact that the autoscaling_groups data source already exists, backwards compatibility should be preserved, and a new autoscaling_group (singular) data source should be created that, given a single name (or arn? or both?), retrieves attributes (same ones as in the autoscaling_group resource?)

I ran into something similar, and was able to do it like this:

resource_label = "${aws_lb.test_lb.arn_suffix}/${aws_lb_target_group.test_tg.arn_suffix}"

I've got a similar use case with kops. Kops creates the ASG for my nodes, but I need to associate them with some new ALBs I'm creating. There doesn't currently seem to be a way for me to use a data source to get the target ASGs to update them. I also can't just maintain a copy of the definition of the ASGs because there's no way for me to use a data source to get the launch configuration at runtime to put into a an aws_autoscaling_group resource.

Please add a data source to allow simple modifications to ASGs.

This is very useful for modules, it can prevent them from needing to take a mass of parameters. In my case, I want to create metric alarms for an auto-scaling group given an ARN, it is harder to use the module if you need to duplicate/copy parameters of the asg used to calculate the thresholds automatically.

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings