From d94d7f696218aca14571e289113b8bf1e7040ba1 Mon Sep 17 00:00:00 2001 From: Paul Carleton Date: Fri, 9 Jun 2017 12:27:49 -0700 Subject: [PATCH] Add propagated tags and ASG name tag to asg instances --- moto/autoscaling/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index ec46d1182..18ec7e35a 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -9,6 +9,7 @@ from moto.elb.exceptions import LoadBalancerNotFoundError # http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AS_Concepts.html#Cooldown DEFAULT_COOLDOWN = 300 +ASG_NAME_TAG = "aws:autoscaling:groupName" class InstanceState(object): @@ -169,8 +170,8 @@ class FakeAutoScalingGroup(BaseModel): self.termination_policies = termination_policies self.instance_states = [] - self.set_desired_capacity(desired_capacity) self.tags = tags if tags else [] + self.set_desired_capacity(desired_capacity) @classmethod def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name): @@ -261,12 +262,17 @@ class FakeAutoScalingGroup(BaseModel): # Need more instances count_needed = int(self.desired_capacity) - \ int(curr_instance_count) + + propagated_tags = {t['key']: t['value'] for t in self.tags + if t['propagate_at_launch'] == 'true'} + propagated_tags[ASG_NAME_TAG] = self.name reservation = self.autoscaling_backend.ec2_backend.add_instances( self.launch_config.image_id, count_needed, self.launch_config.user_data, self.launch_config.security_groups, instance_type=self.launch_config.instance_type, + tags={'instance': propagated_tags} ) for instance in reservation.instances: instance.autoscaling_group = self